下面列出了java.util.concurrent.CompletableFuture#runAfterEitherAsync ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void monitorRoutingStability(DeviceId deviceId) {
CompletableFuture<Void> checkerFuture = new CompletableFuture<>();
CompletableFuture<Void> timeoutFuture =
Tools.completeAfter(ROUTING_CHECKER_TIMEOUT, TimeUnit.SECONDS);
RoutingStabilityChecker checker = new RoutingStabilityChecker(checkerFuture);
checkerFuture.runAfterEitherAsync(timeoutFuture, () -> {
if (checkerFuture.isDone()) {
log.info("Routing stable. Move {} to the next phase", deviceId);
} else {
log.info("Timeout reached. Move {} to the next phase", deviceId);
// Mark the future as completed to signify the termination of periodical checker
checkerFuture.complete(null);
}
setPhase(deviceId, Phase.EDGE);
});
executor.schedule(checker, ROUTING_CHECKER_DELAY, TimeUnit.SECONDS);
}
protected void init(DeviceId devId) {
log.info("Initializing hosts on {}", devId);
List<CompletableFuture<Void>> hostFutures = Lists.newArrayList();
// Init hosts in parallel using hostWorkers executor
hostService.getHosts().forEach(host -> {
hostFutures.add(hostWorkers.submit(() -> initHost(host, devId), host.id().hashCode()));
});
log.debug("{} hostFutures for {}", hostFutures.size(), devId);
CompletableFuture<Void> allHostFuture = CompletableFuture.allOf(hostFutures.toArray(new CompletableFuture[0]));
CompletableFuture<Void> timeoutFuture =
Tools.completeAfter(PhasedRecoveryService.PAIR_TIMEOUT, TimeUnit.SECONDS);
allHostFuture.runAfterEitherAsync(timeoutFuture, () -> {
if (allHostFuture.isDone()) {
log.info("{} hosts initialized. Move {} to the next phase", hostFutures.size(), devId);
} else {
log.info("Timeout reached. Move {} to the next phase", devId);
}
srManager.phasedRecoveryService.setPhase(devId, Phase.INFRA);
});
}
public <T> CompletableFuture<Void> runAfterEither
(CompletableFuture<T> f,
CompletionStage<?> g,
java.lang.Runnable a) {
return f.runAfterEitherAsync(g, a);
}
public <T> CompletableFuture<Void> runAfterEither
(CompletableFuture<T> f,
CompletionStage<?> g,
java.lang.Runnable a) {
return f.runAfterEitherAsync(g, a, new ThreadExecutor());
}
public <T> CompletableFuture<Void> runAfterEither
(CompletableFuture<T> f,
CompletionStage<?> g,
java.lang.Runnable a) {
return f.runAfterEitherAsync(g, a);
}
public <T> CompletableFuture<Void> runAfterEither
(CompletableFuture<T> f,
CompletionStage<?> g,
java.lang.Runnable a) {
return f.runAfterEitherAsync(g, a, new ThreadExecutor());
}