java.util.concurrent.Callable#call ( )源码实例Demo

下面列出了java.util.concurrent.Callable#call ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
@SuppressWarnings("unchecked")
public void test_generation_in_different_isolated_classloaders() throws Exception {
  URL[] cp = new URL[]{
      new File("target/classes").toURI().toURL(),
      new File("target/test-classes").toURI().toURL(),
  };
  URLClassLoader cl1 = new URLClassLoader(cp, this.getClass().getClassLoader());
  URLClassLoader cl2 = new URLClassLoader(cp, this.getClass().getClassLoader());

  Callable<String> runner1 = (Callable<String>) cl1.loadClass("org.terracotta.management.sequence.Runner").newInstance();
  Callable<String> runner2 = (Callable<String>) cl2.loadClass("org.terracotta.management.sequence.Runner").newInstance();

  String seq1 = runner1.call();
  String seq2 = runner2.call();

  System.out.println(seq1);
  System.out.println(seq2);

  assertNotEquals(seq1, seq2);
}
 
源代码2 项目: keycloak   文件: PolicyResource.java
/**
 * Queries the server for a permission with the given {@code id}.
 *
 * @param id the permission id
 * @return the permission with the given id
 */
public UmaPermissionRepresentation findById(final String id) {
    if (id == null) {
        throw new IllegalArgumentException("Permission id must not be null");
    }

    Callable<UmaPermissionRepresentation> callable = new Callable<UmaPermissionRepresentation>() {
        @Override
        public UmaPermissionRepresentation call() {
            return http.<UmaPermissionRepresentation>get(serverConfiguration.getPolicyEndpoint() + "/" + id)
                    .authorizationBearer(pat.call())
                    .response().json(UmaPermissionRepresentation.class).execute();
        }
    };
    try {
        return callable.call();
    } catch (Exception cause) {
        return Throwables.retryAndWrapExceptionIfNecessary(callable, pat, "Error creating policy for resource [" + resourceId + "]", cause);
    }
}
 
源代码3 项目: openemm   文件: WorkflowParametersHelper.java
@SuppressWarnings("unchecked")
private static <T> T convertOrNull(Object value, Class<T> type, Callable<T> handleStringValue) {
       if (value == null) {
           return null;
       }
       
       if (value instanceof String) {
           try {
               return handleStringValue.call();
           } catch (Exception e) {
               logger.error("Could not convert value to " + type.getName() + " type", e);
               return null;
           }
       }
       
       if (type.isInstance(value)) {
           return (T) value;
       }
       
       return null;
   }
 
