Examples of DownloadFuture


Examples of io.fabric8.agent.download.DownloadFuture

            if (container != null) {
                final DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService, downloadExecutor);
                return new DownloadStrategy() {
                    @Override
                    public File downloadContent(URL sourceUrl, File installDir) throws IOException {
                        DownloadFuture future = downloadManager.download(sourceUrl.toString());
                        File file = AgentUtils.waitForFileDownload(future);
                        if (file != null && file.exists() && file.isFile()) {
                            // now lest copy it to the install dir
                            File newFile = new File(installDir, file.getName());
                            Files.copy(file, newFile);
View Full Code Here

Examples of io.fabric8.agent.download.DownloadFuture

        MavenConfigurationImpl config = new MavenConfigurationImpl(new PropertiesPropertyResolver(System.getProperties()), "org.ops4j.pax.url.mvn");
        config.setSettings(new MavenSettingsImpl(config.getSettingsFileUrl(), config.useFallbackRepositories()));
        DownloadManager dm = new DownloadManager(config, Executors.newSingleThreadExecutor());

        final CountDownLatch latch = new CountDownLatch(1);
        final DownloadFuture df = dm.download(String.format("mvn:%s/%s/%s", archetype.groupId, archetype.artifactId, archetype.version));
        df.addListener(new FutureListener<DownloadFuture>() {
            @Override
            public void operationComplete(DownloadFuture future) {
                latch.countDown();
            }
        });

        // wait for download
        try {
            boolean init = false;
            for (int i = 0; i < 2 * 60 && latch.getCount() > 0; i++) {
                // dont do anything in the first 3 seconds as we likely can download it faster
                if (i > 3) {
                    if (!init) {
                        System.out.print("Downloading archetype in progress: ");
                        init = true;
                    }
                    System.out.print(".");
                }
                // only sleep 0.5 sec so we can react faster
                Thread.sleep(500);
            }
        } catch (InterruptedException e) {
            System.err.println("\nFailed to download " + archetype);
            throw new IOException(e.getMessage(), e);
        }

        if (latch.getCount() == 0) {
            return df.getFile();
        } else {
            System.err.println("\nFailed to download archetype within 60 seconds: " + archetype);
            throw new IOException("Failed to download archetype within 60 seconds: " + archetype);
        }
    }
View Full Code Here

Examples of io.fabric8.agent.download.DownloadFuture

            this.manager = manager;
        }

        public void download(String uri, final DownloadCallback callback) throws MalformedURLException {
            synchronized (lock) {
                DownloadFuture future = futures.get(uri);
                if (future == null) {
                    pendings.incrementAndGet();
                    future = manager.download(uri);
                    future.addListener(new FutureListener<DownloadFuture>() {
                        @Override
                        public void operationComplete(DownloadFuture future) {
                            onDownloaded(future, callback);
                        }
                    });
View Full Code Here

Examples of io.fabric8.agent.download.DownloadFuture

            }
        }

        public DownloadFuture download(String uri) throws MalformedURLException {
            synchronized (lock) {
                DownloadFuture future = futures.get(uri);
                if (future == null) {
                    pendings.incrementAndGet();
                    future = manager.download(uri);
                    future.addListener(new FutureListener<DownloadFuture>() {
                        @Override
                        public void operationComplete(DownloadFuture future) {
                            onDownloaded(future, null);
                        }
                    });
View Full Code Here

Examples of io.fabric8.agent.download.DownloadFuture

        String settings = createMavenSettingsWithProxy(server.getConnectors()[0].getLocalPort());
        DownloadManager dm = createDownloadManager("http://relevant.not/maven2@id=central", settings, custom);

        try {
            final CountDownLatch latch = new CountDownLatch(1);
            DownloadFuture df = dm.download("mvn:x.y/z/1.0");
            df.addListener(new FutureListener<DownloadFuture>() {
                @Override
                public void operationComplete(DownloadFuture future) {
                    latch.countDown();
                }
            });

            latch.await(30, TimeUnit.SECONDS);
            assertNotNull(df.getUrl());
            assertNotNull(df.getFile());
            assertEquals("z-1.0.jar", df.getFile().getName());
            LOG.info("Downloaded URL={}, FILE={}", df.getUrl(), df.getFile());
        } finally {
            server.stop();
        }
    }
View Full Code Here

Examples of io.fabric8.agent.download.DownloadFuture

        String settings = createMavenSettingsWithProxy(server.getConnectors()[0].getLocalPort());
        DownloadManager dm = createDownloadManager("http://relevant.not/maven2@id=central", settings, custom);

        try {
            final CountDownLatch latch = new CountDownLatch(1);
            DownloadFuture df = dm.download("mvn:x.y/z/1.0");
            df.addListener(new FutureListener<DownloadFuture>() {
                @Override
                public void operationComplete(DownloadFuture future) {
                    latch.countDown();
                }
            });

            latch.await(30, TimeUnit.SECONDS);
            assertNotNull(df.getUrl());
            assertNotNull(df.getFile());
            assertEquals("z-1.0.jar", df.getFile().getName());
            LOG.info("Downloaded URL={}, FILE={}", df.getUrl(), df.getFile());
        } finally {
            server.stop();
        }
    }
View Full Code Here

Examples of io.fabric8.agent.download.DownloadFuture

        FileOutputStream artifact = new FileOutputStream(new File(dir, "z-1.0.jar"));
        artifact.write(new byte[] { 0x42 });
        artifact.close();

        final CountDownLatch latch = new CountDownLatch(1);
        DownloadFuture df = dm.download("mvn:x.y/z/1.0");
        df.addListener(new FutureListener<DownloadFuture>() {
            @Override
            public void operationComplete(DownloadFuture future) {
                latch.countDown();
            }
        });

        latch.await(30, TimeUnit.SECONDS);
        assertNotNull(df.getUrl());
        assertNotNull(df.getFile());
        assertEquals("z-1.0.jar", df.getFile().getName());
        LOG.info("Downloaded URL={}, FILE={}", df.getUrl(), df.getFile());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.