Example usage for java.util.concurrent Callable call

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

Introduction

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

Prototype

V call() throws Exception;

Source Link

Document

Computes a result, or throws an exception if unable to do so.

Usage

From source file:org.sonar.server.db.migrations.v36.ViolationConvertersTest.java

@Test
public void propagate_converter_failure() throws Exception {
    Callable<Object> callable = mock(Callable.class);
    when(callable.call()).thenThrow(new IllegalStateException("Need to cry"));

    List<Callable<Object>> callables = Lists.newArrayList(callable);
    try {//from w w w .  jav  a  2 s  . co  m
        new ViolationConverters(new Settings()).doExecute(new FakeTimerTask(), callables);
        fail();
    } catch (Exception e) {
        assertThat(ExceptionUtils.getRootCause(e).getMessage()).isEqualTo("Need to cry");
    }

}

From source file:hivemall.smile.utils.SmileTaskExecutor.java

public <T> List<T> run(Collection<? extends Callable<T>> tasks) throws Exception {
    final List<T> results = new ArrayList<T>(tasks.size());
    if (exec == null) {
        for (Callable<T> task : tasks) {
            results.add(task.call());
        }/*  w  ww. j a  v a2s.  co m*/
    } else {
        final List<Future<T>> futures = exec.invokeAll(tasks);
        for (Future<T> future : futures) {
            results.add(future.get());
        }
    }
    return results;
}

From source file:com.francetelecom.clara.cloud.commons.PersistenceTestUtil.java

/**
 * Executes the given Calleable on the current thread within a new Transational context, and returns the computed result
 *//*from www.  j a v a 2  s  . c om*/
@Transactional
public <T> T executeWithinTransaction(Callable<T> calleable) throws Exception {
    return calleable.call();
}

From source file:org.codehaus.mojo.unix.core.FsFileCollector.java

public void collect() throws Exception {
    for (Callable operation : operations) {
        operation.call();
    }/*from  www.j  a v  a  2s  .  c  o m*/
}

From source file:org.obiba.mica.core.ExceptionHandlingAsyncTaskExecutor.java

private <T> Callable<T> createCallable(Callable<T> task) {
    return () -> {
        try {//from w  w  w  .  j a v  a2 s  .c  o m
            return task.call();
        } catch (Exception e) {
            handle(e);
            throw e;
        }
    };
}

From source file:com.gu.management.timing.LoggingStopWatch.java

private <T> T executeAndTime(Callable<T> callable) throws Exception {
    start();//from  ww  w .  j  av  a2  s  .  c o m
    T value = callable.call();
    stop();
    return value;
}

From source file:net.orfjackal.retrolambda.test.InterfaceStaticMethodsTest.java

@Test
public void calling_static_methods_on_interfaces_from_method_references() throws Exception {
    Callable<Integer> c = Interface::staticMethod;
    assertThat(c.call(), is(42));
}

From source file:org.force66.mediator.TaskMediator.java

public T invoke(Callable<T> operation) {
    Validate.notNull(operation, "Null operation not allowed.");
    try {// w  w  w . ja va 2 s .  co  m
        T output = operation.call();
        return output;
    } catch (Exception e) {
        taskErrorHandler.handle(e, operation);
        return defaultResponse;
    }
}

From source file:org.fishwife.jrugged.spring.retry.ExtendedRetryTemplateTest.java

@Test
public void test_asCallable_callback() throws Exception {
    RetryCallback<Long> callback = Mockito.mock(RetryCallback.class);
    ExtendedRetryTemplate template = new ExtendedRetryTemplate();

    Mockito.when(callback.doWithRetry(Mockito.any(RetryContext.class))).thenReturn(10L);

    Callable<Long> wrapped = template.asCallable(callback);
    Assert.assertEquals(10L, wrapped.call().longValue());

    Mockito.verify(callback, Mockito.times(1)).doWithRetry(Mockito.any(RetryContext.class));
}

From source file:net.orfjackal.retrolambda.test.InterfaceStaticMethodsTest.java

@Test
public void calling_static_methods_on_interfaces_from_lambdas() throws Exception {
    Callable<Integer> c = () -> Interface.staticMethod();
    assertThat(c.call(), is(42));
}