List of usage examples for io.vertx.core VertxOptions setClustered
@Deprecated public VertxOptions setClustered(boolean clustered)
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); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result();//from w w w . j a v a 2s . c o m 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.palmg.core.main.vertx.VertxCoreWrapperKernel.java
License:Open Source License
private void vertxBuild() { try {// w ww . ja va2 s . c om // 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); Vertx.clusteredVertx(options, vertxHandler -> { if (vertxHandler.succeeded()) { log.info("start deploying verticles...."); Vertx vertx = vertxHandler.result(); vertx.deployVerticle(new ServerVerticle()); }/* ww w . j a v a 2 s . com*/ }); }
From source file:io.github.jdocker.serviceregistry.ServiceRegistry.java
License:Apache License
public static void main(String[] args) { // DeploymentOptions options = new DeploymentOptions().setInstances(1).setConfig(new JsonObject().put("host","localhost")); // Vertx.vertx().deployVerticle(ServiceRegistry.class.getServiceName(),options); VertxOptions vOpts = new VertxOptions(); DeploymentOptions options = new DeploymentOptions().setInstances(1); vOpts.setClustered(true); Vertx.clusteredVertx(vOpts, cluster -> { if (cluster.succeeded()) { final Vertx result = cluster.result(); result.deployVerticle(ServiceRegistry.class.getName(), options, handle -> { });//from w w w .j a v a 2s .c o m } }); }
From source file:org.wisdom.framework.vertx.VertxSingleton.java
License:Apache License
/** * Creates and exposed the instance of Vert.X. *//* w w w .j a v a 2s .c o m*/ @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); } }
From source file:scp.targets.vertx.CommunicationManagerImpl.java
License:Open Source License
/** * Instantiates a new Communication manager impl based on clustered Vertx instance. * * @param port the port. If this argument is 0, then the system will pick the port. * @param hostname the hostname// w w w . j a va2 s . c om */ public CommunicationManagerImpl(int port, String hostname) { final Semaphore _sem = new Semaphore(0); final Handler<AsyncResult<Vertx>> _handler = event -> { try { if (event.succeeded()) { LOGGER.info("Vertx creation succeeded"); CommunicationManagerImpl.this.vertx = event.result(); } else { LOGGER.error("Vertx creation failed"); throw new RuntimeException("Could not initialize Communication manager", event.cause()); } } finally { _sem.release(); } }; final VertxOptions _opt = new VertxOptions(); _opt.setClustered(true); _opt.setClusterHost(hostname); _opt.setClusterPort(port); Vertx.clusteredVertx(_opt, _handler); try { _sem.acquire(); } catch (final InterruptedException _e) { final String _msg = "Why did the semaphore encountered InterruptedException?"; LOGGER.error(_msg, _e); throw new RuntimeException(_msg, _e); } assert this.vertx != null; }