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

The following examples show how to use io.vertx.core.Vertx#isClustered() . 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: SharedGlobalDataRegistry.java    From apiman with Apache License 2.0 6 votes vote down vote up
public SharedGlobalDataRegistry(Vertx vertx, IEngineConfig vxConfig, Map<String, String> options) {
    this.vertx = vertx;
    this.vxConfig = vxConfig;
    this.options = options;

    if (!vertx.isClustered()) {
        throw new IllegalStateException(SharedGlobalDataRegistry.class.getCanonicalName() + " only works when operating in clustered mode!");
    }

    vertx.sharedData().<String, Object> getClusterWideMap("SharedGlobalDataRegistry-Shared",  async -> {
        if (async.succeeded()) {
            objectMap = async.result();
        } else {
            throw new IllegalStateException(async.cause());
        }
    });
}
 
Example 2
Source File: CircuitBreakerMetrics.java    From vertx-circuit-breaker with Apache License 2.0 5 votes vote down vote up
CircuitBreakerMetrics(Vertx vertx, CircuitBreakerImpl circuitBreaker, CircuitBreakerOptions options) {
  this.circuitBreaker = circuitBreaker;
  this.circuitBreakerTimeout = circuitBreaker.options().getTimeout();
  this.circuitBreakerResetTimeout = circuitBreaker.options().getResetTimeout();
  this.node = vertx.isClustered() ? ((VertxInternal) vertx).getClusterManager().getNodeId() : "local";
  this.rollingWindow = new RollingWindow(options.getMetricsRollingWindow(), options.getMetricsRollingBuckets());
}
 
Example 3
Source File: AsyncMapFactory.java    From okapi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an AsyncMap.
 *
 * @param <K> Key type
 * @param <V> Value type
 * @param vertx Vert.x handle
 * @param mapName name of the map. If null, will always create a local map
 * @param fut future
 */
public static <K, V> void create(Vertx vertx, String mapName,
                                 Handler<ExtendedAsyncResult<AsyncMap<K, V>>> fut) {
  SharedData shared = vertx.sharedData();
  if (vertx.isClustered() && mapName != null) {
    shared.<K, V>getClusterWideMap(mapName, res -> {
      if (res.succeeded()) {
        fut.handle(new Success<>(res.result()));
      } else {
        fut.handle(new Failure<>(ErrorType.INTERNAL, res.cause()));
      }
    });
  } else {
    // Dirty trickery to make sure we can run two verticles in our tests,
    // without them sharing the 'shared' memory. Only when running in non-
    // clustered mode, of course.
    // Also used in deploy-only nodes, where we want local-only tenant and
    // module lists with only the hard-coded supertenant and internalModule.
    String id = vertx.getOrCreateContext().deploymentID();
    if (mapName != null) {
      id = mapName + id;
    }
    shared.<K, V>getLocalAsyncMap(id, res -> {
      if (res.succeeded()) {
        fut.handle(new Success<>(res.result()));
      } else {
        fut.handle(new Failure<>(ErrorType.INTERNAL, res.cause()));
      }
    });
  }
}
 
Example 4
Source File: DefaultServiceDiscoveryBackend.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Vertx vertx, JsonObject config) {
  this.vertx = vertx;
  if (!vertx.isClustered() || useLocalBackend()) {
    registry = vertx.sharedData().<String, String>getLocalAsyncMap("service.registry").result();
  }
}
 
Example 5
Source File: AbstractRegistrar.java    From vertx-graphql-service-discovery with Apache License 2.0 5 votes vote down vote up
private static String getNodeId(Vertx vertx) {
    if (vertx.isClustered()) {
        return ((VertxInternal) vertx).getNodeID();
    } else {
        return "localhost";
    }
}