Example usage for java.util.concurrent Callable Callable

List of usage examples for java.util.concurrent Callable Callable

Introduction

In this page you can find the example usage for java.util.concurrent Callable Callable.

Prototype

Callable

Source Link

Usage

From source file:com.microsoft.windowsazure.management.storage.StorageManagementIntegrationTestBase.java

protected static void createService() throws Exception {
    // reinitialize configuration from known state
    Configuration config = createConfiguration();
    config.setProperty(ApacheConfigurationProperties.PROPERTY_RETRY_HANDLER,
            new DefaultHttpRequestRetryHandler());

    storageManagementClient = StorageManagementService.create(config);
    addClient((ServiceClient<?>) storageManagementClient, new Callable<Void>() {
        @Override//from   ww  w  . j  a  va 2  s  .c  om
        public Void call() throws Exception {
            createService();
            return null;
        }
    });
    addRegexRule("azurejavatest[a-z]{10}");
}

From source file:com.insightml.utils.jobs.Threaded.java

public final List<Pair<I, O>> run(final Iterable<? extends I> queue, final int directThreshold) {
    final List<Callable<Pair<I, O>>> tasks = new LinkedList<>();
    int i = -1;//  ww w .ja  va  2  s  .com
    for (final I it : queue) {
        final int j = ++i;
        tasks.add(new Callable<Pair<I, O>>() {
            @Override
            public Pair<I, O> call() {
                try {
                    return new Pair<>(it, exec(j, it));
                } catch (final Exception e) {
                    e.printStackTrace();
                    throw new IllegalStateException(e);
                }
            }
        });
    }
    return new LinkedList<>(JobPool.invokeAll(tasks, directThreshold));
}

From source file:com.parse.ParseCurrentConfigController.java

public Task<ParseConfig> getCurrentConfigAsync() {
    return Task.call(new Callable<ParseConfig>() {
        @Override/*from www  . j a  v a2  s . co m*/
        public ParseConfig call() throws Exception {
            synchronized (currentConfigMutex) {
                if (currentConfig == null) {
                    ParseConfig config = getFromDisk();
                    currentConfig = (config != null) ? config : new ParseConfig();
                }
            }
            return currentConfig;
        }
    }, ParseExecutors.io());
}

From source file:org.fornax.cartridges.sculptor.framework.richclient.errorhandling.ExceptionAwareJob.java

@Override
protected IStatus run(final IProgressMonitor monitor) {
    Callable<IStatus> callable = new Callable<IStatus>() {
        public IStatus call() throws Exception {
            return doRun(monitor);
        }/*from   www  .j  a  va2 s  .c o  m*/
    };
    return exceptionAware.run(callable);
}

From source file:com.parse.ParseFile.java

private static ProgressCallback progressCallbackOnMainThread(final ProgressCallback progressCallback) {
    if (progressCallback == null) {
        return null;
    }/*from w ww. j ava2s  . c  o  m*/

    return new ProgressCallback() {
        @Override
        public void done(final Integer percentDone) {
            Task.call(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    progressCallback.done(percentDone);
                    return null;
                }
            }, ParseExecutors.main());
        }
    };
}

From source file:com.webcrawler.manager.impl.ImageManagerImpl.java

@Override
public List<ImageDTO> getImageData(final String url)
        throws IOException, IllegalArgumentException, InterruptedException, ExecutionException {

    if (url == null || url.equals("")) {
        throw new IllegalArgumentException("Set URL first");
    }//  ww w .ja v  a2 s  .c  o  m

    Callable<List<ImageDTO>> callable = new Callable<List<ImageDTO>>() {

        @Override
        public List<ImageDTO> call() throws Exception {
            System.out.println("Retrieving image data from url " + url);

            Document document = null;
            Elements media = null;
            List<ImageDTO> images = new ArrayList<ImageDTO>();
            try {
                document = Jsoup.connect(url).get();
                media = document.select("[src]");
            } catch (Exception e) {
                e.printStackTrace();
                return images;
            }

            System.out.println("# of images: " + media.size());

            for (Element src : media) {
                if (src.tagName().equals("img")) {
                    ImageDTO dto = new ImageDTO();
                    dto.setUrlAddress(src.attr("abs:src"));
                    dto.setFileName(getFileName(src.attr("abs:src")));
                    images.add(dto);
                }
            }

            return images;
        }
    };

    Future<List<ImageDTO>> result = executorService.submit(callable);

    return result.get();

}

From source file:com.sishuok.chapter3.web.controller.CallableController.java

@RequestMapping("/callable2")
public Callable<ModelAndView> callable2() {
    return new Callable<ModelAndView>() {
        @Override//from ww  w.jav a 2 s  .c o  m
        public ModelAndView call() throws Exception {
            Thread.sleep(2L * 1000); //?
            ModelAndView mv = new ModelAndView("msg");
            mv.addObject("msg", "hello callable");
            return mv;
        }
    };
}

From source file:brooklyn.rest.BrooklynRestApiLauncherTest.java

private static void checkRestCatalogApplications(Server server) throws Exception {
    final String rootUrl = "http://localhost:" + server.getConnectors()[0].getLocalPort();
    int code = Asserts.succeedsEventually(new Callable<Integer>() {
        @Override/*from ww w .ja va2 s  .  co  m*/
        public Integer call() throws Exception {
            int code = HttpTestUtils.getHttpStatusCode(rootUrl + "/v1/catalog/applications");
            if (code == HttpStatus.SC_FORBIDDEN) {
                throw new RuntimeException("Retry request");
            } else {
                return code;
            }
        }
    });
    HttpTestUtils.assertHealthyStatusCode(code);
    HttpTestUtils.assertContentContainsText(rootUrl + "/v1/catalog/applications",
            SampleNoOpApplication.class.getSimpleName());
}

From source file:com.rogiel.httpchannel.util.HttpClientUtils.java

public static Future<HttpResponse> executeAsyncHttpResponse(final HttpClient client,
        final HttpUriRequest request) throws IOException {
    return threadPool.submit(new Callable<HttpResponse>() {
        @Override//from   w ww  . j a  v a  2 s  .c o  m
        public HttpResponse call() throws Exception {
            return client.execute(request);
        }
    });
}

From source file:com.adobe.acs.commons.util.ThreadContextClassLoaderTaskExecutorTest.java

@Test
public void test_with_normal_execution() throws Exception {
    final String expectedResult = RandomStringUtils.randomAlphanumeric(10);
    final ClassLoader parent = getClass().getClassLoader();

    final ClassLoader innerLoader = new DummyClassLoader(parent);

    //set the TCCL to something different
    ClassLoader outerLoader = new DummyClassLoader(parent);
    Thread.currentThread().setContextClassLoader(outerLoader);

    String actual = ThreadContextClassLoaderTaskExecutor.doWithTccl(innerLoader, new Callable<String>() {
        @Override/*ww  w.ja va  2  s. co  m*/
        public String call() throws Exception {
            assertEquals(innerLoader, Thread.currentThread().getContextClassLoader());
            return expectedResult;
        }
    });
    assertEquals(expectedResult, actual);
    assertEquals(outerLoader, Thread.currentThread().getContextClassLoader());
}