Java Code Examples for io.vertx.core.Vertx#clusteredVertx()

The following examples show how to use io.vertx.core.Vertx#clusteredVertx() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Examples.java    From vertx-hazelcast with Apache License 2.0 6 votes vote down vote up
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!
      }
    });
  }
 
Example 2
Source File: Examples.java    From vertx-hazelcast with Apache License 2.0 6 votes vote down vote up
public void liteMemberConfig() {
  Config hazelcastConfig = ConfigUtil.loadConfig()
    .setLiteMember(true);

  ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);

  VertxOptions options = new VertxOptions().setClusterManager(mgr);

  Vertx.clusteredVertx(options, res -> {
    if (res.succeeded()) {
      Vertx vertx = res.result();
    } else {
      // failed!
    }
  });
}
 
Example 3
Source File: Examples.java    From vertx-hazelcast with Apache License 2.0 6 votes vote down vote up
public void customizeDefaultConfig() {
  Config hazelcastConfig = ConfigUtil.loadConfig();

  hazelcastConfig.setClusterName("my-cluster-name");

  ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);

  VertxOptions options = new VertxOptions().setClusterManager(mgr);

  Vertx.clusteredVertx(options, res -> {
    if (res.succeeded()) {
      Vertx vertx = res.result();
    } else {
      // failed!
    }
  });
}
 
Example 4
Source File: VxmsGateway.java    From kube_vertx_demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    DeploymentOptions options = new DeploymentOptions().setInstances(1).
            setConfig(new JsonObject().put("local", true).put("host", "0.0.0.0").put("port", 8181));
    VertxOptions vOpts = new VertxOptions();
    vOpts.setClustered(true);
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(VxmsGateway.class.getName(), options, handle -> {

            });
        }
    });

}
 
Example 5
Source File: InfinispanDiscoveryImplClusteredTest.java    From vertx-infinispan with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 6
Source File: Examples.java    From vertx-infinispan with Apache License 2.0 5 votes vote down vote up
public void useExistingCacheManager(DefaultCacheManager cacheManager) {
  ClusterManager mgr = new InfinispanClusterManager(cacheManager);

  VertxOptions options = new VertxOptions().setClusterManager(mgr);

  Vertx.clusteredVertx(options, res -> {
    if (res.succeeded()) {
      Vertx vertx = res.result();
    } else {
      // failed!
    }
  });
}
 
Example 7
Source File: Runner.java    From vxms with Apache License 2.0 5 votes vote down vote up
public static void run(DeploymentOptions options, Class clazz) {
    VertxOptions vOpts = new VertxOptions();
    vOpts.setClustered(true);
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(clazz.getName(), options, handle -> {

            });
        }
    });
}
 
Example 8
Source File: Examples.java    From vertx-hazelcast with Apache License 2.0 5 votes vote down vote up
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!
    }
  });
}
 
Example 9
Source File: Examples.java    From vertx-ignite with Apache License 2.0 5 votes vote down vote up
public void example2() {
  IgniteConfiguration cfg = new IgniteConfiguration();
  // Configuration code (omitted)

  ClusterManager clusterManager = new IgniteClusterManager(cfg);

  VertxOptions options = new VertxOptions().setClusterManager(clusterManager);
  Vertx.clusteredVertx(options, res -> {
    if (res.succeeded()) {
      Vertx vertx = res.result();
    } else {
      // failed!
    }
  });
}
 
