public static void toJson(EventOptions obj, java.util.Map<String, Object> json) { if (obj.getNode() != null) { json.put("node", obj.getNode()); } if (obj.getPayload() != null) { json.put("payload", obj.getPayload()); } if (obj.getService() != null) { json.put("service", obj.getService()); } if (obj.getTag() != null) { json.put("tag", obj.getTag()); } } }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, EventOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "node": if (member.getValue() instanceof String) { obj.setNode((String)member.getValue()); } break; case "payload": if (member.getValue() instanceof String) { obj.setPayload((String)member.getValue()); } break; case "service": if (member.getValue() instanceof String) { obj.setService((String)member.getValue()); } break; case "tag": if (member.getValue() instanceof String) { obj.setTag((String)member.getValue()); } break; } } }
private void runTest(TestContext tc, boolean timeout) { String name1 = randomAlphaString(10); String name2 = randomAlphaString(10); EventOptions opts = new EventOptions().setPayload(randomAlphaString(10)); ctx.writeClient().fireEventWithOptions(name1, opts, tc.asyncAssertSuccess(event -> { tc.assertEquals(name1, event.getName()); tc.assertEquals(opts.getPayload(), event.getPayload()); String evId1 = event.getId(); ctx.writeClient().listEvents(tc.asyncAssertSuccess(list1 -> {
@Test public void watchEvents() throws InterruptedException { StateConsumer<String> consumer = new StateConsumer<>(); String evName = randomAlphaString(10); String p1 = randomAlphaString(10); String p2 = randomAlphaString(10); Watch<EventList> watch = Watch.events(evName, vertx, ctx.readClientOptions()) .setHandler(list -> { if (list.succeeded()) { consumer.consume(list.nextResult().getList() .stream().map(Event::getPayload).collect(Collectors.joining(","))); } }) .start(); consumer.await(""); Utils.<Event>getAsync(h -> ctx.writeClient().fireEventWithOptions(evName, new EventOptions().setPayload(p1), h)); Utils.<Event>getAsync(h -> ctx.writeClient().fireEventWithOptions(randomAlphaString(10), new EventOptions().setPayload(randomAlphaString(10)), h)); Utils.<Event>getAsync(h -> ctx.writeClient().fireEventWithOptions(evName, new EventOptions().setPayload(p2), h)); consumer.await(p1); consumer.await(p1 + "," + p2); consumer.check(); watch.stop(); }
public static io.vertx.ext.consul.ConsulService fireEventWithOptions(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String name, 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.fireEventWithOptions(name, options != null ? new io.vertx.ext.consul.EventOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.Event>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.Event> 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 listEvents(io.vertx.ext.consul.ConsulService j_receiver, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
public static io.vertx.ext.consul.ConsulClient fireEventWithOptions(io.vertx.ext.consul.ConsulClient j_receiver, java.lang.String name, 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.fireEventWithOptions(name, options != null ? new io.vertx.ext.consul.EventOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.Event>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.Event> 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.ConsulClient listEvents(io.vertx.ext.consul.ConsulClient j_receiver, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Override public ConsulClient fireEventWithOptions(String name, EventOptions options, Handler<AsyncResult<Event>> resultHandler) { Query query = new Query(); if (options != null) { query.put("node", options.getNode()).put("service", options.getService()).put("tag", options.getTag()); } String body = options == null || options.getPayload() == null ? "" : options.getPayload(); requestObject(HttpMethod.PUT, "/v1/event/fire/" + urlEncode(name), query, body, resultHandler, (jsonObject, headers) -> EventParser.parse(jsonObject)); return this; }