Java Code Examples for java.util.concurrent.CompletableFuture#runAfterEitherAsync()

The following examples show how to use java.util.concurrent.CompletableFuture#runAfterEitherAsync() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhasedRecoveryManager.java    From onos with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: HostHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
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);
    });
}
 
Example 3
Source File: CompletableFutureTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public <T> CompletableFuture<Void> runAfterEither
    (CompletableFuture<T> f,
     CompletionStage<?> g,
     java.lang.Runnable a) {
    return f.runAfterEitherAsync(g, a);
}
 
Example 4
Source File: CompletableFutureTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public <T> CompletableFuture<Void> runAfterEither
    (CompletableFuture<T> f,
     CompletionStage<?> g,
     java.lang.Runnable a) {
    return f.runAfterEitherAsync(g, a, new ThreadExecutor());
}
 
Example 5
Source File: CompletableFutureTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public <T> CompletableFuture<Void> runAfterEither
    (CompletableFuture<T> f,
     CompletionStage<?> g,
     java.lang.Runnable a) {
    return f.runAfterEitherAsync(g, a);
}
 
Example 6
Source File: CompletableFutureTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public <T> CompletableFuture<Void> runAfterEither
    (CompletableFuture<T> f,
     CompletionStage<?> g,
     java.lang.Runnable a) {
    return f.runAfterEitherAsync(g, a, new ThreadExecutor());
}