Example 10
Source File: Vertx3GatewayTestServer.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
    try {
        if (clustered) {
            CountDownLatch clusteredStart = new CountDownLatch(1);
            Vertx.clusteredVertx(new VertxOptions().setClustered(clustered).setClusterHost("localhost").setBlockedThreadCheckInterval(9999999), result -> {
                if (result.succeeded()) {
                    System.out.println("**** Clustered Vert.x started up successfully! ****");
                    this.vertx = result.result();
                    clusteredStart.countDown();
                } else {
                    throw new RuntimeException(result.cause());
                }
            });
            clusteredStart.await();
        } else {
            vertx = Vertx.vertx(new VertxOptions().setBlockedThreadCheckInterval(9999999));
        }
        echoServer.start();

        startLatch = new CountDownLatch(1);

        DeploymentOptions options = new DeploymentOptions();
        options.setConfig(vertxConf);

        vertx.deployVerticle(InitVerticle.class.getCanonicalName(),
                options, result -> {
                    if (result.succeeded()) {
                        System.out.println("*** Started Non-clustered Vert.x successfully ***");
                    } else {
                        throw new RuntimeException("InitVerticle deployment failed", result.cause());
                    }
                    startLatch.countDown();
                });

        startLatch.await();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 11
Source File: KueRestApiTest.java    From vertx-kue with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp(TestContext context) throws Exception {
  Async async = context.async();
  Vertx.clusteredVertx(new VertxOptions(), r -> {
    if (r.succeeded()) {
      Vertx vertx = r.result();
      kue = Kue.createQueue(vertx, new JsonObject());
      vertx.deployVerticle(new KueVerticle(), r2 -> {
        if (r2.succeeded()) {
          kue.jobRangeByType(TYPE, "inactive", 0, 100, "asc").setHandler(r1 -> {
            if (r1.succeeded()) {
              r1.result().forEach(Job::remove);
              vertx.deployVerticle(new KueHttpVerticle(), r3 -> {
                if (r3.succeeded())
                  async.complete();
                else
                  context.fail(r3.cause());
              });
            } else {
              context.fail(r1.cause());
            }
          });
        } else {
          context.fail(r2.cause());
        }
      });

    } else {
      context.fail(r.cause());
    }
  });
}
 
Example 12
Source File: Runner.java    From kube_vertx_demo with Apache License 2.0 5 votes vote down vote up
public static void run(DeploymentOptions options, Class clazz) {
    VertxOptions vOpts = new VertxOptions();
    vOpts.setClustered(true);
    Vertx.clusteredVertx(vOpts, cluster -> {
        if (cluster.succeeded()) {
            final Vertx result = cluster.result();
            result.deployVerticle(clazz.getName(), options, handle -> {

            });
        }
    });
}
 
Example 13
Source File: Application.java    From skywalking with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    System.setProperty("vertx.disableFileCPResolving", "true");
    ClusterManager mgr = new HazelcastClusterManager();
    VertxOptions options = new VertxOptions().setClusterManager(mgr);
    Vertx.clusteredVertx(options, cluster -> {
        if (cluster.succeeded()) {
            cluster.result().deployVerticle(new ClusterReceiver(), deploy -> {
                if (deploy.succeeded()) {
                    ClusterManager mgr2 = new HazelcastClusterManager();
                    VertxOptions options2 = new VertxOptions().setClusterManager(mgr2);
                    Vertx.clusteredVertx(options2, cluster2 -> {
                        if (cluster2.succeeded()) {
                            cluster2.result().deployVerticle(new VertxEventbusController());
                        } else {
                            cluster2.cause().printStackTrace();
                            System.exit(-1);
                        }
                    });
                } else {
                    deploy.cause().printStackTrace();
                    System.exit(-1);
                }
            });
        } else {
            cluster.cause().printStackTrace();
            System.exit(-1);
        }
    });
}
 
Example 14
Source File: DiscoveryImplClusteredTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  FakeClusterManager.reset();
  VertxOptions options = new VertxOptions();
  options
    .setClusterManager(new FakeClusterManager())
    .getEventBusOptions().setHost("127.0.0.1");
  Vertx.clusteredVertx(options, ar -> {
    vertx = ar.result();
  });
  await().until(() -> vertx != null);
  discovery = new DiscoveryImpl(vertx, new ServiceDiscoveryOptions());
}
 
Example 15
Source File: DefaultServiceDiscoveryBackendClusteredTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() {
  backend = new DefaultServiceDiscoveryBackend();
  VertxOptions options = new VertxOptions();
  options.getEventBusOptions().setHost("127.0.0.1");
  Vertx.clusteredVertx(options, ar -> {
    backend.init(ar.result(), new JsonObject());
    vertx = ar.result();
  });
  await().until(() -> vertx != null);
}
 
