Example usage for java.util.concurrent CompletableFuture thenComposeAsync

List of usage examples for java.util.concurrent CompletableFuture thenComposeAsync

Introduction

In this page you can find the example usage for java.util.concurrent CompletableFuture thenComposeAsync.

Prototype

public <U> CompletableFuture<U> thenComposeAsync(Function<? super T, ? extends CompletionStage<U>> fn) 

Source Link

Usage

From source file:org.apache.storm.localizer.AsyncLocalizer.java

public synchronized CompletableFuture<Void> requestDownloadTopologyBlobs(final LocalAssignment assignment,
        final int port, final BlobChangingCallback cb) throws IOException {
    final String topologyId = assignment.get_topology_id();

    CompletableFuture<Void> baseBlobs = requestDownloadBaseTopologyBlobs(assignment, port, cb);
    return baseBlobs.thenComposeAsync((v) -> {
        LocalDownloadedResource localResource = blobPending.get(topologyId);
        if (localResource == null) {
            Supplier<Void> supplier = new DownloadBlobs(topologyId, assignment.get_owner());
            localResource = new LocalDownloadedResource(CompletableFuture.supplyAsync(supplier, execService));
            blobPending.put(topologyId, localResource);
        }//from  w  w w  .  j a va2  s .  c  o m
        CompletableFuture<Void> r = localResource.reserve(port, assignment);
        LOG.debug("Reserved blobs {} {}", topologyId, localResource);
        return r;
    });
}