List of usage examples for io.vertx.core Future failed
@Override
boolean failed();
From source file:io.flowly.core.verticles.VerticleUtils.java
License:Open Source License
private static void undeployVerticles(Iterator<String> deployementIds, Vertx vertx, Future<Void> undeployedFuture) { // Ensure that vertx platform has the deployment ids. // The list specified by the caller might be stale. List<String> actualDeploymentIds = new ArrayList<>(); Set<String> vertxDeploymentIds = vertx.deploymentIDs(); while (deployementIds.hasNext()) { String deploymentId = deployementIds.next(); if (vertxDeploymentIds.contains(deploymentId)) { actualDeploymentIds.add(deploymentId); }//from w w w . j av a 2s .c o m } if (actualDeploymentIds.isEmpty()) { undeployedFuture.complete(); } else { AtomicInteger counter = new AtomicInteger(0); for (String deploymentId : actualDeploymentIds) { vertx.undeploy(deploymentId, d -> { if (d.succeeded()) { if (counter.incrementAndGet() == actualDeploymentIds.size()) { undeployedFuture.complete(); } } else if (!undeployedFuture.failed()) { undeployedFuture.fail(d.cause()); } }); } } }
From source file:io.flowly.engine.verticles.Build.java
License:Open Source License
private void saveFlows(List<Flow> flows, Handler<AsyncResult<Void>> resultHandler) { Future<Void> future = Future.future(); future.setHandler(resultHandler);/*from w w w . j a v a 2 s.co m*/ // Save flow and its router in the repository. AtomicInteger counter = new AtomicInteger(0); for (Flow flow : flows) { vertx.eventBus().send(EngineAddresses.REPO_FLOW_SAVE, flow, reply -> { if (reply.succeeded() && (Boolean) reply.result().body()) { if (counter.incrementAndGet() == flows.size()) { future.complete(); } } else if (!future.failed()) { future.fail(reply.cause()); } }); } }
From source file:io.gravitee.gateway.core.failover.FailoverInvoker.java
License:Apache License
@Override public void invoke(ExecutionContext context, ReadStream<Buffer> stream, Handler<ProxyConnection> connectionHandler) { ((MutableExecutionContext) context).request(new FailoverRequest(context.request())); circuitBreaker.execute(new io.vertx.core.Handler<Future<ProxyConnection>>() { @Override//www. ja v a 2 s. c o m public void handle(Future<ProxyConnection> event) { FailoverInvoker.super.invoke(context, stream, proxyConnection -> { proxyConnection.exceptionHandler(event::fail); proxyConnection.responseHandler( response -> event.complete(new FailoverProxyConnection(proxyConnection, response))); }); } }).setHandler(new io.vertx.core.Handler<AsyncResult<ProxyConnection>>() { @Override public void handle(AsyncResult<ProxyConnection> event) { if (event.failed()) { FailoverConnection connection = new FailoverConnection(); connectionHandler.handle(connection); connection.sendBadGatewayResponse(); } else { FailoverProxyConnection proxyConnection = (FailoverProxyConnection) event.result(); connectionHandler.handle(proxyConnection); proxyConnection.sendResponse(); } } }); }
From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java
License:Open Source License
private void doUploadMessage(final RoutingContext ctx, final String tenant, final String deviceId, final Buffer payload, final String contentType, final Future<MessageSender> senderTracker, final String endpointName) { if (contentType == null) { badRequest(ctx.response(), String.format("%s header is missing", HttpHeaders.CONTENT_TYPE)); metrics.incrementUndeliverableHttpMessages(endpointName, tenant); } else if (payload == null || payload.length() == 0) { badRequest(ctx.response(), "missing body"); metrics.incrementUndeliverableHttpMessages(endpointName, tenant); } else {//from www. jav a 2 s .co m final Future<String> tokenTracker = getRegistrationAssertionHeader(ctx, tenant, deviceId); CompositeFuture.all(tokenTracker, senderTracker).setHandler(s -> { if (s.failed()) { if (tokenTracker.failed()) { LOG.debug("could not get registration assertion [tenant: {}, device: {}]", tenant, deviceId, s.cause()); endWithStatus(ctx.response(), HTTP_FORBIDDEN, null, null, null); } else { serviceUnavailable(ctx.response(), 5); } metrics.incrementUndeliverableHttpMessages(endpointName, tenant); } else { sendToHono(ctx.response(), deviceId, payload, contentType, tokenTracker.result(), senderTracker.result(), tenant, endpointName); } }); } }