@Override void wait(long index, Handler<AsyncResult<State<KeyValue>>> handler) { BlockingQueryOptions options = new BlockingQueryOptions().setWait(BLOCKING_WAIT).setIndex(index); consulClient.getValueWithOptions(key, options, h -> handler.handle(h.map(kv -> new State<KeyValue>(kv, kv.getModifyIndex())))); } }
public static void toJson(EventListOptions obj, java.util.Map<String, Object> json) { if (obj.getBlockingOptions() != null) { json.put("blockingOptions", obj.getBlockingOptions().toJson()); } if (obj.getName() != null) { json.put("name", obj.getName()); } } }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, BlockingQueryOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "index": if (member.getValue() instanceof Number) { obj.setIndex(((Number)member.getValue()).longValue()); } break; case "wait": if (member.getValue() instanceof String) { obj.setWait((String)member.getValue()); } break; } } }
private void testServicesBlocking(Consumer<Handler<AsyncResult<ServiceList>>> runner, BiConsumer<BlockingQueryOptions, Handler<AsyncResult<ServiceList>>> request) throws InterruptedException { runAsync(h -> ctx.writeClient().registerService(new ServiceOptions().setName("service1").setId("id1"), h)); ServiceList list1 = getAsync(runner); list1.getList().forEach(s -> System.out.println("--- " + s.toJson().encode())); CountDownLatch latch = new CountDownLatch(1); waitBlockingQuery(latch, 10, list1.getIndex(), (idx, fut) -> { request.accept(new BlockingQueryOptions().setIndex(idx), h -> { h.result().getList().forEach(s -> System.out.println("-+- " + s.toJson().encode())); List<String> names = h.result().getList().stream().map(Service::getName).collect(Collectors.toList()); waitComplete(vertx, fut, h.result().getIndex(), names.contains("service2")); }); }); sleep(vertx, 4000); assertEquals(latch.getCount(), 1); runAsync(h -> ctx.writeClient().registerService(new ServiceOptions().setName("service2").setId("id2"), h)); awaitLatch(latch); runAsync(h -> ctx.writeClient().deregisterService("id1", h)); runAsync(h -> ctx.writeClient().deregisterService("id2", h)); }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, EventListOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "blockingOptions": if (member.getValue() instanceof JsonObject) { obj.setBlockingOptions(new io.vertx.ext.consul.BlockingQueryOptions((JsonObject)member.getValue())); } break; case "name": if (member.getValue() instanceof String) { obj.setName((String)member.getValue()); } break; } } }
.setBlockingOptions(new BlockingQueryOptions().setIndex(nodes1.getIndex())); ctx.readClient().catalogNodesWithOptions(blockingQueryOptions1, h -> { System.out.println(">>>>>>> new node event received"); ctx.readClient().catalogNodes(tc.asyncAssertSuccess(nodes2 -> { NodeQueryOptions blockingQueryOptions2 = new NodeQueryOptions() .setBlockingOptions(new BlockingQueryOptions().setIndex(nodes2.getIndex())); System.out.println(">>>>>>> wait for new node detaching"); ctx.readClient().catalogNodesWithOptions(blockingQueryOptions2, tc.asyncAssertSuccess());
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, NodeQueryOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "blockingOptions": if (member.getValue() instanceof JsonObject) { obj.setBlockingOptions(new io.vertx.ext.consul.BlockingQueryOptions((JsonObject)member.getValue())); } break; case "near": if (member.getValue() instanceof String) { obj.setNear((String)member.getValue()); } break; } } }
@Override void wait(long index, Handler<AsyncResult<State<KeyValueList>>> handler) { BlockingQueryOptions options = new BlockingQueryOptions().setWait(BLOCKING_WAIT).setIndex(index); consulClient.getValuesWithOptions(keyPrefix, options, h -> handler.handle(h.map(kv -> new State<KeyValueList>(kv, kv.getIndex())))); } }
private void testSessionsBlocking(TestContext tc, BiConsumer<BlockingQueryOptions, Handler<AsyncResult<SessionList>>> request) { ctx.writeClient().createSession(tc.asyncAssertSuccess(id1 -> { ctx.readClient().listSessions(tc.asyncAssertSuccess(list1 -> { Async async = tc.async(); request.accept(new BlockingQueryOptions().setIndex(list1.getIndex()), h -> { List<String> ids = h.result().getList().stream().map(Session::getId).collect(Collectors.toList()); assertTrue(ids.contains(id1)); async.countDown(); }); vertx.setTimer(1000, l -> { assertEquals(async.count(), 1); ctx.writeClient().createSession(tc.asyncAssertSuccess(id2 -> { async.handler(a -> { ctx.writeClient().destroySession(id1, tc.asyncAssertSuccess(d1 -> { ctx.writeClient().destroySession(id2, tc.asyncAssertSuccess()); })); }); })); }); })); })); }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, CheckQueryOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "blockingOptions": if (member.getValue() instanceof JsonObject) { obj.setBlockingOptions(new io.vertx.ext.consul.BlockingQueryOptions((JsonObject)member.getValue())); } break; case "near": if (member.getValue() instanceof String) { obj.setNear((String)member.getValue()); } break; } } }
public static void toJson(NodeQueryOptions obj, java.util.Map<String, Object> json) { if (obj.getBlockingOptions() != null) { json.put("blockingOptions", obj.getBlockingOptions().toJson()); } if (obj.getNear() != null) { json.put("near", obj.getNear()); } } }
@Override void wait(long index, Handler<AsyncResult<State<ServiceList>>> handler) { BlockingQueryOptions options = new BlockingQueryOptions().setWait(BLOCKING_WAIT).setIndex(index); consulClient.catalogServicesWithOptions(options, h -> handler.handle(h.map(services -> new State<ServiceList>(services, services.getIndex())))); } }
BlockingQueryOptions opts = new BlockingQueryOptions().setIndex(idx); ctx.readClient().coordinateNodesWithOptions(opts, h -> { boolean success = h.result().getList().size() == 2;
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, ServiceQueryOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "blockingOptions": if (member.getValue() instanceof JsonObject) { obj.setBlockingOptions(new io.vertx.ext.consul.BlockingQueryOptions((JsonObject)member.getValue())); } break; case "near": if (member.getValue() instanceof String) { obj.setNear((String)member.getValue()); } break; case "tag": if (member.getValue() instanceof String) { obj.setTag((String)member.getValue()); } break; } } }
public static void toJson(CheckQueryOptions obj, java.util.Map<String, Object> json) { if (obj.getBlockingOptions() != null) { json.put("blockingOptions", obj.getBlockingOptions().toJson()); } if (obj.getNear() != null) { json.put("near", obj.getNear()); } } }
@Override void wait(long index, Handler<AsyncResult<State<ServiceEntryList>>> handler) { BlockingQueryOptions bOpts = new BlockingQueryOptions().setWait(BLOCKING_WAIT).setIndex(index); ServiceQueryOptions sOpts = new ServiceQueryOptions().setBlockingOptions(bOpts); consulClient.healthServiceNodesWithOptions(service, false, sOpts, h -> handler.handle(h.map(services -> new State<ServiceEntryList>(services, services.getIndex())))); } }
@Test public void healthState() throws InterruptedException { String serviceName = randomAlphaString(10); ServiceOptions opts = new ServiceOptions() .setName(serviceName) .setId(serviceName) .setCheckOptions(new CheckOptions().setTtl("1m")); runAsync(h -> ctx.writeClient().registerService(opts, h)); CheckList list1 = getAsync(h -> ctx.readClient().healthState(HealthState.CRITICAL, h)); CountDownLatch latch = new CountDownLatch(1); waitBlockingQuery(latch, 10, list1.getIndex(), (idx, fut) -> { CheckQueryOptions options = new CheckQueryOptions() .setBlockingOptions(new BlockingQueryOptions().setIndex(idx)); ctx.readClient().healthStateWithOptions(HealthState.PASSING, options, h -> { List<String> names = h.result().getList().stream().map(Check::getServiceName).collect(Collectors.toList()); waitComplete(vertx, fut, h.result().getIndex(), names.contains(serviceName)); }); }); runAsync(h -> ctx.writeClient().passCheck("service:" + serviceName, h)); awaitLatch(latch); runAsync(h -> ctx.writeClient().deregisterService(serviceName, h)); }
public static io.vertx.ext.consul.ConsulService listNodeSessionsWithOptions(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String nodeId, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.listNodeSessionsWithOptions(nodeId, options != null ? new io.vertx.ext.consul.BlockingQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.SessionList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.SessionList> ar) { resultHandler.handle(ar.map(event -> event != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(event.toJson()) : null)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulService createPreparedQuery(io.vertx.ext.consul.ConsulService j_receiver, java.util.Map<String, Object> definition, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> resultHandler) {