use of io.vertx.core.impl.VertxFactoryImpl in project camel by apache.
the class VertxComponent method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
if (vertx == null) {
if (vertxFactory == null) {
vertxFactory = new VertxFactoryImpl();
}
if (vertxOptions == null) {
vertxOptions = new VertxOptions();
if (ObjectHelper.isNotEmpty(host)) {
vertxOptions.setClusterHost(host);
vertxOptions.setClustered(true);
}
if (port > 0) {
vertxOptions.setClusterPort(port);
vertxOptions.setClustered(true);
}
}
// we are creating vertx so we should handle its lifecycle
createdVertx = true;
final CountDownLatch latch = new CountDownLatch(1);
// lets using a host / port if a host name is specified
if (vertxOptions.isClustered()) {
LOG.info("Creating Clustered Vertx {}:{}", vertxOptions.getClusterHost(), vertxOptions.getClusterPort());
// use the async api as we want to wait for the eventbus to be ready before we are in started state
vertxFactory.clusteredVertx(vertxOptions, new Handler<AsyncResult<Vertx>>() {
@Override
public void handle(AsyncResult<Vertx> event) {
if (event.cause() != null) {
LOG.warn("Error creating Clustered Vertx " + host + ":" + port + " due " + event.cause().getMessage(), event.cause());
} else if (event.succeeded()) {
vertx = event.result();
LOG.info("EventBus is ready: {}", vertx);
}
latch.countDown();
}
});
} else {
LOG.info("Creating Non-Clustered Vertx");
vertx = vertxFactory.vertx();
LOG.info("EventBus is ready: {}", vertx);
latch.countDown();
}
if (latch.getCount() > 0) {
LOG.info("Waiting for EventBus to be ready using {} sec as timeout", timeout);
latch.await(timeout, TimeUnit.SECONDS);
}
} else {
LOG.debug("Using Vert.x instance set on the component level.");
}
}
Aggregations