本文整理汇总了Java中io.vertx.spi.cluster.hazelcast.HazelcastClusterManager类的典型用法代码示例。如果您正苦于以下问题:Java HazelcastClusterManager类的具体用法?Java HazelcastClusterManager怎么用?Java HazelcastClusterManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HazelcastClusterManager类属于io.vertx.spi.cluster.hazelcast包,在下文中一共展示了HazelcastClusterManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldFireSessionExpiredEventForHazelcastSessionStore
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
@Test(timeout = 15000L)
public void shouldFireSessionExpiredEventForHazelcastSessionStore(TestContext context) {
Async async = context.async();
Vertx.clusteredVertx(new VertxOptions().setClusterManager(new HazelcastClusterManager()), res -> {
vertx = res.result();
SessionStore adapted = SessionStoreAdapter.adapt(vertx, ClusteredSessionStore.create(vertx));
Session session = adapted.createSession(2000);
sessionExpiredConsumer = SessionStoreAdapter.sessionExpiredHandler(vertx, event -> {
context.assertEquals(session.id(), event.body());
async.countDown();
});
adapted.put(session, Future.<Boolean>future().completer());
session.put("a", "b");
});
}
示例2: initVerticle
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
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");
}
});
}
示例3: DisplayManager
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
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");
}
示例4: example2
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
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!
}
});
}
示例5: start
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
@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);
}
示例6: createClusteredVertx
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的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");
}
}
示例7: configureClusterManager
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
/**
* The Hazelcast instance name will always start with "vertx". If an instance-name is specified, it will be appended to "vertx/", e.g., vertx/instance-name
*/
private void configureClusterManager() {
ConfigUtils.getConfig(config, "VertxOptions", "clusterManager", "hazelcast").map(c -> {
final String hazelcastInstanceName = ConfigUtils.getString(c, "instance-name")
.map(name -> String.format("%s/%s", VERTX_HAZELCAST_INSTANCE_ID, name))
.orElse(VERTX_HAZELCAST_INSTANCE_ID);
final com.hazelcast.config.Config hazelcastConfig = hazelcastConfigFactory(hazelcastInstanceName).apply(c.withFallback(config));
return new HazelcastClusterManager(hazelcastConfig);
}).ifPresent(vertxOptions::setClusterManager);
}
示例8: getHazelcastInstance
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
@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();
}
示例9: main
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
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");
}
});
}
示例10: Display
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
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);
}
示例11: example1
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
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!
}
});
}
示例12: example3
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
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!
}
});
}
示例13: testProgrammatic
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
private void testProgrammatic(HazelcastClusterManager mgr, Config config) throws Exception {
mgr.setConfig(config);
assertEquals(config, mgr.getConfig());
VertxOptions options = new VertxOptions().setClusterManager(mgr).setClustered(true);
Vertx.clusteredVertx(options, res -> {
assertTrue(res.succeeded());
assertNotNull(mgr.getHazelcastInstance());
res.result().close(res2 -> {
assertTrue(res2.succeeded());
testComplete();
});
});
await();
}
示例14: testProgrammaticSetConfig
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
@Test
public void testProgrammaticSetConfig() throws Exception {
Config config = new Config();
HazelcastClusterManager mgr = new HazelcastClusterManager();
mgr.setConfig(config);
testProgrammatic(mgr, config);
}
示例15: hazelcastClusterManager
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; //导入依赖的package包/类
@Bean
public HazelcastClusterManager hazelcastClusterManager(HazelcastInstance hazelcastInstance) {
return new HazelcastClusterManager(hazelcastInstance);
}