private void startCluster(final ClusterManager manager, final Consumer<Vertx> consumer) { Motor.each((name, option) -> { Vertx.clusteredVertx(option, clustered -> { // 1. Async clustered vertx initialized final Vertx vertx = clustered.result(); // 2. Codecs Motor.codec(vertx.eventBus()); // 3. Cluster connect manager.setVertx(vertx); // Finalized VERTX.putIfAbsent(name, vertx); consumer.accept(vertx); }); }); }
public static <T> void start( final Class<?> clazz, final Consumer<T> consumer, final Consumer<Consumer<T>> fnSingle, final BiConsumer<ClusterManager, Consumer<T>> fnCluster, final Annal logger) { if (null == consumer) { throw new VertxCallbackException(clazz); } // 1. Check if clustered mode final ClusterOptions cluster = ZeroGrid.getClusterOption(); if (cluster.isEnabled()) { // 2.1. Clustered final ClusterManager manager = cluster.getManager(); logger.info(Info.APP_CLUSTERD, manager.getClass().getName(), manager.getNodeID(), manager.isActive()); fnCluster.accept(manager, consumer); } else { // 2.2. Standalone fnSingle.accept(consumer); } }
static void fromJson(final JsonObject json, final ClusterOptions obj) { if (json.getValue("enabled") instanceof Boolean) { obj.setEnabled(json.getBoolean("enabled")); } if (json.getValue("options") instanceof JsonObject) { obj.setOptions(json.getJsonObject("options")); } final Object managerObj = json.getValue("manager"); Fn.safeNull(() -> { final Class<?> clazz = Instance.clazz(managerObj.toString()); Fn.safeNull(() -> { // If null, keep default final ClusterManager manager = Instance.instance(clazz); obj.setManager(manager); }, clazz); }, managerObj); }
private void initVerticle(Handler<Object> handler){ //start vert.x ClusterManager mgr = new HazelcastClusterManager(); VertxOptions options = new VertxOptions().setClusterManager(mgr); options.setWorkerPoolSize(1000); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { vertx = res.result(); vertx.eventBus().registerDefaultCodec(MessageBody.class, new MessageBodyCodec()); AppConfig appConfig = context.getBean(AppConfig.class); appConfig.setVertx(vertx); appConfig.setAppClass(appClass); appConfig.setAppName(appName); handler.handle(1); } else { logger.error("fail clusteredVertx"); } }); }
public DisplayManager(){ LOG.info("\n-----------------------------------\n" + "Starting DisplayDisplayManager...\n" + "-----------------------------------"); LOG.info("--- Starting Vertx cluster..."); // Reusing the hazelcast instance already in place for vertx... ClusterManager mgr = new HazelcastClusterManager( hazelCastPropertySource.getHazelcastInstance()); VertxOptions vertxOptions = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(vertxOptions, h -> { vertx = h.result(); }); LOG.info("--- Waiting for Vertx cluster..."); while(vertx==null){ try { Thread.sleep(100L); } catch (InterruptedException e) { e.printStackTrace(); } } monitorField.getStyleClass().add("monitor"); configField.getStyleClass().add("config"); }
public void example2() { Config hazelcastConfig = new Config(); // Now set some stuff on the config (omitted) ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig); VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
private void startCluster(final ClusterManager manager, final Consumer<Vertx> consumer) { Motor.each((name, option) -> { // Set cluster manager option.setClusterManager(manager); final Single<Vertx> observable = Vertx.rxClusteredVertx(option); observable.subscribe(vertx -> { Motor.codec(vertx.eventBus().getDelegate()); // Finalized VERTX.putIfAbsent(name, vertx); consumer.accept(vertx); }); }); }
@Activate public void start(BundleContext bundleContext) { this.bc = bundleContext; LOGGER.info("Starting VertxHazelcastClusterMngrFactory ... registering ClusterManager as service."); ClusterManager mgr = new HazelcastClusterManager(hazelcastInstance); clusterManagerService = bc.registerService(ClusterManager.class, mgr, null); }
public void example1() { ClusterManager clusterManager = new IgniteClusterManager(); VertxOptions options = new VertxOptions().setClusterManager(clusterManager); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
public void example2() { IgniteConfiguration cfg = new IgniteConfiguration(); // Configuration code (omitted) ClusterManager clusterManager = new IgniteClusterManager(cfg); VertxOptions options = new VertxOptions().setClusterManager(clusterManager); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
public void example3(Ignite ignite) { // Configuration code (omitted) ClusterManager clusterManager = new IgniteClusterManager(ignite); VertxOptions options = new VertxOptions().setClusterManager(clusterManager); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
public void createClusterManagerProgramatically() { ClusterManager mgr = new InfinispanClusterManager(); VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
public void useExistingCacheManager(DefaultCacheManager cacheManager) { ClusterManager mgr = new InfinispanClusterManager(cacheManager); VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
public ExtendedAsyncMapImpl(Vertx vertx, String name) { this.vertx = vertx; ClusterManager clusterManager = ((VertxInternal) vertx).getClusterManager(); if (clusterManager == null) { syncMap = new ConcurrentHashMap<>(); } else { syncMap = clusterManager.getSyncMap(name); } }
private void logVertxOptions() { LOG.logp(CONFIG, getClass().getName(), "logVertxOptions", () -> { final JsonObject json = new JsonObject() .put("BlockedThreadCheckInterval", vertxOptions.getBlockedThreadCheckInterval()) .put("ClusterHost", vertxOptions.getClusterHost()) .put("ClusterPingInterval", vertxOptions.getClusterPingInterval()) .put("ClusterPingReplyInterval", vertxOptions.getClusterPingReplyInterval()) .put("ClusterPort", vertxOptions.getClusterPort()) .put("EventLoopPoolSize", vertxOptions.getEventLoopPoolSize()) .put("HAGroup", vertxOptions.getHAGroup()) .put("InternalBlockingPoolSize", vertxOptions.getInternalBlockingPoolSize()) .put("MaxEventLoopExecuteTime", vertxOptions.getMaxEventLoopExecuteTime()) .put("MaxWorkerExecuteTime", vertxOptions.getMaxWorkerExecuteTime()) .put("QuorumSize", vertxOptions.getQuorumSize()) .put("WarningExceptionTime", vertxOptions.getWarningExceptionTime()) .put("WorkerPoolSize", vertxOptions.getWorkerPoolSize()); final ClusterManager clusterManager = vertxOptions.getClusterManager(); if (clusterManager != null) { json.put("clusterManagerClass", clusterManager.getClass().getName()); } final MetricsOptions metricsOptions = vertxOptions.getMetricsOptions(); if (metricsOptions != null) { json.put("MetricsOptions", toJsonObject(metricsOptions)); } return json.encodePrettily(); }); }
@Override public Optional<HazelcastInstance> getHazelcastInstance() { if (!this.vertx.isClustered()) { return Optional.empty(); } final ClusterManager clusterManager = this.vertxOptions.getClusterManager(); if (clusterManager != null && clusterManager instanceof HazelcastClusterManager) { return Optional.of(((HazelcastClusterManager) clusterManager).getHazelcastInstance()); } return Optional.empty(); }
public void example1() { ClusterManager mgr = new JGroupsClusterManager(); VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
public void example2(JChannel channel) { ClusterManager mgr = new JGroupsClusterManager(channel); VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); // Don't forget to close the channel when done. }
public static void main(String[] args) { ClusterManager clusterManager = new HazelcastClusterManager(); VertxOptions vertxOptions = new VertxOptions().setClusterManager(clusterManager); Vertx.clusteredVertx(vertxOptions, res -> { if(res.succeeded()) { vertx = res.result(); initRouter(); addVerticle(); }else { throw new RuntimeException("Vert.x Init Error"); } }); }
public Display(){ LOG.info("\n-----------------------------------\n" + "Starting Display...\n" + "-----------------------------------"); LOG.info("--- Starting Vertx cluster..."); // Reusing the hazelcast instance already in place for vertx... ClusterManager mgr = new HazelcastClusterManager( hazelCastPropertySource.getHazelcastInstance()); VertxOptions vertxOptions = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(vertxOptions, h -> { vertx = h.result(); }); LOG.info("--- Waiting for Vertx cluster..."); while(vertx==null){ try { Thread.sleep(100L); } catch (InterruptedException e) { e.printStackTrace(); } } titleField.getStyleClass().add("title"); contentField.getStyleClass().add("content"); monitorField.getStyleClass().add("monitor"); titleField.setId("title"); titleField.setEditable(false); contentField.setId("scene"); contentField.setEditable(false); }
public void example1() { ClusterManager mgr = new HazelcastClusterManager(); VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
public void example3(HazelcastInstance hazelcastInstance) { ClusterManager mgr = new HazelcastClusterManager(hazelcastInstance); VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx.clusteredVertx(options, res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { // failed! } }); }
@Bean public SpringVertx vertx( ObjectProvider<VertxOptions> optionsProvider, ObjectProvider<ClusterManager> clusterManagerProvider, ObjectProvider<List<VertxListener>> listenersProvider, ObjectProvider<List<VertxConfigurer>> configurersProvider) { SpringVertx.Builder builder = SpringVertx.builder(); List<VertxConfigurer> configurers = new ArrayList<>(); ClusterManager clusterManager = clusterManagerProvider.getIfAvailable(); if (clusterManager != null) { configurers.add(new ClusterManagerConfigurer(clusterManager)); } List<VertxListener> listeners = listenersProvider.getIfAvailable(); if (listeners != null) { for (VertxListener listener : listeners) { builder.listener(listener); } } List<VertxConfigurer> injectedConfigurers = configurersProvider.getIfAvailable(); if (injectedConfigurers != null) { configurers.addAll(injectedConfigurers); } if (!configurers.isEmpty()) { List<VertxConfigurer> sortedConfigurers = new ArrayList<>(configurers); AnnotationAwareOrderComparator.sort(sortedConfigurers); for (VertxConfigurer configurer : sortedConfigurers) { logger.debug("Applying configurer: {}", configurer); configurer.configure(builder); } } // If we have a VertxOptions bean, it will replace all the options possibly gathered by configurers, // so make sure to call it last VertxOptions options = optionsProvider.getIfAvailable(); if (options != null) { builder.options(options); } return builder.build(); }
public ClusterManagerConfigurer(ClusterManager clusterManager) { this.clusterManager = clusterManager; }
protected ClusterManager getClusterManager() { return null; }
public ClusterManager getManager() { return this.manager; }
public ClusterOptions setManager(final ClusterManager manager) { this.manager = manager; return this; }
public void bindClusterManager(ClusterManager clusterManager) { this.clusterManager = clusterManager; deregisterVertx(); createAndRegisterVertx(); }
public void unbindClusterManager(ClusterManager clusterManager) { this.clusterManager = null; deregisterVertx(); createAndRegisterVertx(); }
public void setClusterManager(ClusterManager mgr) { this.clusterManager = mgr; mgr.nodeListener(this); }
public void setClusterManager(ClusterManager mgr) { clusterManager = mgr; }
@Override protected ClusterManager getClusterManager() { return new IgniteClusterManager(); }