本文整理匯總了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");
}
}