Example usage for io.vertx.core CompositeFuture succeeded

List of usage examples for io.vertx.core CompositeFuture succeeded

Introduction

In this page you can find the example usage for io.vertx.core CompositeFuture succeeded.

Prototype

boolean succeeded(int index);

Source Link

Document

Returns true if a wrapped future is succeeded

Usage

From source file:io.engagingspaces.graphql.servicediscovery.publisher.SchemaRegistrar.java

License:Open Source License

private void handleCloseCompletion(Handler<AsyncResult<Void>> closeHandler, List<Future> futures) {
    CompositeFuture.all(futures).setHandler(rh -> {
        if (rh.succeeded()) {
            CompositeFuture composite = rh.result();
            for (int index = 0; index < composite.size(); index++) {
                if (composite.succeeded(index) && composite.resultAt(index) != null) {
                    composite.<SchemaRegistration>resultAt(index).unregisterServiceProxy();
                }//from  w  w  w. j  a  va  2 s  . c  o  m
            }
            doClose(closeHandler);
        } else {
            closeHandler.handle(Future.failedFuture(rh.cause()));
        }
    });
}

From source file:io.engagingspaces.vertx.dataloader.DataLoader.java

License:Open Source License

/**
 * Dispatches the queued load requests to the batch execution function and returns a composite future of the result.
 * <p>/*from  www.ja  va  2 s. com*/
 * If batching is disabled, or there are no queued requests, then a succeeded composite future is returned.
 *
 * @return the composite future of the queued load requests
 */
public CompositeFuture dispatch() {
    if (!loaderOptions.batchingEnabled() || loaderQueue.size() == 0) {
        return CompositeFuture.join(Collections.emptyList());
    }
    CompositeFuture batch = batchLoadFunction.load(loaderQueue.keySet());
    dispatchedQueues.put(batch, new LinkedHashMap<>(loaderQueue));
    batch.setHandler(rh -> {
        AtomicInteger index = new AtomicInteger(0);
        dispatchedQueues.get(batch).forEach((key, future) -> {
            if (batch.succeeded(index.get())) {
                future.complete(batch.resultAt(index.get()));
            } else {
                future.fail(batch.cause(index.get()));
            }
            index.incrementAndGet();
        });
        dispatchedQueues.remove(batch);
    });
    loaderQueue.clear();
    return batch;
}