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:io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.java

private <T> Callable<T> createCallable(final Callable<T> task) {
    return () -> {
        try {// w w  w.  j  av a 2 s .c  om
            return task.call();
        } catch (Exception e) {
            handle(e);
            throw e;
        }
    };
}

From source file:org.apache.mina.springrpc.example.gettingstarted.AbstractHelloServiceClientTests.java

private void execute(List<Callable<HelloResponse>> tasks) {
    for (Callable<HelloResponse> task : tasks) {
        try {//ww  w  . j  a  v  a  2 s  .  co  m
            task.call();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            continue;
        }
    }
}

From source file:com.proofpoint.stats.TimedStat.java

public <T> T time(Callable<T> callable) throws Exception {
    long start = System.nanoTime();
    T result = callable.call();
    addValue(Duration.nanosSince(start));
    return result;
}

From source file:io.fabric8.vertx.maven.plugin.utils.IncrementalBuilder.java

private void triggerBuild(File file) {
    try {/*from   w ww . j a v  a2 s. c  o m*/
        for (Callable<Void> task : chain) {
            task.call();
        }
    } catch (Exception e) {
        //ignore
    }
}

From source file:com.fitbur.testify.system.internal.SpringSystemServletInterceptor.java

@RuntimeType
public Object anyMethod(@SuperCall Callable<?> zuper, @AllArguments Object... args) throws Exception {
    return zuper.call();
}

From source file:com.fitbur.testify.system.internal.SpringSystemServletInterceptor.java

public Class<?>[] getServletConfigClasses(@SuperCall Callable<Class<?>[]> zuper) throws Exception {
    this.servletConfigClasses = zuper.call();

    return servletConfigClasses;
}

From source file:com.watchrabbit.executor.spring.ExecutorAnnotationBeanPostProcessor.java

private Callable<Object> prepareExtractingInvocationExCallable(Callable<Object> callable) {
    return () -> {
        try {//from  w  w  w  .  j  a  v  a 2 s  . c  o  m
            return callable.call();
        } catch (InvocationTargetException ex) {
            LOGGER.debug("Extracting orginally thrown exception");
            if (ex.getTargetException() instanceof Exception) {
                throw (Exception) ex.getTargetException();
            } else {
                throw ex;
            }
        }
    };
}

From source file:pt.webdetails.cpk.testUtils.PentahoSystemForTesting.java

public static <T> T runAsSystem(final Callable<T> callable) throws Exception {
    final String name = "system session"; //$NON-NLS-1$
    IPentahoSession origSession = PentahoSessionHolder.getSession();
    Authentication origAuth = SecurityContextHolder.getContext().getAuthentication();
    try {/*from  ww  w  . j a  v  a  2 s  .c o m*/
        // create pentaho session
        StandaloneSession session = new StandaloneSession(name);
        session.setAuthenticated(name);
        // create authentication

        GrantedAuthority[] roles;

        ISystemSettings settings = PentahoSystem.getSystemSettings();
        String roleName = (settings != null) ? settings.getSystemSetting("acl-voter/admin-role", "Admin")
                : "Admin";

        roles = new GrantedAuthority[1];
        roles[0] = new SimpleGrantedAuthority(roleName);

        Authentication auth = new UsernamePasswordAuthenticationToken(name, "", Arrays.asList(roles)); //$NON-NLS-1$

        // set holders
        PentahoSessionHolder.setSession(session);
        SecurityContextHolder.getContext().setAuthentication(auth);
        return callable.call();
    } finally {
        IPentahoSession sessionToDestroy = PentahoSessionHolder.getSession();
        if (sessionToDestroy != null) {
            try {
                sessionToDestroy.destroy();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        PentahoSessionHolder.setSession(origSession);
        SecurityContextHolder.getContext().setAuthentication(origAuth);
    }
}

From source file:com.aol.advertising.qiao.management.metrics.StatsCollector.java

@Override
public void run() {
    for (Callable<?> c : statsCallable) {
        try {/*from  ww  w  .j  av  a 2  s .  c om*/
            c.call();
        } catch (Throwable e) {
            logger.error(e.getMessage(), e);
        }
    }

}

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

@Test
public void test_asCallable_callable() throws Exception {
    Callable<Long> callable = Mockito.mock(Callable.class);
    ExtendedRetryTemplate template = new ExtendedRetryTemplate();

    Mockito.when(callable.call()).thenReturn(10L);

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

    Mockito.verify(callable, Mockito.times(1)).call();
}