io.vertx.core.VertxOptions.setClusterManager()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(152)

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

VertxOptions.setClusterManager介绍

[英]Programmatically set the cluster manager to be used when clustering.

Only valid if clustered = true.

Normally Vert.x will look on the classpath for a cluster manager, but if you want to set one programmatically you can use this method.
[中]以编程方式设置群集时要使用的群集管理器。
仅当clustered=true时有效。
通常是垂直的。x将在类路径上查找集群管理器,但如果您想以编程方式设置集群管理器,可以使用此方法。

代码示例

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

@PostConstruct
void init() throws ExecutionException, InterruptedException {
 VertxOptions options = new VertxOptions()
  .setClusterManager(new HazelcastClusterManager(hazelcastInstance));
 CompletableFuture<Vertx> future = new CompletableFuture<>();
 Vertx.clusteredVertx(options, ar -> {
  if (ar.succeeded()) {
   future.complete(ar.result());
  } else {
   future.completeExceptionally(ar.cause());
  }
 });
 vertx = future.get();
}

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

/**
   * Specifies Vert.x instance configuration, this is essential for clustering on multiple separate machines and
   * Docker containers in order to make Event Bus send/consume messages appropriately
   * @param clusterManager represents the cluster manager
   * @return VertxOptions object to be used in deployment
   */
  private static VertxOptions configureVertx(ClusterManager clusterManager) {
    /*
      the default value of the cluster host (localhost) is used here, if we want to have multiple machines/docker
      containers in our cluster we must configure the cluster host properly on each node in order for the event bus
      to send/consume messages properly between our verticles, to do so we use the method setClusterHost and give it
      this node's IP. For example:
      options.setClusterHost(192.168.1.12);
    */
    VertxOptions options = new VertxOptions()
        .setClustered(true)
        .setClusterManager(clusterManager);
    return options;
  }
}

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

/**
   * Specifies Vert.x instance configuration, this is essential for clustering on multiple separate machines and
   * Docker containers in order to make Event Bus send/consume messages appropriately
   * @param clusterManager represents the cluster manager
   * @return VertxOptions object to be used in deployment
   */
  private static VertxOptions configureVertx(ClusterManager clusterManager) {
    /*
      the default value of the cluster host (localhost) is used here, if we want to have multiple machines/docker
      containers in our cluster we must configure the cluster host properly on each node in order for the event bus
      to send/consume messages properly between our verticles, to do so we use the method setClusterHost and give it
      this node's IP. For example:
      options.setClusterHost(192.168.1.12);
    */
    VertxOptions options = new VertxOptions()
        .setClustered(true)
        .setClusterManager(clusterManager);
    return options;
  }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
 public void testCallbackInvokedOnFailure() throws Exception {

  // will trigger java.net.UnknownHostException
  String hostName = "zoom.zoom.zen.tld";

  VertxOptions options = new VertxOptions()
   .setClusterManager(new FakeClusterManager())
   .setClusterHost(hostName);

  AtomicReference<AsyncResult<Vertx>> resultRef = new AtomicReference<>();

  CountDownLatch latch = new CountDownLatch(1);
  Vertx.clusteredVertx(options, ar -> {
   resultRef.set(ar);
   latch.countDown();
  });
  awaitLatch(latch);

  assertFalse(resultRef.get() == null);
  assertTrue(resultRef.get().failed());
  assertTrue("Was expecting failure to be an instance of UnknownHostException", resultRef.get().cause() instanceof UnknownHostException);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

protected void startNodes(int numNodes, VertxOptions options) {
 CountDownLatch latch = new CountDownLatch(numNodes);
 vertices = new Vertx[numNodes];
 for (int i = 0; i < numNodes; i++) {
  int index = i;
  clusteredVertx(options.setClusterHost("localhost").setClusterPort(0).setClustered(true)
   .setClusterManager(getClusterManager()), ar -> {
    try {
     if (ar.failed()) {
      ar.cause().printStackTrace();
     }
     assertTrue("Failed to start node", ar.succeeded());
     vertices[index] = ar.result();
    }
    finally {
     latch.countDown();
    }
  });
 }
 try {
  assertTrue(latch.await(2, TimeUnit.MINUTES));
 } catch (InterruptedException e) {
  fail(e.getMessage());
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

protected Vertx startVertx(String haGroup, int quorumSize, boolean ha) throws Exception {
 VertxOptions options = new VertxOptions().setHAEnabled(ha).setClustered(true).
  setClusterHost("localhost").setClusterManager(getClusterManager());
 if (ha) {
  options.setQuorumSize(quorumSize);
  if (haGroup != null) {
   options.setHAGroup(haGroup);
  }
 }
 CountDownLatch latch = new CountDownLatch(1);
 AtomicReference<Vertx> vertxRef = new AtomicReference<>();
 clusteredVertx(options, onSuccess(vertx -> {
  vertxRef.set(vertx);
  latch.countDown();
 }));
 latch.await(2, TimeUnit.MINUTES);
 return vertxRef.get();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
 public void testCreateClusteredVertxAsyncDetectJoinFailure() {
  VertxOptions options = new VertxOptions().setClusterManager(new FakeClusterManager(){
   @Override
   public void join(Handler<AsyncResult<Void>> resultHandler) {
    resultHandler.handle(Future.failedFuture(new Exception("joinfailure")));
   }
  });
  clusteredVertx(options, ar -> {
   assertTrue(ar.failed());
   assertEquals("joinfailure", ar.cause().getMessage());
   testComplete();
  });
  await();
 }
}

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

@Test
 public void testCallbackInvokedOnFailure() throws Exception {

  // will trigger java.net.UnknownHostException
  String hostName = "zoom.zoom.zen.tld";

  VertxOptions options = new VertxOptions()
   .setClusterManager(new FakeClusterManager())
   .setClusterHost(hostName);

  AtomicReference<AsyncResult<Vertx>> resultRef = new AtomicReference<>();

  CountDownLatch latch = new CountDownLatch(1);
  Vertx.clusteredVertx(options, ar -> {
   resultRef.set(ar);
   latch.countDown();
  });
  awaitLatch(latch);

  assertFalse(resultRef.get() == null);
  assertTrue(resultRef.get().failed());
  assertTrue("Was expecting failure to be an instance of UnknownHostException", resultRef.get().cause() instanceof UnknownHostException);
 }
}

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

protected void startNodes(int numNodes, VertxOptions options) {
 CountDownLatch latch = new CountDownLatch(numNodes);
 vertices = new Vertx[numNodes];
 for (int i = 0; i < numNodes; i++) {
  int index = i;
  clusteredVertx(options.setClusterHost("localhost").setClusterPort(0).setClustered(true)
   .setClusterManager(getClusterManager()), ar -> {
    try {
     if (ar.failed()) {
      ar.cause().printStackTrace();
     }
     assertTrue("Failed to start node", ar.succeeded());
     vertices[index] = ar.result();
    }
    finally {
     latch.countDown();
    }
  });
 }
 try {
  assertTrue(latch.await(2, TimeUnit.MINUTES));
 } catch (InterruptedException e) {
  fail(e.getMessage());
 }
}

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

protected Vertx startVertx(String haGroup, int quorumSize, boolean ha) throws Exception {
 VertxOptions options = new VertxOptions().setHAEnabled(ha).setClustered(true).
  setClusterHost("localhost").setClusterManager(getClusterManager());
 if (ha) {
  options.setQuorumSize(quorumSize);
  if (haGroup != null) {
   options.setHAGroup(haGroup);
  }
 }
 CountDownLatch latch = new CountDownLatch(1);
 AtomicReference<Vertx> vertxRef = new AtomicReference<>();
 clusteredVertx(options, onSuccess(vertx -> {
  vertxRef.set(vertx);
  latch.countDown();
 }));
 latch.await(2, TimeUnit.MINUTES);
 return vertxRef.get();
}

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

@Test
 public void testCreateClusteredVertxAsyncDetectJoinFailure() {
  VertxOptions options = new VertxOptions().setClusterManager(new FakeClusterManager(){
   @Override
   public void join(Handler<AsyncResult<Void>> resultHandler) {
    resultHandler.handle(Future.failedFuture(new Exception("joinfailure")));
   }
  });
  clusteredVertx(options, ar -> {
   assertTrue(ar.failed());
   assertEquals("joinfailure", ar.cause().getMessage());
   testComplete();
  });
  await();
 }
}

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

@Override
public void setUp() throws Exception {
 super.setUp();
 VertxOptions options = new VertxOptions();
 options.setClustered(true);
 options.setClusterManager(getClusterManager());
 startNodes(numNodes, options);
 store = ClusteredSessionStore.create(vertices[0], 3000);
}

代码示例来源:origin: eclipse-vertx/vert.x

assertEquals(options, options.setClusterManager(mgr));
assertSame(mgr, options.getClusterManager());
assertFalse(options.isHAEnabled());

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

public void example3(CuratorFramework curator) {
  ClusterManager mgr = new ZookeeperClusterManager(curator);
  VertxOptions options = new VertxOptions().setClusterManager(mgr);
  Vertx.clusteredVertx(options, res -> {
   if (res.succeeded()) {
    Vertx vertx = res.result();
   } else {
    // failed!
   }
  });
 }
}

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

