List of usage examples for io.vertx.core AsyncResult result
T result();
From source file:ClientVerticle.java
License:Apache License
@Override public void handle(AsyncResult<Message<JsonObject>> result) { Message<JsonObject> msg = result.result(); System.out.println("Client verticle received response : " + msg.body().encodePrettily()); }
From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java
License:Apache License
private void initVertx() { if (this.vertxOptions.isClustered()) { final CompletableFuture<AsyncResult<Vertx>> clusteredVertxResult = new CompletableFuture<>(); Vertx.clusteredVertx(vertxOptions, clusteredVertxResult::complete); while (true) { try { final AsyncResult<Vertx> result = clusteredVertxResult.get(10, TimeUnit.SECONDS); if (result.succeeded()) { this.vertx = result.result(); LOG.logp(INFO, getClass().getName(), "initVertx", "Vertx clustered instance has been created"); } else { throw new RuntimeException("Failed to start a clustered Vertx instance", result.cause()); }/* w w w .j a v a 2s . co m*/ break; } catch (final ExecutionException ex) { throw new RuntimeException("Failed to start a clustered Vertx instance", ex); } catch (final TimeoutException ex) { LOG.logp(INFO, getClass().getName(), "initVertx", "Waiting for Vertx to start"); } catch (final InterruptedException ex) { throw new RuntimeException(ex); } } } else { this.vertx = Vertx.vertx(vertxOptions); LOG.logp(INFO, getClass().getName(), "initVertx", "Vertx instance has been created"); } }
From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java
License:Apache License
private void deployVerticleManager() throws InterruptedException { final CompletableFuture<AsyncResult<String>> deployVerticleResult = new CompletableFuture<>(); vertx.deployVerticle(verticleManager, deployVerticleResult::complete); while (true) { try {//from w w w. j ava2 s . com final AsyncResult<String> result = deployVerticleResult.get(10, TimeUnit.SECONDS); if (result.succeeded()) { LOG.logp(INFO, getClass().getName(), "deployVerticleManager", result.result()); } else { throw new RuntimeException("Failed to deploy RunRightFastVerticleManager", result.cause()); } break; } catch (final ExecutionException ex) { throw new RuntimeException("Failed to deploy RunRightFastVerticleManager", ex); } catch (final TimeoutException ex) { LOG.logp(INFO, getClass().getName(), "deployVerticleManager", "Waiting for RunRightFastVerticleManager deployment to complete"); } catch (final InterruptedException ex) { throw new RuntimeException(ex); } } }
From source file:com.acme.rxjava.example.IrcClient.java
License:Apache License
public void connect(Handler<AsyncResult<IrcClient>> connectHandler) { this.delegate.connect(new Handler<AsyncResult<com.acme.example.IrcClient>>() { public void handle(AsyncResult<com.acme.example.IrcClient> event) { AsyncResult<IrcClient> f; if (event.succeeded()) { f = InternalHelper.<IrcClient>result(new IrcClient(event.result())); } else { f = InternalHelper.<IrcClient>failure(event.cause()); }/*from w w w . ja va2s . c o m*/ connectHandler.handle(f); } }); }
From source file:com.consol.citrus.vertx.endpoint.VertxSyncProducer.java
License:Apache License
@Override public void send(Message message, final TestContext context) { if (log.isDebugEnabled()) { log.debug("Sending message to Vert.x event bus address: '" + endpointConfiguration.getAddress() + "'"); }/*from w w w. jav a 2 s . co m*/ String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()); final String correlationKey = endpointConfiguration.getCorrelator().getCorrelationKey(message); correlationManager.saveCorrelationKey(correlationKeyName, correlationKey, context); context.onOutboundMessage(message); log.info("Message was sent to Vert.x event bus address: '" + endpointConfiguration.getAddress() + "'"); vertx.eventBus().send(endpointConfiguration.getAddress(), message.getPayload(), new Handler<AsyncResult<io.vertx.core.eventbus.Message<Object>>>() { @Override public void handle(AsyncResult<io.vertx.core.eventbus.Message<Object>> event) { log.info("Received synchronous response on Vert.x event bus reply address"); Message responseMessage = endpointConfiguration.getMessageConverter() .convertInbound(event.result(), endpointConfiguration, context); context.onInboundMessage(responseMessage); correlationManager.store(correlationKey, responseMessage); } }); }
From source file:com.consol.citrus.vertx.factory.AbstractVertxInstanceFactory.java
License:Apache License
/** * Creates new Vert.x instance with default factory. Subclasses may overwrite this * method in order to provide special Vert.x instance. * @return// ww w.j a v a2s . co m */ protected Vertx createVertx(VertxEndpointConfiguration endpointConfiguration) { final Vertx[] vertx = new Vertx[1]; final Future loading = new FutureFactoryImpl().future(); Handler<AsyncResult<Vertx>> asyncLoadingHandler = new Handler<AsyncResult<Vertx>>() { @Override public void handle(AsyncResult<Vertx> event) { vertx[0] = event.result(); loading.complete(); log.info("Vert.x instance started"); } }; if (endpointConfiguration.getPort() > 0) { if (log.isDebugEnabled()) { log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(), endpointConfiguration.getPort())); } VertxOptions vertxOptions = new VertxOptions(); vertxOptions.setClusterPort(endpointConfiguration.getPort()); vertxOptions.setClusterHost(endpointConfiguration.getHost()); vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler); } else { if (log.isDebugEnabled()) { log.debug(String.format("Creating new Vert.x instance '%s:%s' ...", endpointConfiguration.getHost(), 0L)); } VertxOptions vertxOptions = new VertxOptions(); vertxOptions.setClusterPort(0); vertxOptions.setClusterHost(endpointConfiguration.getHost()); vertxFactory.clusteredVertx(vertxOptions, asyncLoadingHandler); } // Wait for full loading while (!loading.isComplete()) { try { log.debug("Waiting for Vert.x instance to startup"); Thread.sleep(250L); } catch (InterruptedException e) { log.warn("Interrupted while waiting for Vert.x instance startup", e); } } return vertx[0]; }
From source file:com.diabolicallabs.process.manager.rxjava.service.KnowledgeService.java
License:Apache License
public KnowledgeService getProcessService(Handler<AsyncResult<ProcessService>> handler) { delegate.getProcessService(//w w w . j a v a2s . co m new Handler<AsyncResult<com.diabolicallabs.process.manager.service.ProcessService>>() { public void handle(AsyncResult<com.diabolicallabs.process.manager.service.ProcessService> ar) { if (ar.succeeded()) { handler.handle( io.vertx.core.Future.succeededFuture(ProcessService.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
From source file:com.diabolicallabs.process.manager.rxjava.service.KnowledgeService.java
License:Apache License
public KnowledgeService getRuleService(Handler<AsyncResult<RuleService>> handler) { delegate.getRuleService(new Handler<AsyncResult<com.diabolicallabs.process.manager.service.RuleService>>() { public void handle(AsyncResult<com.diabolicallabs.process.manager.service.RuleService> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(RuleService.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); }/*from w w w .j a v a2 s .com*/ } }); return this; }
From source file:com.diabolicallabs.process.manager.rxjava.service.KnowledgeService.java
License:Apache License
public KnowledgeService getTaskService(Handler<AsyncResult<TaskService>> handler) { delegate.getTaskService(new Handler<AsyncResult<com.diabolicallabs.process.manager.service.TaskService>>() { public void handle(AsyncResult<com.diabolicallabs.process.manager.service.TaskService> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(TaskService.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); }/*from w w w . j a va2 s . co m*/ } }); return this; }
From source file:com.diabolicallabs.process.manager.rxjava.service.KnowledgeServiceFactory.java
License:Apache License
public KnowledgeServiceFactory getKnowledgeService(Handler<AsyncResult<KnowledgeService>> handler) { delegate.getKnowledgeService(/* w w w . ja v a 2 s.co m*/ new Handler<AsyncResult<com.diabolicallabs.process.manager.service.KnowledgeService>>() { public void handle( AsyncResult<com.diabolicallabs.process.manager.service.KnowledgeService> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future .succeededFuture(KnowledgeService.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }