List of usage examples for io.vertx.core Vertx clusteredVertx
static void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler)
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()); }/*from w ww.j av a2s.c o 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:com.ab.main.MainApp.java
/** * @param args the command line arguments *//*from w ww . ja va 2 s.c om*/ public static void main(String[] args) { System.out.println("Vertx webserver started at port 8080"); Config hazelcastConfig = new Config(); ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig); VertxOptions options = new VertxOptions().setClusterManager(mgr); int port = 8081; DeploymentOptions depOptions = new DeploymentOptions().setConfig(new JsonObject().put("http.port", port)); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); vertx.deployVerticle(new MainVerticle(), depOptions); System.out.println("Server started at port " + port + "..."); } else { // failed! } }); }
From source file:com.ddp.SimpleREST.java
License:Open Source License
public static void main(String argv[]) { VertxOptions options = new VertxOptions().setBlockedThreadCheckInterval(200000000); options.setClustered(true);/* www .j a v a2s . co m*/ Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); final JsonObject js = new JsonObject(); vertx.fileSystem().readFile("app-conf.json", result -> { if (result.succeeded()) { Buffer buff = result.result(); js.mergeIn(new JsonObject(buff.toString())); initConfig(js); DeploymentOptions deploymentOptions = new DeploymentOptions().setConfig(js) .setMaxWorkerExecuteTime(5000).setWorker(true).setWorkerPoolSize(5); vertx.deployVerticle(SimpleREST.class.getName(), deploymentOptions); } else { System.err.println("Oh oh ..." + result.cause()); } }); } }); }
From source file:com.deblox.DebloxRunner.java
License:Apache License
public static void run(String runDir, String verticleID, VertxOptions options, String confFile) { logger.info("Booting"); // System.setProperty("vertx.cwd", runDir + "/"); Consumer<Vertx> runner = vertx -> { try {//from w w w . j a v a 2s .com JsonObject config = Util.loadConfig(confFile); // put config inside a config tag to solve issue between running as fatJar and running main[] DeploymentOptions deploymentOptions = new DeploymentOptions(new JsonObject().put("config", config)); vertx.deployVerticle(verticleID, deploymentOptions); } catch (Throwable t) { t.printStackTrace(); } }; if (options.isClustered()) { Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); runner.accept(vertx); } else { res.cause().printStackTrace(); } }); } else { Vertx vertx = Vertx.vertx(options); runner.accept(vertx); } }
From source file:com.dinstone.vertx.starter.VertxHelper.java
License:Apache License
public static Vertx createVertx(VertxOptions vertxOptions) throws Exception { CompletableFuture<Vertx> future = new CompletableFuture<>(); if (vertxOptions.isClustered()) { Vertx.clusteredVertx(vertxOptions, asyncResult -> { if (asyncResult.succeeded()) { future.complete(asyncResult.result()); } else { future.completeExceptionally(asyncResult.cause()); }/* w w w . jav a2s . c om*/ }); } else { future.complete(Vertx.vertx(vertxOptions)); } return future.get(); }
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);//from ww w . j a va2 s.c o m 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:com.jtpark.example_vertx_amqp.util.Runner.java
License:Apache License
public static void runExample(String exampleDir, String verticleID, VertxOptions options, DeploymentOptions deploymentOptions) { if (options == null) { // Default parameter options = new VertxOptions(); }// www .ja v a 2 s .c o m // Smart cwd detection // Based on the current directory (.) and the desired directory // (exampleDir), we try to compute the vertx.cwd // directory: try { // We need to use the canonical file. Without the file name is . File current = new File(".").getCanonicalFile(); if (exampleDir.startsWith(current.getName()) && !exampleDir.equals(current.getName())) { exampleDir = exampleDir.substring(current.getName().length() + 1); } } catch (IOException e) { // Ignore it. } System.setProperty("vertx.cwd", exampleDir); Consumer<Vertx> runner = vertx -> { try { if (deploymentOptions != null) { vertx.deployVerticle(verticleID, deploymentOptions); } else { vertx.deployVerticle(verticleID); } } catch (Throwable t) { t.printStackTrace(); } }; if (options.isClustered()) { Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); runner.accept(vertx); } else { res.cause().printStackTrace(); } }); } else { Vertx vertx = Vertx.vertx(options); runner.accept(vertx); } }
From source file:com.palmg.core.main.vertx.VertxCoreWrapperKernel.java
License:Open Source License
private void vertxBuild() { try {/*w w w .j a v a 2s. c o m*/ // get the configure. ClusterConfig cluster = clusterConfig; final BusConfig busConfig = AaronConfigure.Instance.getPalmgConfig().getBusConfig(); VertxOptions options = new VertxOptions(); // eventbus configure options.setEventLoopPoolSize(busConfig.getCoreThreadPoolSize()) .setWorkerPoolSize(busConfig.getWorkerThreadPoolSize()) .setInternalBlockingPoolSize(busConfig.getInternalBlockingPoolSize()) .setBlockedThreadCheckInterval(busConfig.getCoreThreadBlockedCheckInterval()) .setMaxEventLoopExecuteTime(busConfig.getMaxCoreThreadExecuteTime()) .setMaxWorkerExecuteTime(busConfig.getMaxWorkerThreadExecuteTime()) .setWarningExceptionTime(busConfig.getWarningExceptionTime()); if (cluster.isEnabled()) {// use cluster options.setClustered(true); CompletableFuture<Void> future = new CompletableFuture<>(); // user hazelcast to create cluster HazelcastClusterWrapperImpl.Instance.getHazelcastCluster(); Vertx.clusteredVertx(options, result -> { if (result.failed()) { LOG.error("Init cluster error! Terminate palmg", result.cause()); future.completeExceptionally(result.cause()); } else { vertx = result.result(); future.complete(null); } }); future.get(10, TimeUnit.SECONDS); } else {// default vertx = Vertx.vertx(options.setClustered(false)); } } catch (Throwable t) { LOG.error("create palmg kernel error! Terminate", t); // if create vertx instance error then terminate palmg. // because we can not provide any toolkit without vertx. System.exit(0); } }
From source file:com.test.bugnpe.MainVertx.java
public static void main(String[] args) { log.info("Start with cluster!"); VertxOptions options = new VertxOptions(); options.setClustered(true);/*from w ww . j a v a 2s. c om*/ Vertx.clusteredVertx(options, vertxHandler -> { if (vertxHandler.succeeded()) { log.info("start deploying verticles...."); Vertx vertx = vertxHandler.result(); vertx.deployVerticle(new ServerVerticle()); } }); }
From source file:com.zanclus.distributed.chat.service.Main.java
License:Apache License
public static void main(String[] args) { Vertx.clusteredVertx(new VertxOptions().setClustered(true), startHandler -> { Vertx.vertx().deployVerticle(new Main()); });/*from w w w.jav a 2 s . c o m*/ }