List of usage examples for io.vertx.core VertxOptions setClusterManager
public VertxOptions setClusterManager(ClusterManager clusterManager)
From source file:com.foreks.vertx.launcher.ClusteredVertxFactory.java
License:Apache License
@Override public Single<Vertx> createVertx(VertxOptions vertxOptions) { HazelcastClusterManager clusterManager = getClusterManager(); this.latch = clusterManager.getHazelcastInstance().getCountDownLatch("shutdown.latch"); latch.trySetCount(1);// w ww. j a v a 2 s .com vertxOptions.setClusterManager(clusterManager); return Single.fromPublisher(publisher -> { Vertx.clusteredVertx(vertxOptions, response -> { if (response.succeeded()) { Vertx vertx = response.result(); clusterManager.getHazelcastInstance().getLifecycleService().addLifecycleListener(state -> { if (state.getState() == LifecycleEvent.LifecycleState.SHUTTING_DOWN) { beforeLeaveUndeploy(vertx); } }); publisher.onNext(vertx); } else { publisher.onError(response.cause()); } publisher.onComplete(); }); }); }
From source file:org.wisdom.framework.vertx.VertxSingleton.java
License:Apache License
/** * Creates and exposed the instance of Vert.X. *///w ww . jav a2 s . c om @Validate public void start() { final Configuration configuration = appConfiguration.getConfiguration("vertx"); String log = System.getProperty("org.vertx.logger-delegate-factory-class-name"); if (log == null) { // No logging backend configured, set one: System.setProperty("org.vertx.logger-delegate-factory-class-name", SLF4JLogDelegateFactory.class.getName()); } VertxOptions options = new VertxOptions(); boolean clustered = false; if (configuration != null) { clustered = configuration.getBooleanWithDefault("clustered", false); options = new VertxOptions(new JsonObject(configuration.asMap())); if (clustered) { options.setClustered(true).setClusterHost(configuration.getOrDie("cluster-host")); // Identify port and configuration file String clusterConfig = configuration.getWithDefault("cluster-config", "conf/cluster.xml"); System.setProperty("hazelcast.config", new File(clusterConfig).getAbsolutePath()); } } // To setup the logging backend, Vert.x needs a TTCL. final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); Hashtable<String, Object> properties = new Hashtable<>(); if (clustered) { options.setClusterManager(new HazelcastClusterManager()); String host = options.getClusterHost(); properties.put("eventbus.host", host); Vertx.clusteredVertx(options, ar -> { if (ar.failed()) { throw new IllegalStateException("Cannot join cluster", ar.cause()); } vertx = ar.result(); vertxRegistration = context.registerService(Vertx.class, vertx, properties); busRegistration = context.registerService(EventBus.class, vertx.eventBus(), properties); }); } else { // Not a clustered environment vertx = Vertx.vertx(options); vertxRegistration = context.registerService(Vertx.class, vertx, properties); busRegistration = context.registerService(EventBus.class, vertx.eventBus(), properties); } } finally { Thread.currentThread().setContextClassLoader(tccl); } }