List of usage examples for java.util.concurrent Callable call
V call() throws Exception;
From source file:org.libreplan.web.planner.reassign.ReassignCommand.java
private <T> T resolve(Callable<T> callable) { try {//from w w w .j av a 2 s . c om return callable.call(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.meltmedia.dropwizard.crypto.EncryptCommandTest.java
@Test public void testEncryptionAtDeepPath() throws Exception { mockInput(namespace, "secret: {nested: value}"); Callable<String> output = mockOutput(namespace); mockPointer(namespace, "/secret/nested"); Commands.Encrypt encryptCommand = new Commands.Encrypt("encrypt", "desc", service); encryptCommand.run(null, namespace); JsonNode result = yamlMapper.readValue(output.call(), JsonNode.class); assertThat(result.at("/secret/nested/value").isMissingNode(), equalTo(false)); }
From source file:io.syndesis.filestore.impl.SqlFileStoreTest.java
private <T> void expectInvalidPath(Callable<T> callable) { assertNotNull(callable);//from w w w. ja v a2 s. co m try { callable.call(); Assert.fail("Expected exception"); } catch (FileStoreException ex) { assertTrue(ex.getMessage().startsWith("Invalid path")); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) { Assert.fail("Got generic exception"); } }
From source file:net.stuxcrystal.airblock.canary.CanaryServerBackend.java
@Override public <R> R callInMainThread(Callable<R> callable) throws Throwable { if (this.mTID == -1) throw new IllegalStateException("We do not know the main-thread id yet."); if (Thread.currentThread().getId() == this.mTID) { return callable.call(); }//w ww. ja v a2 s . co m FutureTask<R> ft = new FutureTask<R>(callable); this.runLater(ft); return ft.get(); }
From source file:org.fishwife.jrugged.spring.retry.ExtendedRetryTemplate.java
/*** * Execute a given {@link Callable} with retry logic. * * @param callable The callable to execute * @param retryState The current retryState * @param <T> The return type of the callable * @return The result of the callable//from w w w . j av a2 s.c o m * @throws Exception * @throws ExhaustedRetryException If all retry attempts have been exhausted */ public <T> T execute(final Callable<T> callable, RetryState retryState) throws Exception, ExhaustedRetryException { return execute(new RetryCallback<T>() { public T doWithRetry(RetryContext retryContext) throws Exception { return callable.call(); } }, retryState); }
From source file:org.apache.lucene.replicator.http.HttpClientBase.java
/** * Do a specific action and validate after the action that the status is still OK, * and if not, attempt to extract the actual server side exception. Optionally * release the response at exit, depending on <code>consume</code> parameter. *///w ww .j av a 2s. c o m protected <T> T doAction(HttpResponse response, boolean consume, Callable<T> call) throws IOException { Throwable th = null; try { return call.call(); } catch (Throwable t) { th = t; } finally { try { verifyStatus(response); } finally { if (consume) { EntityUtils.consumeQuietly(response.getEntity()); } } } assert th != null; // extra safety - if we get here, it means the callable failed IOUtils.reThrow(th); return null; // silly, if we're here, IOUtils.reThrow always throws an exception }
From source file:org.force66.insanity.RetryManager.java
public T invoke(Callable<T> operation) { Validate.notNull(operation, "Null operation not allowed."); int nbrTries = 0; Exception lastFailure = null; retryAlgorithm.reset();/*ww w . j a v a 2 s . c o m*/ while (retryAlgorithm.isExecutionAllowed()) { nbrTries++; try { T output = operation.call(); return output; } catch (Exception e) { lastFailure = e; retryAlgorithm.reportExecutionFailure(e); } } throw new RetryException("invocation not successful.", lastFailure) .addContextValue("callable class", operation.getClass().getName()) .addContextValue("callable", operation.toString()).addContextValue("nbrTries", nbrTries); }
From source file:net.orfjackal.retrolambda.test.LambdaTest.java
@Test public void method_references_to_interface_methods() throws Exception { List<String> foos = Arrays.asList("foo"); Callable<Integer> ref = foos::size; assertThat(ref.call(), is(1)); }
From source file:ddf.catalog.validation.impl.ValidationParser.java
private void commitStaged(Collection<Callable<Boolean>> stagedAdds) throws Exception { for (Callable<Boolean> staged : stagedAdds) { try {/*w w w.j a va 2 s.c om*/ staged.call(); } catch (RuntimeException e) { LOGGER.warn("Error adding staged item {}", staged, e); } } stagedAdds.clear(); }
From source file:net.orfjackal.retrolambda.test.LambdaTest.java
@Test public void method_references_to_virtual_methods_on_local_variables() throws Exception { String foo = "foo"; Callable<String> ref = foo::toUpperCase; assertThat(ref.call(), is("FOO")); }