List of usage examples for java.util.concurrent Callable call
V call() throws Exception;
From source file:com.acuityph.commons.util.Benchmark.java
/** * Run and benchmark a {@link Callable} and return its result. * * @param <T>//from w w w . j a va 2s . c o m * a type * @param callable * the {@link Callable} to call * @return the result of the call * @throws Exception * on exception */ public final <T> T call(final Callable<T> callable) throws Exception { start(); T result = null; try { result = callable.call(); } finally { stop(); } return result; }
From source file:name.martingeisse.common.util.PassthroughCache.java
@Override public V get(K key, Callable<? extends V> producer) throws ExecutionException { try {/* w w w. j a v a 2 s . c o m*/ return producer.call(); } catch (Exception e) { throw new ExecutionException(e); } }
From source file:com.acuityph.commons.util.Benchmark.java
/** * Run and benchmark a named {@link Callable} and return its result. * * @param <T>/*ww w . ja v a2s. c o m*/ * a type * @param taskName * the task name * @param callable * the {@link Callable} to call * @return the result of the call * @throws Exception * on exception */ public final <T> T call(final String taskName, final Callable<T> callable) throws Exception { start(taskName); T result = null; try { result = callable.call(); } finally { stop(); } return result; }
From source file:org.compass.core.executor.DefaultExecutorManager.java
public <T> List<Future<T>> invokeAllWithLimit(Collection<Callable<T>> tasks, int concurrencyThreshold) { if (disabled) { throw new UnsupportedOperationException("Executor Manager is disabled"); }/*www.j a va2 s .c o m*/ if (tasks.size() == 0) { return new ArrayList<Future<T>>(0); } List<Future<T>> futures; if (tasks.size() > concurrencyThreshold) { try { futures = invokeAll(tasks); } catch (InterruptedException e) { throw new ExecutorException("Interrupted while executing tasks", e); } } else { futures = new ArrayList<Future<T>>(); for (Callable<T> commit : tasks) { try { futures.add(new DummyFuture<T>(commit.call())); } catch (Exception e) { futures.add(new DummyFuture<T>(e)); } } } return futures; }
From source file:com.fitbur.testify.system.internal.SpringSystemServletInterceptor.java
public WebApplicationContext createServletApplicationContext(@SuperCall Callable<WebApplicationContext> zuper) throws Exception { this.context = (AnnotationConfigWebApplicationContext) zuper.call(); context.setId(testContext.getName()); context.setAllowBeanDefinitionOverriding(true); context.setAllowCircularReferences(false); Class<?>[] modules = testContext.getAnnotations(Module.class).stream().map(Module::value) .toArray(Class[]::new); if (modules != null && modules.length != 0) { context.register(modules);//w w w . j a v a 2 s. com } serviceLocator = new SpringServiceLocator(context, serviceAnnotations); methodTestNeeds = new TestNeeds(testContext, methodName, NeedScope.METHOD); methodTestNeeds.init(); methodTestNeedContainers = new TestNeedContainers(testContext, methodName, NeedScope.METHOD); methodTestNeedContainers.init(); SpringServicePostProcessor postProcessor = new SpringServicePostProcessor(serviceLocator, methodTestNeeds, methodTestNeedContainers, classTestNeeds, classTestNeedContainers); context.addBeanFactoryPostProcessor(postProcessor); return context; }
From source file:fr.litarvan.commons.crash.ExceptionHandler.java
public <T> T handler(Callable<T> callable, T def) { try {//from ww w. ja v a 2 s . c o m return callable.call(); } catch (Throwable t) { handle(t); } return def; }
From source file:org.fornax.cartridges.sculptor.framework.richclient.errorhandling.ExceptionAware.java
public T run(java.util.concurrent.Callable<T> callable) { try {//from ww w.ja v a2 s .com return callable.call(); } catch (ApplicationException e) { return handleApplicationException(e); } catch (OptimisticLockingException e) { return handleOptimisticLockingException(e); } catch (ValidationException e) { return handleValidationException(e); } catch (RemoteAccessException e) { return handleRemoteAccessException(e); } catch (Exception e) { return handleWrappingException(e); } catch (Error e) { return handleError(e); } }
From source file:org.zanata.sync.jobs.cache.RepoCache.java
default void get(String url, Path dest, Callable<Path> loader) { if (!getAndCopyToIfPresent(url, dest)) { try {// w ww . j a v a 2 s. c om Path source = loader.call(); put(url, source); } catch (Exception e) { log.error("error calling the cache loader", e); throw new RepoSyncException(e.getMessage()); } } }
From source file:com.fitbur.testify.junit.system.internal.SpringBootInterceptor.java
public void prepareEmbeddedWebApplicationContext(@SuperCall Callable<Void> zuper, @This Object object, @AllArguments Object[] args) throws Exception { zuper.call(); SpringBootDescriptor descriptor = getDescriptor(object); descriptor.setServletContext((ServletContext) args[0]); }
From source file:org.fishwife.jrugged.spring.retry.ExtendedRetryTemplateTest.java
@Test public void test_execute_callableWithState() throws Exception { Callable<Long> callable = Mockito.mock(Callable.class); RetryState retryState = Mockito.mock(RetryState.class); ExtendedRetryTemplate template = new ExtendedRetryTemplate(); Mockito.when(callable.call()).thenReturn(10L); Assert.assertEquals(10L, template.execute(callable, retryState).longValue()); Mockito.verify(callable, Mockito.times(1)).call(); }