List of usage examples for io.vertx.core Future future
future
From source file:org.eclipse.hono.example.ExampleSender.java
License:Open Source License
private Future<String> getRegistrationAssertion() { final Future<String> result = Future.future(); if (token != null) { }/*from www . jav a 2s . c om*/ getRegistrationClient().compose(regClient -> { Future<RegistrationResult> tokenTracker = Future.future(); regClient.assertRegistration(deviceId, tokenTracker.completer()); return tokenTracker; }).compose(regResult -> { if (regResult.getStatus() == HTTP_OK) { result.complete(regResult.getPayload().getString(RegistrationConstants.FIELD_ASSERTION)); } else { result.fail("cannot assert registration status"); } }, result); return result; }
From source file:org.eclipse.hono.example.ExampleSender.java
License:Open Source License
private Future<RegistrationClient> getRegistrationClient() { Future<RegistrationClient> result = Future.future(); client.getOrCreateRegistrationClient(tenantId, result.completer()); return result; }
From source file:org.eclipse.hono.example.ExampleSender.java
License:Open Source License
private Future<Void> send(final String msg, final Map<String, Object> props, final String registrationAssertion) { Future<Void> result = Future.future(); Future<MessageSender> senderTracker = Future.future(); if (activeProfiles.contains("event")) { client.getOrCreateEventSender(tenantId, senderTracker.completer()); } else {/*w w w.ja v a 2 s . com*/ client.getOrCreateTelemetrySender(tenantId, senderTracker.completer()); } senderTracker.compose(sender -> { if (!sender.send(deviceId, props, msg, "text/plain", registrationAssertion)) { LOG.info("sender has no credit (yet), maybe no consumers attached? Try again ..."); } result.complete(); }, result); return result; }
From source file:org.eclipse.hono.messaging.ForwardingDownstreamAdapter.java
License:Open Source License
@Override public final void onClientAttach(final UpstreamReceiver client, final Handler<AsyncResult<Void>> resultHandler) { if (!running) { throw new IllegalStateException("adapter must be started first"); }//from w w w.j a va2 s . c om Objects.requireNonNull(client); Objects.requireNonNull(resultHandler); ProtonSender sender = activeSenders.get(client); if (sender != null && sender.isOpen()) { logger.info("reusing existing downstream sender [con: {}, link: {}]", client.getConnectionId(), client.getLinkId()); resultHandler.handle(Future.succeededFuture()); } else { removeSender(client); // register the result handler to be failed if the connection to the downstream container fails during // the attempt to create a downstream sender clientAttachHandlers.add(resultHandler); Future<Void> tracker = Future.future(); tracker.setHandler(attempt -> { if (attempt.succeeded()) { logger.info("created downstream sender [con: {}, link: {}]", client.getConnectionId(), client.getLinkId()); } else { logger.warn("can't create downstream sender [con: {}, link: {}]: {}", client.getConnectionId(), client.getLinkId(), attempt.cause().getMessage()); } clientAttachHandlers.remove(resultHandler); resultHandler.handle(attempt); }); final ResourceIdentifier targetAddress = ResourceIdentifier.fromString(client.getTargetAddress()); createSender(targetAddress, replenishedSender -> handleFlow(replenishedSender, client)) .compose(createdSender -> { addSender(client, createdSender); tracker.complete(); }, tracker); } }
From source file:org.eclipse.hono.messaging.HonoMessagingApplication.java
License:Open Source License
/** * Deploys the additional service implementations that are * required by the HonoServer./*ww w . j av a 2 s . c om*/ * */ @Override protected Future<Void> deployRequiredVerticles(final int maxInstances) { Future<Void> result = Future.future(); Future<String> authFuture = deployAuthenticationService();// we only need 1 authentication service authFuture.setHandler(ar -> { if (ar.succeeded()) { result.complete(); } else { result.fail(ar.cause()); } }); return result; }
From source file:org.eclipse.hono.messaging.HonoMessagingApplication.java
License:Open Source License
private Future<String> deployAuthenticationService() { Future<String> result = Future.future(); if (!Verticle.class.isInstance(authenticationService)) { result.fail("authentication service is not a verticle"); } else {/*from ww w. j a v a 2 s .c o m*/ LOG.info("Starting authentication service {}", authenticationService); getVertx().deployVerticle((Verticle) authenticationService, result.completer()); } return result; }
From source file:org.eclipse.hono.messaging.SenderFactoryImpl.java
License:Open Source License
private Future<ProtonSession> newSession(final ProtonConnection con, final ResourceIdentifier targetAddress) { final Future<ProtonSession> result = Future.future(); ProtonSession session = con.attachments().get(targetAddress.getEndpoint(), ProtonSession.class); if (session != null) { LOG.debug("re-using existing session for sending {} data downstream", targetAddress.getEndpoint()); result.complete(session);// w ww. j a v a2 s.c o m } else { LOG.debug("creating new session for sending {} data downstream", targetAddress.getEndpoint()); session = con.createSession(); con.attachments().set(targetAddress.getEndpoint(), ProtonSession.class, session); session.openHandler(remoteOpen -> { if (remoteOpen.succeeded()) { result.complete(remoteOpen.result()); } else { result.fail(remoteOpen.cause()); } }); session.open(); } return result; }
From source file:org.eclipse.hono.messaging.SenderFactoryImpl.java
License:Open Source License
private Future<ProtonSender> newSender(final ProtonConnection connection, final ProtonSession session, final ResourceIdentifier address, final ProtonQoS qos, final Handler<ProtonSender> sendQueueDrainHandler) { Future<ProtonSender> result = Future.future(); ProtonSender sender = session.createSender(getTenantOnlyTargetAddress(address)); sender.setQoS(qos);/*from w ww. ja va 2s .c om*/ sender.sendQueueDrainHandler(sendQueueDrainHandler); sender.openHandler(openAttempt -> { if (openAttempt.succeeded()) { LOG.debug("sender [{}] for container [{}] open", address, connection.getRemoteContainer()); result.complete(openAttempt.result()); } else { LOG.debug("could not open sender [{}] for container [{}]", address, connection.getRemoteContainer(), openAttempt.cause()); result.fail(openAttempt.cause()); } }); sender.closeHandler(closed -> { if (closed.succeeded()) { LOG.debug("sender [{}] for container [{}] closed", address, connection.getRemoteContainer()); } }); sender.open(); return result; }
From source file:org.eclipse.hono.server.ForwardingDownstreamAdapter.java
License:Open Source License
@Override public final void onClientAttach(final UpstreamReceiver client, final Handler<AsyncResult<Void>> resultHandler) { if (!running) { throw new IllegalStateException("adapter must be started first"); }/*w w w .j av a 2 s .c om*/ Objects.requireNonNull(client); Objects.requireNonNull(resultHandler); ProtonSender sender = activeSenders.get(client); if (sender != null && sender.isOpen()) { logger.info("reusing existing downstream sender [con: {}, link: {}]", client.getConnectionId(), client.getLinkId()); resultHandler.handle(Future.succeededFuture()); } else { removeSender(client); // register the result handler to be failed if the connection to the downstream container fails during // the attempt to create a downstream sender clientAttachHandlers.add(resultHandler); Future<Void> tracker = Future.future(); tracker.setHandler(attempt -> { if (attempt.succeeded()) { logger.info("created downstream sender [con: {}, link: {}]", client.getConnectionId(), client.getLinkId()); } else { logger.warn("can't create downstream sender [con: {}, link: {}]", client.getConnectionId(), client.getLinkId(), attempt.cause()); } clientAttachHandlers.remove(resultHandler); resultHandler.handle(attempt); }); createSender(client.getTargetAddress(), replenishedSender -> handleFlow(replenishedSender, client)) .compose(createdSender -> { addSender(client, createdSender); tracker.complete(); }, tracker); } }
From source file:org.eclipse.hono.server.SenderFactoryImpl.java
License:Open Source License
private Future<ProtonSession> newSession(final ProtonConnection con) { final Future<ProtonSession> result = Future.future(); con.createSession().openHandler(remoteOpen -> { if (remoteOpen.succeeded()) { result.complete(remoteOpen.result()); } else {//from w w w .j av a 2 s . c o m result.fail(remoteOpen.cause()); } }).open(); return result; }