List of usage examples for io.vertx.core.impl FutureFactoryImpl FutureFactoryImpl
FutureFactoryImpl
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/*from w w w .j av a2 s . 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]; }