Java Code Examples for io.vertx.core.impl.VertxInternal#close()

The following examples show how to use io.vertx.core.impl.VertxInternal#close() . 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: Lifecycle.java    From vertx-infinispan with Apache License 2.0 5 votes vote down vote up
public static void closeClustered(List<Vertx> clustered) throws Exception {
  for (Vertx vertx : clustered) {
    VertxInternal vertxInternal = (VertxInternal) vertx;

    InfinispanClusterManager clusterManager = getInfinispanClusterManager(vertxInternal.getClusterManager());

    ComponentStatus status = null;
    if (clusterManager != null) {
      EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
      status = cacheManager.getStatus();

      Health health = cacheManager.getHealth();

      SECONDS.sleep(2); // Make sure rebalancing has been triggered

      long start = System.currentTimeMillis();
      try {
        while (health.getClusterHealth().getHealthStatus() != HealthStatus.HEALTHY
          && System.currentTimeMillis() - start < MILLISECONDS.convert(2, MINUTES)) {
          MILLISECONDS.sleep(100);
        }
      } catch (Exception ignore) {
      }
    }

    if (status == null || status.compareTo(STOPPING) >= 0) {
      vertxInternal.close();
    } else {
      CountDownLatch latch = new CountDownLatch(1);
      vertxInternal.close(ar -> {
        if (ar.failed()) {
          log.error("Failed to shutdown vert.x", ar.cause());
        }
        latch.countDown();
      });
      latch.await(2, TimeUnit.MINUTES);
    }
  }
}
 
Example 2
Source File: Lifecycle.java    From vertx-hazelcast with Apache License 2.0 5 votes vote down vote up
public static void closeClustered(List<Vertx> clustered) throws Exception {
  for (Vertx vertx : clustered) {
    VertxInternal vertxInternal = (VertxInternal) vertx;

    HazelcastClusterManager clusterManager = getHazelcastClusterManager(vertxInternal.getClusterManager());

    if (clusterManager != null) {
      HazelcastInstance hazelcastInstance = clusterManager.getHazelcastInstance();

      SECONDS.sleep(2); // Make sure rebalancing has been triggered

      long start = System.currentTimeMillis();
      try {
        while (!hazelcastInstance.getPartitionService().isClusterSafe()
          && System.currentTimeMillis() - start < MILLISECONDS.convert(2, MINUTES)) {
          MILLISECONDS.sleep(100);
        }
      } catch (Exception ignore) {
      }
    }

    CountDownLatch latch = new CountDownLatch(1);
    vertxInternal.close(ar -> {
      if (ar.failed()) {
        log.error("Failed to shutdown vert.x", ar.cause());
      }
      latch.countDown();
    });
    latch.await(2, TimeUnit.MINUTES);
  }
}