List of usage examples for io.vertx.core Future succeeded
@Override
boolean succeeded();
From source file:com.dinstone.vertx.web.core.AbstractRouteResolver.java
License:Apache License
private static Handler<RoutingContext> asyncHandler(final Object service, final RouteDefinition definition, RouterContext routerContext) {//from w w w .j av a 2s . c o m return context -> { try { Object[] args = prepareArguments(context, definition, routerContext); Object result = definition.getMethod().invoke(service, args); if (result instanceof Future) { Future<?> future = (Future<?>) result; // wait for future to complete ... don't block vertx event bus in the mean time future.setHandler(handler -> { if (future.succeeded()) { try { Object futureResult = future.result(); handleResponse(futureResult, context, definition, routerContext); } catch (Throwable e) { handleException(e, context, definition, routerContext); } } else { handleException(future.cause(), context, definition, routerContext); } }); } } catch (Throwable e) { handleException(e, context, definition, routerContext); } }; }
From source file:de.braintags.netrelay.processor.DemoMailProcessor.java
License:Open Source License
@Override protected void handleEvent(Future<Void> future) { try {//ww w .ja va 2 s . c o m LOGGER.info("starting to send message"); MockRoutingContext context = new MockRoutingContext(vertx, new URI("http://localhost:8080/")); context.put(MailController.TO_PARAMETER, NetRelayBaseTest.TESTS_MAIL_RECIPIENT); context.put(MailController.SUBJECT_PARAMETER, "Mail gesendet von Processor"); context.put("TestProperty", "echt ein Testvalue"); sendMail(context, result -> { if (result.failed()) { future.fail(result.cause()); } else { if (!result.result().success) { future.fail(result.result().errorMessage); } else { TMailProcessor.eventProcessed = true; future.succeeded(); } } async.complete(); }); } catch (Exception e) { future.fail(e); async.complete(); } }
From source file:org.eclipse.hono.vertx.example.base.HonoConsumerBase.java
License:Open Source License
/** * Initiate the connection and set the message handling method to treat data that is received. * * @throws Exception Thrown if the latch is interrupted during waiting or if the read from System.in throws an IOException. *//*from w w w . jav a2 s . c om*/ protected void consumeData() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final Future<MessageConsumer> consumerFuture = Future.future(); consumerFuture.setHandler(result -> { if (!result.succeeded()) { System.err.println("honoClient could not create telemetry consumer for " + HonoExampleConstants.HONO_AMQP_CONSUMER_HOST + ":" + HonoExampleConstants.HONO_AMQP_CONSUMER_PORT + " : " + result.cause()); } latch.countDown(); }); honoClient.connect(this::onDisconnect).compose(connectedClient -> createConsumer()) .setHandler(consumerFuture.completer()); latch.await(); if (consumerFuture.succeeded()) { System.in.read(); } vertx.close(); }