本文整理汇总了Java中io.vertx.core.VertxOptions.setClusterHost方法的典型用法代码示例。如果您正苦于以下问题:Java VertxOptions.setClusterHost方法的具体用法?Java VertxOptions.setClusterHost怎么用?Java VertxOptions.setClusterHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.VertxOptions
的用法示例。
在下文中一共展示了VertxOptions.setClusterHost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}