/** * Creates a new clustered vert.x instance. * * @param options the options * @param resultHandler the result handler */ protected synchronized void create(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler) { final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classloader != null ? classloader : getClass().getClassLoader()); Vertx.clusteredVertx(options, resultHandler); } catch (Exception e) { log.error("Failed to create the vert.x instance", e); } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } }
public static void main(String[] args) { Vertx.clusteredVertx(new VertxOptions().setClustered(true), ar -> { if (ar.failed()) { System.err.println("Cannot create vert.x instance : " + ar.cause()); } else { Vertx vertx = ar.result(); vertx.deployVerticle(DisplayStatsApp.class.getName()); } }); } }
public static void main(String[] args) { Vertx.clusteredVertx(new VertxOptions().setClustered(true), ar -> { if (ar.failed()) { System.err.println("Cannot create vert.x instance : " + ar.cause()); } else { Vertx vertx = ar.result(); vertx.deployVerticle(ConsumerApp.class.getName()); } }); }
public static void main(String[] args) { Vertx.clusteredVertx(new VertxOptions().setClustered(true), ar -> { if (ar.failed()) { System.err.println("Cannot create vert.x instance : " + ar.cause()); } else { Vertx vertx = ar.result(); vertx.deployVerticle(StatsConsumerApp.class.getName()); } }); } }
public static void main(String[] args) { Vertx.clusteredVertx(new VertxOptions().setClustered(true), ar -> { if (ar.failed()) { System.err.println("Cannot create vert.x instance : " + ar.cause()); } else { Vertx vertx = ar.result(); vertx.deployVerticle(ProducerApp.class.getName()); } }); }
public static void main(String[] args) { Vertx.clusteredVertx(new VertxOptions().setClustered(true), ar -> { if (ar.failed()) { System.err.println("Cannot create vert.x instance : " + ar.cause()); } else { Vertx vertx = ar.result(); vertx.deployVerticle(StatsProducerApp.class.getName()); } }); }
@PostConstruct void init() throws ExecutionException, InterruptedException { VertxOptions options = new VertxOptions() .setClusterManager(new HazelcastClusterManager(hazelcastInstance)); CompletableFuture<Vertx> future = new CompletableFuture<>(); Vertx.clusteredVertx(options, ar -> { if (ar.succeeded()) { future.complete(ar.result()); } else { future.completeExceptionally(ar.cause()); } }); vertx = future.get(); }
/** * Create a blank new clustered Vert.x instance with @{@code options} closed when tear down executes. */ protected void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> ar) { if (created == null) { created = Collections.synchronizedList(new ArrayList<>()); } Vertx.clusteredVertx(options, event -> { if (event.succeeded()) { created.add(event.result()); } ar.handle(event); }); }
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();
public static void main(String[] args) { JsonObject zkConfig = configureClusterManager(); ClusterManager zookeeperClusterManager = new ZookeeperClusterManager(zkConfig); VertxOptions options = configureVertx(zookeeperClusterManager); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(2); vertx.deployVerticle("verticle.SenderVerticle", deploymentOptions); System.out.println("Sender verticle deployed"); } }); }
public static void main(String[] args) { JsonObject zkConfig = configureClusterManager(); ClusterManager zookeeperClusterManager = new ZookeeperClusterManager(zkConfig); VertxOptions options = configureVertx(zookeeperClusterManager); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(2); vertx.deployVerticle("verticle.ConsumerVerticle", deploymentOptions); System.out.println("consumer verticle deployed"); } }); }
Vertx.clusteredVertx(options, ar -> { result.set(ar); latch.countDown();
@Test public void testCallbackInvokedOnFailure() throws Exception { // will trigger java.net.UnknownHostException String hostName = "zoom.zoom.zen.tld"; VertxOptions options = new VertxOptions() .setClusterManager(new FakeClusterManager()) .setClusterHost(hostName); AtomicReference<AsyncResult<Vertx>> resultRef = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); Vertx.clusteredVertx(options, ar -> { resultRef.set(ar); latch.countDown(); }); awaitLatch(latch); assertFalse(resultRef.get() == null); assertTrue(resultRef.get().failed()); assertTrue("Was expecting failure to be an instance of UnknownHostException", resultRef.get().cause() instanceof UnknownHostException); } }