本文整理汇总了Java中io.vertx.core.VertxOptions.setClusterManager方法的典型用法代码示例。如果您正苦于以下问题:Java VertxOptions.setClusterManager方法的具体用法?Java VertxOptions.setClusterManager怎么用?Java VertxOptions.setClusterManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.VertxOptions
的用法示例。
在下文中一共展示了VertxOptions.setClusterManager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: vertx
import io.vertx.core.VertxOptions; //导入方法依赖的package包/类
/**
* Vertx.
*
* @return the future vertx
*/
protected Future<Vertx> vertx() {
VertxOptions options = new VertxOptions();
options.setClustered(true);
options.setClusterManager(clusterManager());
return VertxBuilder.create().options(options).build().compose(vertx -> {
vertx.deployVerticle(this);
}, Future.succeededFuture());
}
示例2: createClusteredVertx
import io.vertx.core.VertxOptions; //导入方法依赖的package包/类
/**
* Create a clustered vert.x instance and block until the instance has been created.
*
* @param options
* Mesh options
* @param vertxOptions
* Vert.x options
* @param hazelcast
* Hazelcast instance which should be used by vert.x
*/
private Vertx createClusteredVertx(MeshOptions options, VertxOptions vertxOptions, HazelcastInstance hazelcast) {
Objects.requireNonNull(hazelcast, "The hazelcast instance was not yet initialized.");
manager = new HazelcastClusterManager(hazelcast);
vertxOptions.setClusterManager(manager);
String localIp = options.getClusterOptions().getNetworkHost();
vertxOptions.getEventBusOptions().setHost(localIp);
vertxOptions.getEventBusOptions().setClusterPublicHost(localIp);
vertxOptions.setClusterHost(localIp);
vertxOptions.setClusterPublicHost(localIp);
Integer clusterPort = options.getClusterOptions().getVertxPort();
int vertxClusterPort = clusterPort == null ? 0 : clusterPort;
vertxOptions.setClusterPort(vertxClusterPort);
vertxOptions.setClusterPublicPort(vertxClusterPort);
if (log.isDebugEnabled()) {
log.debug("Using vert.x cluster port {" + vertxClusterPort + "}");
log.debug("Using vert.x cluster public port {" + vertxClusterPort + "}");
log.debug("Binding vert.x on host {" + localIp + "}");
}
CompletableFuture<Vertx> fut = new CompletableFuture<>();
Vertx.clusteredVertx(vertxOptions, rh -> {
log.info("Created clustered vert.x instance");
if (rh.failed()) {
Throwable cause = rh.cause();
log.error("Failed to create clustered vert.x instance", cause);
fut.completeExceptionally(new RuntimeException("Error while creating clusterd vert.x instance", cause));
return;
}
Vertx vertx = rh.result();
fut.complete(vertx);
});
try {
return fut.get(10, SECONDS);
} catch (Exception e) {
throw new RuntimeException("Error while creating clusterd vert.x instance");
}
}
示例3: createAndRegisterVertx
import io.vertx.core.VertxOptions; //导入方法依赖的package包/类
private void createAndRegisterVertx() {
VertxOptions options = new VertxOptions().setMetricsOptions(new DropwizardMetricsOptions()
.setJmxEnabled(true)
.setJmxDomain("vertx-metrics")
.setRegistryName("vertx-karaf-registry")
.setFactory(metrxFactory)
);
if (cfg.getWorkerPoolSize() > 0) {
options.setWorkerPoolSize(cfg.getWorkerPoolSize());
}
if (cfg.getEventLoopPoolSize() > 0) {
options.setEventLoopPoolSize(cfg.getEventLoopPoolSize());
}
if (cfg.getHAEnabled()) {
options.setHAEnabled(cfg.getHAEnabled());
if (cfg.getHAGroup() != null && !cfg.getHAGroup().isEmpty()) {
options.setHAGroup(cfg.getHAGroup());
}
}
if (clusterManager != null) {
LOGGER.info("Starting vertx with cluster manager");
options.setClusterManager(clusterManager);
}
try {
vertx = executeWithTCCLSwitch(() -> Vertx.vertx(options));
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error while creating vertx system", e);
return;
}
vertxRegistration = bundleContext.registerService(Vertx.class, vertx, null);
LOGGER.info("Vert.x service registered");
ebRegistration = bundleContext.registerService(EventBus.class, vertx.eventBus(), null);
LOGGER.info("Vert.x Event Bus service registered");
registry = SharedMetricRegistries.getOrCreate("vertx-karaf-registry");
metricsRegistration = bundleContext.registerService(MetricRegistry.class, registry, null);
LOGGER.info("Vert.x MetricsService service registered");
MetricsService metricsService = MetricsService.create(vertx);
metricsServiceRegistration = bundleContext.registerService(MetricsService.class, metricsService, null);
}