Example 16
Source File: MainDeploy.java    From okapi with Apache License 2.0 5 votes vote down vote up
private void deployClustered(final Logger logger, Handler<AsyncResult<Vertx>> fut) {
  if (hazelcastConfig == null) {
    hazelcastConfig = ConfigUtil.loadConfig();
    if (clusterHost != null) {
      NetworkConfig network = hazelcastConfig.getNetworkConfig();
      InterfacesConfig interfacesConfig = network.getInterfaces();
      interfacesConfig.setEnabled(true).addInterface(clusterHost);
    }
  }
  hazelcastConfig.setProperty("hazelcast.logging.type", "log4j");

  HazelcastClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);
  vopt.setClusterManager(mgr);
  EventBusOptions eventBusOptions = vopt.getEventBusOptions();
  if (clusterHost != null) {
    logger.info("clusterHost={}", clusterHost);
    eventBusOptions.setHost(clusterHost);
  } else {
    logger.warn("clusterHost not set");
  }
  if (clusterPort != -1) {
    logger.info("clusterPort={}", clusterPort);
    eventBusOptions.setPort(clusterPort);
  } else {
    logger.warn("clusterPort not set");
  }
  eventBusOptions.setClustered(true);

  Vertx.clusteredVertx(vopt, res -> {
    if (res.succeeded()) {
      MainVerticle v = new MainVerticle();
      v.setClusterManager(mgr);
      deploy(v, res.result(), fut);
    } else {
      fut.handle(Future.failedFuture(res.cause()));
    }
  });
}
 
Example 17
Source File: VertxCoreRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static Vertx initialize(VertxConfiguration conf, VertxOptionsCustomizer customizer) {

        VertxOptions options = new VertxOptions();

        if (conf != null) {
            convertToVertxOptions(conf, options, true);
        }

        // Allow extension customizers to do their thing
        if (customizer != null) {
            customizer.customize(options);
        }

        Vertx vertx;
        if (options.getEventBusOptions().isClustered()) {
            CompletableFuture<Vertx> latch = new CompletableFuture<>();
            Vertx.clusteredVertx(options, ar -> {
                if (ar.failed()) {
                    latch.completeExceptionally(ar.cause());
                } else {
                    latch.complete(ar.result());
                }
            });
            vertx = latch.join();
        } else {
            vertx = Vertx.vertx(options);
        }
        return logVertxInitialization(vertx);
    }
 
Example 18
Source File: FirstInstance.java    From vertx-in-action with MIT License 5 votes vote down vote up
public static void main(String[] args) {
  Vertx.clusteredVertx(new VertxOptions(), ar -> {
    if (ar.succeeded()) {
      logger.info("First instance has been started");
      Vertx vertx = ar.result();
      vertx.deployVerticle("chapter3.HeatSensor", new DeploymentOptions().setInstances(4));
      vertx.deployVerticle("chapter3.HttpServer");
    } else {
      logger.error("Could not start", ar.cause());
    }
  });
}
 
Example 19
Source File: HeatSensor.java    From vertx-in-action with MIT License 5 votes vote down vote up
public static void main(String[] args) throws UnknownHostException {
  String ipv4 = InetAddress.getLocalHost().getHostAddress();
  VertxOptions options = new VertxOptions()
    .setEventBusOptions(new EventBusOptions()
      .setHost(ipv4)
      .setClusterPublicHost(ipv4));
  Vertx.clusteredVertx(options, ar -> {
    if (ar.succeeded()) {
      ar.result().deployVerticle(new HeatSensor());
    } else {
      logger.error("Could not start", ar.cause());
    }
  });
}
 
Example 20
Source File: ClusteredAsyncMapTest.java    From vertx-service-discovery with Apache License 2.0 4 votes vote down vote up
@Override
protected Future<Vertx> createVertx() {
  return Vertx.clusteredVertx(new VertxOptions());
}