public void example1() {
 ClusterManager mgr = new ZookeeperClusterManager();
 VertxOptions options = new VertxOptions().setClusterManager(mgr);
 Vertx.clusteredVertx(options, res -> {
  if (res.succeeded()) {
   Vertx vertx = res.result();
  } else {
   // failed!
  }
 });
}

代码示例来源:origin: stackoverflow.com

VertxOptions options = new VertxOptions();
 Config config = new Config();
 NetworkConfig networkConfig = config.getNetworkConfig();
 networkConfig.getInterfaces().setEnabled(true).addInterface(args[0]);
 options.setClusterManager(new HazelcastClusterManager(config));
 options.setClustered(true);
 options.setClusterHost(args[0]);
 Vertx.clusteredVertx(options, res -> {
   Vertx vertx = res.result();
   vertx.deployVerticle(new Receiver());
 });

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

@Before
 public void setUp() {
  Random random = new Random();
  System.setProperty("vertx.infinispan.test.auth.token", new BigInteger(128, random).toString(32));

  VertxOptions options = new VertxOptions()
   .setClusterManager(new InfinispanClusterManager());
  Vertx.clusteredVertx(options, ar -> {
   vertx = ar.result();
  });
  await().until(() -> vertx != null);
  discovery = new DiscoveryImpl(vertx, new ServiceDiscoveryOptions());
 }
}

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

@Override
public void setUp() throws Exception {
 super.setUp();
 VertxOptions options = new VertxOptions();
 options.setClustered(true);
 options.setClusterManager(getClusterManager());
 startNodes(numNodes, options);
 store = ClusteredSessionStore.create(vertices[0], 3000);
}

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

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();
}

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

assertEquals(options, options.setClusterManager(mgr));
assertSame(mgr, options.getClusterManager());
assertFalse(options.isHAEnabled());

相关文章

VertxOptions类方法