gpt4 book ai didi

io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 12:57:36 26 4
gpt4 key购买 nike

本文整理了Java中io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager类的一些代码示例,展示了ZookeeperClusterManager类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZookeeperClusterManager类的具体详情如下:
包路径:io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager
类名称:ZookeeperClusterManager

ZookeeperClusterManager介绍

[英]A cluster manager that uses Zookeeper
[中]使用Zookeeper的群集管理器

代码示例

代码示例来源:origin: vert-x3/vertx-examples

public static void main(String[] args) {
  JsonObject zkConfig = configureClusterManager();
  ClusterManager zookeeperClusterManager = new ZookeeperClusterManager(zkConfig);
  VertxOptions options = configureVertx(zookeeperClusterManager);
  Vertx.clusteredVertx(options, res -> {
    if (res.succeeded()) {
      Vertx vertx = res.result();
      DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(2);
      vertx.deployVerticle("verticle.SenderVerticle", deploymentOptions);
      System.out.println("Sender verticle deployed");
    }
  });
}

代码示例来源:origin: io.vertx/vertx-zookeeper

curator2.start();
ZookeeperClusterManager mgr1 = new ZookeeperClusterManager(curator1);
ZookeeperClusterManager mgr2 = new ZookeeperClusterManager(curator2);
VertxOptions options1 = new VertxOptions().setClusterManager(mgr1).setClustered(true).setClusterHost("127.0.0.1");
VertxOptions options2 = new VertxOptions().setClusterManager(mgr2).setClustered(true).setClusterHost("127.0.0.1");
 assertNotNull(mgr1.getCuratorFramework());
 res.result().eventBus().consumer("news", message -> {
  assertNotNull(message);
 assertNotNull(mgr2.getCuratorFramework());
 vertx2.set(res.result());
 res.result().eventBus().send("news", "hello");

代码示例来源:origin: io.vertx/vertx-zookeeper

String nodeID = UUID.randomUUID().toString();
ZookeeperClusterManager mgr = new ZookeeperClusterManager(curator, nodeID);
VertxOptions options = new VertxOptions().setClusterManager(mgr).setClustered(true).setClusterHost("127.0.0.1");
 assertNotNull(mgr.getCuratorFramework());
 res.result().sharedData().getClusterWideMap("mymap1", ar -> {
  ar.result().put("news", "hello", v -> {
int size = mgr.getNodes().size();
assertTrue(size > 0);
assertTrue(mgr.getNodes().contains(nodeID));
assertWaitUntil(() -> mgr.getNodes().size() == size - 1);
vertx1.get().close();
vertx1.get().close(ar -> vertx1.set(null));

代码示例来源:origin: vert-x3/vertx-zookeeper

@Test
public void testProgrammaticSetConfig() throws Exception {
 JsonObject config = zkCluster.getDefaultConfig();
 ZookeeperClusterManager mgr = new ZookeeperClusterManager();
 mgr.setConfig(config);
 testProgrammatic(mgr, config);
}

代码示例来源:origin: vert-x3/vertx-zookeeper

private void testProgrammatic(ZookeeperClusterManager mgr, JsonObject 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.getCuratorFramework());
  res.result().close(res2 -> {
   assertTrue(res2.succeeded());
   testComplete();
  });
 });
 await();
}

代码示例来源:origin: vert-x3/vertx-zookeeper

private void createThisNode() throws Exception {
 //clean ha node would be happened multi times with multi vertx node in startup, so we have a lock to avoid conflict.
 this.getLockWithTimeout("__cluster_init_lock", 3000L, lockAsyncResult -> {
  if (lockAsyncResult.succeeded()) {
   try {
    //we have to clear `__vertx.haInfo` node if cluster is empty, as __haInfo is PERSISTENT mode, so we can not delete last
    //child of this path.
    if (clusterNodes.getCurrentData().size() == 0
     && curator.checkExists().forPath("/syncMap") != null
     && curator.checkExists().forPath("/syncMap/" + VERTX_HA_NODE) != null) {
     getSyncMap(VERTX_HA_NODE).clear();
    }
   } catch (Exception ex) {
    log.error("check zk node failed.", ex);
   } finally {
    lockAsyncResult.result().release();
   }
  } else {
   log.error("get cluster init lock failed.", lockAsyncResult.cause());
  }
 });
 curator.create().withMode(CreateMode.EPHEMERAL).forPath(ZK_PATH_CLUSTER_NODE + nodeID, nodeID.getBytes());
}

代码示例来源:origin: vert-x3/vertx-zookeeper

public void stop() {
 try {
  clusterManagers.forEach(clusterManager -> clusterManager.getCuratorFramework().close());
  clusterManagers.clear();
 } catch (Exception e) {
  e.printStackTrace();
 }
}

代码示例来源:origin: vert-x3/vertx-zookeeper

private void addLocalNodeID() throws VertxException {
 clusterNodes = new PathChildrenCache(curator, ZK_PATH_CLUSTER_NODE_WITHOUT_SLASH, true);
 clusterNodes.getListenable().addListener(this);
 try {
  clusterNodes.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
  //Join to the cluster
  createThisNode();
  joined = true;
 } catch (Exception e) {
  throw new VertxException(e);
 }
}

代码示例来源:origin: vert-x3/vertx-zookeeper

private void loadProperties(String resourceLocation) {
 try {
  BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(getConfigStream(resourceLocation))));
  String line;
  StringBuilder sb = new StringBuilder();
  while ((line = reader.readLine()) != null) {
   sb.append(line);
  }
  conf = new JsonObject(sb.toString());
  log.info("Loaded zookeeper.json file from resourceLocation=" + resourceLocation);
 } catch (FileNotFoundException e) {
  log.error("Could not find zookeeper config file", e);
 } catch (IOException e) {
  log.error("Failed to load zookeeper config", e);
 }
}

代码示例来源:origin: vert-x3/vertx-zookeeper

addLocalNodeID();
  future.complete();
 } catch (VertxException e) {
 addLocalNodeID();
 future.complete();
} catch (Exception e) {

代码示例来源:origin: vert-x3/vertx-zookeeper

curator2.start();
ZookeeperClusterManager mgr1 = new ZookeeperClusterManager(curator1);
ZookeeperClusterManager mgr2 = new ZookeeperClusterManager(curator2);
VertxOptions options1 = new VertxOptions().setClusterManager(mgr1).setClustered(true).setClusterHost("127.0.0.1");
VertxOptions options2 = new VertxOptions().setClusterManager(mgr2).setClustered(true).setClusterHost("127.0.0.1");
 assertNotNull(mgr1.getCuratorFramework());
 res.result().eventBus().consumer("news", message -> {
  assertNotNull(message);
 assertNotNull(mgr2.getCuratorFramework());
 vertx2.set(res.result());
 res.result().eventBus().send("news", "hello");

代码示例来源:origin: vert-x3/vertx-zookeeper

String nodeID = UUID.randomUUID().toString();
ZookeeperClusterManager mgr = new ZookeeperClusterManager(curator, nodeID);
VertxOptions options = new VertxOptions().setClusterManager(mgr).setClustered(true).setClusterHost("127.0.0.1");
 assertNotNull(mgr.getCuratorFramework());
 res.result().sharedData().getClusterWideMap("mymap1", ar -> {
  ar.result().put("news", "hello", v -> {
int size = mgr.getNodes().size();
assertTrue(size > 0);
assertTrue(mgr.getNodes().contains(nodeID));
assertWaitUntil(() -> mgr.getNodes().size() == size - 1);
vertx1.get().close();
vertx1.get().close(ar -> vertx1.set(null));

代码示例来源:origin: io.vertx/vertx-zookeeper

@Test
public void testProgrammaticSetConfig() throws Exception {
 JsonObject config = zkCluster.getDefaultConfig();
 ZookeeperClusterManager mgr = new ZookeeperClusterManager();
 mgr.setConfig(config);
 testProgrammatic(mgr, config);
}

代码示例来源:origin: io.vertx/vertx-zookeeper

private void testProgrammatic(ZookeeperClusterManager mgr, JsonObject 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.getCuratorFramework());
  res.result().close(res2 -> {
   assertTrue(res2.succeeded());
   testComplete();
  });
 });
 await();
}

代码示例来源:origin: io.vertx/vertx-zookeeper

public void stop() {
 try {
  clusterManagers.forEach(clusterManager -> clusterManager.getCuratorFramework().close());
  clusterManagers.clear();
 } catch (Exception e) {
  e.printStackTrace();
 }
}

代码示例来源:origin: vert-x3/vertx-zookeeper

case CONNECTION_RECONNECTED:
 if (joined) {
  createThisNode();

代码示例来源:origin: vert-x3/vertx-examples

public static void main(String[] args) {
  JsonObject zkConfig = configureClusterManager();
  ClusterManager zookeeperClusterManager = new ZookeeperClusterManager(zkConfig);
  VertxOptions options = configureVertx(zookeeperClusterManager);
  Vertx.clusteredVertx(options, res -> {
    if (res.succeeded()) {
      Vertx vertx = res.result();
      DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(2);
      vertx.deployVerticle("verticle.ConsumerVerticle", deploymentOptions);
      System.out.println("consumer verticle deployed");
    }
  });
}

代码示例来源:origin: io.vertx/vertx-zookeeper

curator2.start();
ZookeeperClusterManager mgr1 = new ZookeeperClusterManager(curator1);
ZookeeperClusterManager mgr2 = new ZookeeperClusterManager(curator2);
VertxOptions options1 = new VertxOptions().setClusterManager(mgr1).setClustered(true).setClusterHost("127.0.0.1");
VertxOptions options2 = new VertxOptions().setClusterManager(mgr2).setClustered(true).setClusterHost("127.0.0.1");
 assertNotNull(mgr1.getCuratorFramework());
 res.result().sharedData().getClusterWideMap("mymap1", ar -> {
  ar.result().put("news", "hello", v -> {
 assertNotNull(mgr2.getCuratorFramework());
 vertx2.set(res.result());
 res.result().sharedData().getClusterWideMap("mymap1", ar -> {

代码示例来源:origin: vert-x3/vertx-zookeeper

public void example2() {
 JsonObject zkConfig = new JsonObject();
 zkConfig.put("zookeeperHosts", "127.0.0.1");
 zkConfig.put("rootPath", "io.vertx");
 zkConfig.put("retry", new JsonObject()
   .put("initialSleepTime", 3000)
   .put("maxTimes", 3));
 ClusterManager mgr = new ZookeeperClusterManager(zkConfig);
 VertxOptions options = new VertxOptions().setClusterManager(mgr);
 Vertx.clusteredVertx(options, res -> {
  if (res.succeeded()) {
   Vertx vertx = res.result();
  } else {
   // failed!
  }
 });
}

代码示例来源:origin: vert-x3/vertx-zookeeper

curator2.start();
ZookeeperClusterManager mgr1 = new ZookeeperClusterManager(curator1);
ZookeeperClusterManager mgr2 = new ZookeeperClusterManager(curator2);
VertxOptions options1 = new VertxOptions().setClusterManager(mgr1).setClustered(true).setClusterHost("127.0.0.1");
VertxOptions options2 = new VertxOptions().setClusterManager(mgr2).setClustered(true).setClusterHost("127.0.0.1");
 assertNotNull(mgr1.getCuratorFramework());
 res.result().sharedData().getClusterWideMap("mymap1", ar -> {
  ar.result().put("news", "hello", v -> {
 assertNotNull(mgr2.getCuratorFramework());
 vertx2.set(res.result());
 res.result().sharedData().getClusterWideMap("mymap1", ar -> {

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com