@Override public void start() throws Exception { long time = System.nanoTime(); vertx.createHttpServer().requestHandler(request -> { JsonObject json = new JsonObject(); json .put("clustered", vertx.isClustered()) .put("metrics", vertx.isMetricsEnabled()) .put("id", System.getProperty("vertx.id", "no id")) .put("conf", config()) .put("startTime", time); if (System.getProperty("foo") != null) { json.put("foo", System.getProperty("foo")); } if (System.getProperty("baz") != null) { json.put("baz", System.getProperty("baz")); } request.response().putHeader("content-type", "application/json").end(json.encodePrettily()); }).listen(8080); } }
assertThat(this.vertx.isClustered()).isTrue();
@Test public void testCreateClusteredVertxAsync() { VertxOptions options = new VertxOptions(); options.setClustered(true); clusteredVertx(options, ar -> { assertTrue(ar.succeeded()); assertNotNull(ar.result()); assertTrue(ar.result().isClustered()); Vertx v = ar.result(); v.close(ar2 -> { assertTrue(ar2.succeeded()); testComplete(); }); }); await(); }
@Test public void testCreateClusteredVertxAsyncDontSetClustered() { VertxOptions options = new VertxOptions(); clusteredVertx(options, ar -> { assertTrue(ar.succeeded()); assertNotNull(ar.result()); assertTrue(options.isClustered()); assertTrue(ar.result().isClustered()); Vertx v = ar.result(); v.close(ar2 -> { assertTrue(ar2.succeeded()); testComplete(); }); }); await(); }
@Test public void testCreateVertxWithOptions() { VertxOptions options = new VertxOptions(); Vertx vertx = vertx(options); assertNotNull(vertx); assertFalse(vertx.isClustered()); }
@Override public void start() throws Exception { long time = System.nanoTime(); vertx.createHttpServer().requestHandler(request -> { JsonObject json = new JsonObject(); json .put("clustered", vertx.isClustered()) .put("metrics", vertx.isMetricsEnabled()) .put("id", System.getProperty("vertx.id", "no id")) .put("conf", config()) .put("startTime", time); if (System.getProperty("foo") != null) { json.put("foo", System.getProperty("foo")); } if (System.getProperty("baz") != null) { json.put("baz", System.getProperty("baz")); } request.response().putHeader("content-type", "application/json").end(json.encodePrettily()); }).listen(8080); } }
assertThat(this.vertx.isClustered()).isTrue();
/** * Create a Session store given a backend and configuration JSON. * * @param vertx vertx instance * @param options extra options for initialization * @return the store or runtime exception */ static SessionStore create(Vertx vertx, JsonObject options) { SessionStore defaultStore; try { defaultStore = ServiceHelper.loadFactoryOrNull(SessionStore.class); if (defaultStore != null) { return defaultStore.init(vertx, options); } } catch (RuntimeException e) { // ignore that it cannot be loaded, falling back to the next } if (vertx.isClustered()) { defaultStore = new ClusteredSessionStoreImpl(); } else { defaultStore = new LocalSessionStoreImpl(); } return defaultStore.init(vertx, options); }
/** * Is this Vert.x instance clustered? * @return true if clustered */ public boolean isClustered() { boolean ret = delegate.isClustered(); return ret; }
/** * Is this Vert.x instance clustered? * @return true if clustered */ public boolean isClustered() { boolean ret = delegate.isClustered(); return ret; }
@Test public void testCreateClusteredVertxAsync() { VertxOptions options = new VertxOptions(); options.setClustered(true); clusteredVertx(options, ar -> { assertTrue(ar.succeeded()); assertNotNull(ar.result()); assertTrue(ar.result().isClustered()); Vertx v = ar.result(); v.close(ar2 -> { assertTrue(ar2.succeeded()); testComplete(); }); }); await(); }
@Test public void testCreateClusteredVertxAsyncDontSetClustered() { VertxOptions options = new VertxOptions(); clusteredVertx(options, ar -> { assertTrue(ar.succeeded()); assertNotNull(ar.result()); assertTrue(options.isClustered()); assertTrue(ar.result().isClustered()); Vertx v = ar.result(); v.close(ar2 -> { assertTrue(ar2.succeeded()); testComplete(); }); }); await(); }
@Test public void testCreateVertxWithOptions() { VertxOptions options = new VertxOptions(); Vertx vertx = vertx(options); assertNotNull(vertx); assertFalse(vertx.isClustered()); }
private String getNodeId(Vertx vertx) { if (vertx.isClustered()) { return ((VertxInternal) vertx).getNodeID(); } else { return "localhost"; } }
private static String getNodeId(Vertx vertx) { if (vertx.isClustered()) { return ((VertxInternal) vertx).getNodeID(); } else { return "localhost"; } } }
private String getNodeId(Vertx vertx) { if (vertx.isClustered()) { return ((VertxInternal) vertx).getNodeID(); } else { return "localhost"; } }
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()); } }); }
@Override public void init(Vertx vertx, JsonObject config) { this.vertx = vertx; if (!vertx.isClustered() || useLocalBackend()) { registry = new LocalAsyncMap<>(vertx.sharedData().getLocalMap("service.registry")); } }
@Override public void init(Vertx vertx, JsonObject config) { this.vertx = vertx; if (!vertx.isClustered() || useLocalBackend()) { registry = new LocalAsyncMap<>(vertx.sharedData().getLocalMap("service.registry")); } }
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()); }