List of usage examples for io.vertx.core CompositeFuture resultAt
<T> T resultAt(int index);
From source file:com.github.ithildir.airbot.util.AirQualityMessageBuilder.java
License:Open Source License
public Future<String> getMessage(Location location, String locationString, Locale locale) { Future<String> future = Future.future(); MeasurementService measurementService = _getMeasurementService(location); Future<Measurement> measurementFuture = Future.future(); Future<String> nameFuture = Future.future(); measurementService.getMeasurement(location.getLatitude(), location.getLongitude(), measurementFuture); measurementService.getName(nameFuture); CompositeFuture compositeFuture = CompositeFuture.all(measurementFuture, nameFuture); compositeFuture.setHandler(asyncResult -> { if (asyncResult.failed()) { future.fail(asyncResult.cause()); return; }/*w w w .jav a2 s. c o m*/ CompositeFuture resultCompositeFuture = asyncResult.result(); Measurement measurement = (Measurement) resultCompositeFuture.resultAt(0); String name = (String) resultCompositeFuture.resultAt(1); String message = _getMessage(measurement, name, locationString, locale); future.complete(message); }); return future; }
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 ava 2 s .com } 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 w w w. j a v a 2s. co m * 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; }