源代码4 项目: cloudbreak   文件: SaltOrchestrator.java
private void callBackupRestore(GatewayConfig primaryGateway, Set<String> target, Set<Node> allNodes, SaltConfig saltConfig,
        ExitCriteriaModel exitModel, String state) throws CloudbreakOrchestratorFailedException {
    try (SaltConnector sc = createSaltConnector(primaryGateway)) {
        for (Entry<String, SaltPillarProperties> propertiesEntry : saltConfig.getServicePillarConfig().entrySet()) {
            OrchestratorBootstrap pillarSave = new PillarSave(sc, Sets.newHashSet(primaryGateway.getPrivateAddress()), propertiesEntry.getValue());
            Callable<Boolean> saltPillarRunner = saltRunner.runner(pillarSave, exitCriteria, exitModel, maxRetry, true);
            saltPillarRunner.call();
        }

        StateRunner stateRunner = new StateRunner(target, allNodes, state);
        OrchestratorBootstrap saltJobIdTracker = new SaltJobIdTracker(sc, stateRunner);
        Callable<Boolean> saltJobRunBootstrapRunner = saltRunner.runner(saltJobIdTracker, exitCriteria, exitModel, maxRetry, true);
        saltJobRunBootstrapRunner.call();
    } catch (Exception e) {
        LOGGER.error("Error occurred during database backup/restore", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
 
源代码5 项目: resilience4j   文件: CallableUtils.java
/**
 * Returns a composed Callable that first executes the Callable and optionally recovers from a specific result.
 *
 * @param <T>              return type of after
 * @param callable the callable
 * @param resultPredicate the result predicate
 * @param resultHandler the result handler
 * @return a function composed of supplier and exceptionHandler
 */
public static <T> Callable<T> recover(Callable<T> callable,
    Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) {
    return () -> {
        T result = callable.call();
        if(resultPredicate.test(result)){
            return resultHandler.apply(result);
        }
        return result;
    };
}
 
源代码6 项目: openjdk-jdk9   文件: Connect.java
void testCCE(Callable callable) {
    try {
        callable.call();
        fail("should have thrown ClosedChannelException");
    } catch (ClosedChannelException cce) {
       pass();
    } catch (Exception ioe) {
        unexpected(ioe);
    }
}
 
源代码7 项目: cssfx   文件: CSSFX.java
private Runnable start(Callable<CSSFXMonitor> monitorBuilder) {
    CSSFXMonitor mon;
    try {
        mon = monitorBuilder.call();
        mon.addAllConverters(converters);
        mon.start();
        return mon::stop;
    } catch (Exception e) {
        throw new RuntimeException("could not create CSSFXMonitor", e);
    }
}
 
源代码8 项目: metrics-cdi   文件: MonotonicCountedMethodBean.java
@Counted(name = "monotonicCountedMethod", absolute = true, monotonic = true)
public T monotonicCountedMethod(Callable<T> callable) {
    try {
        return callable.call();
    } catch (Exception cause) {
        throw new RuntimeException(cause);
    }
}
 
源代码9 项目: redis-rdb-cli   文件: OutputStreams.java
public static <T> T callQuietly(Callable<T> callable) {
    if (callable == null) return null;
    try {
        return callable.call();
    } catch (Throwable txt) {
        return null;
    }
}
 
public static Single<Integer> create(Callable<Connection> connectionFactory, List<Object> parameters, String sql) {
    Callable<PreparedStatement> resourceFactory = () -> {
        Connection con = connectionFactory.call();
        // TODO set parameters
        return con.prepareStatement(sql);
    };
    Function<PreparedStatement, Single<Integer>> singleFactory = ps -> Single.just(ps.executeUpdate());
    Consumer<PreparedStatement> disposer = Update::closeAll;
    return Single.using(resourceFactory, singleFactory, disposer);
}
 
@Override
public <T> Callable<T> wrapCallable(final Callable<T> callable) {
    return new Callable<T>() {
        @Override
        public T call() throws Exception {
            return callable.call();
        }
    };
}
 
源代码12 项目: estatio   文件: IndexValueRepository_Test.java
private static Action executeCallableAndReturn() {
    return new Action() {
        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            Callable<Object> callable = (Callable<Object>) invocation.getParameter(0);
            return callable.call();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("execute arg 0 as callable and return");
        }
    };
}
 
源代码13 项目: fabric8-forge   文件: CamelGetComponentsCommand.java
@Override
public Result execute(UIExecutionContext context) throws Exception {
    Project project = getSelectedProject(context);
    boolean excludeProjectComponents = isValueTrue(excludeProject);
    Callable<Iterable<ComponentDto>> callable = CamelCommandsHelper.createAllComponentDtoValues(project, getCamelCatalog(), filter, excludeProjectComponents);
    Iterable<ComponentDto> results = callable.call();
    String result = formatResult(results);
    return Results.success(result);
}
 
源代码14 项目: youran   文件: JsonUtil.java
/**
 * 将声明式异常包装成运行时异常抛出
 * @param callable
 * @param <T>
 * @return
 */
private static <T> T doConvertRuntimeException(Callable<T> callable) {
    try {
        return callable.call();
    } catch (Exception e) {
        LOGGER.error("json序列化异常", e);
        if(e instanceof RuntimeException){
            throw (RuntimeException)e;
        }else {
            throw new RuntimeException("json序列化异常", e);
        }
    }
}
 
源代码15 项目: hbase   文件: PerformanceEvaluation.java
public static <V> V propagate(Callable<V> callable) {
  try {
    return callable.call();
  } catch (Exception e) {
    throw runtime(e);
  }
}
 
源代码16 项目: ignite   文件: HadoopAbstractMapTest.java
/** {@inheritDoc} */
@Override public <T> T runAsJobOwner(Callable<T> c) throws IgniteCheckedException {
    try {
        return c.call();
    }
    catch (Exception e) {
        throw new IgniteCheckedException(e);
    }
}
 
源代码17 项目: totallylazy   文件: CountLatch.java
public static <A> Function0<A> monitor(final Callable<? extends A> callable, final CountLatch latch) {
    return () -> {
        latch.countUp();
        try {
            return callable.call();
        } finally {
            latch.countDown();
        }
    };
}
 
源代码18 项目: tomee   文件: Executor.java
@Asynchronous
public <T> Future<T> submit(Callable<T> task) throws Exception {
    return new AsyncResult<T>(task.call());
}
 
源代码19 项目: flink   文件: StreamTaskExecutionDecorationTest.java
@Override
public <R> R call(Callable<R> callable) throws Exception {
	calls.incrementAndGet();
	return callable.call();
}
 
源代码20 项目: pushfish-android   文件: GradleWorkerMain.java
public void run() throws Exception {
    // Read the main action from stdin and execute it
    ObjectInputStream instr = new ObjectInputStream(new EncodedStream.EncodedInput(System.in));
    Callable<?> main = (Callable<?>) instr.readObject();
    main.call();
}
 
 同类方法