List of usage examples for io.vertx.core CompositeFuture all
static <T1, T2, T3> CompositeFuture all(Future<T1> f1, Future<T2> f2, Future<T3> f3)
From source file:org.eclipse.hono.adapter.mqtt.AbstractVertxBasedMqttProtocolAdapter.java
License:Open Source License
private Future<Void> uploadMessage(final MqttContext ctx, final String tenant, final String deviceId, final Buffer payload, final Future<MessageSender> senderTracker, final String endpointName) { if (!isPayloadOfIndicatedType(payload, ctx.contentType())) { return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, String.format("Content-Type %s does not match with the payload", ctx.contentType()))); } else {//from w w w .jav a 2s. c om final Future<JsonObject> tokenTracker = getRegistrationAssertion(tenant, deviceId, ctx.authenticatedDevice()); final Future<TenantObject> tenantConfigTracker = getTenantConfiguration(tenant); return CompositeFuture.all(tokenTracker, tenantConfigTracker, senderTracker).compose(ok -> { if (tenantConfigTracker.result().isAdapterEnabled(getTypeName())) { final MessageSender sender = senderTracker.result(); final Message downstreamMessage = newMessage( ResourceIdentifier.from(endpointName, tenant, deviceId), sender.isRegistrationAssertionRequired(), ctx.message().topicName(), ctx.contentType(), payload, tokenTracker.result(), null); customizeDownstreamMessage(downstreamMessage, ctx); if (ctx.message().qosLevel() == MqttQoS.AT_LEAST_ONCE) { return sender.sendAndWaitForOutcome(downstreamMessage); } else { return sender.send(downstreamMessage); } } else { // this adapter is not enabled for the tenant return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN)); } }).compose(delivery -> { LOG.trace( "successfully processed message [topic: {}, QoS: {}] for device [tenantId: {}, deviceId: {}]", ctx.message().topicName(), ctx.message().qosLevel(), tenant, deviceId); metrics.incrementProcessedMqttMessages(endpointName, tenant); onMessageSent(ctx); // check that the remote MQTT client is still connected before sending PUBACK if (ctx.deviceEndpoint().isConnected() && ctx.message().qosLevel() == MqttQoS.AT_LEAST_ONCE) { ctx.deviceEndpoint().publishAcknowledge(ctx.message().messageId()); } return Future.<Void>succeededFuture(); }).recover(t -> { if (ClientErrorException.class.isInstance(t)) { final ClientErrorException e = (ClientErrorException) t; LOG.debug( "cannot process message for device [tenantId: {}, deviceId: {}, endpoint: {}]: {} - {}", tenant, deviceId, endpointName, e.getErrorCode(), e.getMessage()); } else { LOG.debug("cannot process message for device [tenantId: {}, deviceId: {}, endpoint: {}]", tenant, deviceId, endpointName, t); metrics.incrementUndeliverableMqttMessages(endpointName, tenant); onMessageUndeliverable(ctx); } return Future.failedFuture(t); }); } }
From source file:org.eclipse.hono.deviceregistry.Application.java
License:Open Source License
@Override protected final Future<Void> deployRequiredVerticles(int maxInstances) { Future<Void> result = Future.future(); CompositeFuture.all(deployAuthenticationService(), // we only need 1 authentication service deployRegistrationService(), deployCredentialsService()).setHandler(ar -> { if (ar.succeeded()) { result.complete();//from w w w. j a va 2s . c om } else { result.fail(ar.cause()); } }); return result; }
From source file:org.eclipse.hono.service.AbstractProtocolAdapterBase.java
License:Open Source License
/** * Closes the connections to the Hono Messaging component and the Device Registration service. * //from ww w . j av a 2 s.c o m * @param closeHandler The handler to notify about the result. */ protected final void closeClients(final Handler<AsyncResult<Void>> closeHandler) { Future<Void> messagingTracker = Future.future(); Future<Void> registrationTracker = Future.future(); Future<Void> credentialsTracker = Future.future(); if (messaging == null) { messagingTracker.complete(); } else { messaging.shutdown(messagingTracker.completer()); } if (registration == null) { registrationTracker.complete(); } else { registration.shutdown(registrationTracker.completer()); } if (credentials == null) { credentialsTracker.complete(); } else { credentials.shutdown(credentialsTracker.completer()); } CompositeFuture.all(messagingTracker, registrationTracker, credentialsTracker).setHandler(s -> { if (closeHandler != null) { if (s.succeeded()) { closeHandler.handle(Future.succeededFuture()); } else { closeHandler.handle(Future.failedFuture(s.cause())); } } }); }
From source file:studio.lysid.scales.deploy.LauncherVerticle.java
License:Open Source License
@Override public void start(Future<Void> startFuture) throws Exception { DeploymentOptionsParser.parseVerticleDeploymentOptionsJsonFile(); // We can safely deploy Command, EventStore, and Query in parallel. // Facade must be the last one. Future<Void> startEventStoreFuture = startVerticle(this.vertx, Verticle.EventStore); Future<Void> startCommandFuture = startVerticle(this.vertx, Verticle.Command); Future<Void> startQueryFuture = startVerticle(this.vertx, Verticle.Query); CompositeFuture.all(startCommandFuture, startEventStoreFuture, startQueryFuture).setHandler(ar -> { if (ar.succeeded()) { startFuture.setHandler(startVerticle(this.vertx, Verticle.Facade).completer()); } else {//from www . j a v a 2 s. co m startFuture.fail(ar.cause()); } }); }