/** * Marks the end of a query identified by the provided correlationId * * @param query - Query data * @param correlationId - Identifier * @return Finish event to pass to the Events systems EventBus */ public static <T> RemoveQuery<T> finish(T query, long correlationId) { return finish(query, correlationId, "default"); }
/** * Publish finish events for each of the specified query types * * <pre> * {@code * RequestEvents.start("get", 1l, bus, "typeA", "custom"); try { return "ok"; } finally { RequestEvents.finish("get", 1l, bus, "typeA", "custom"); } * * } * </pre> * * * @param query Completed query * @param correlationId Identifier * @param bus EventBus to post events to * @param types Query types to post to event bus */ public static <T> void finish(T query, long correlationId, EventBus bus, String... types) { for (String type : types) { RemoveQuery<T> next = finish(query, correlationId, type); bus.post(next); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try { return "ok"; } finally { bus.post(RequestEvents.finish("get", 1l)); } }
@GET @Produces("text/plain") @Path("/ping-custom") public String pingCustom() { bus.post(RequestEvents.start("get", 1l, "custom")); try { return "ok"; } finally { bus.post(RequestEvents.finish("get", 1l, "custom")); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { RequestEvents.start("get", 1l, bus, "typeA", "custom"); try { return "ok"; } finally { RequestEvents.finish("get", 1l, bus, "typeA", "custom"); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try{ return "ok"; }finally{ bus.post(RequestEvents.finish("get",1l)); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try { return "ok"; } finally { bus.post(RequestEvents.finish("get", 1l)); } }
@GET @Produces("text/plain") @Path("/ping-custom") public String pingCustom() { RequestEvents.start("get", 1l, bus, "typeA", "custom"); try { return "ok"; } finally { RequestEvents.finish("get", 1l, bus, "typeA", "custom"); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try{ return "ok"; }finally{ bus.post(RequestEvents.finish("get",1l)); } }
@Test public void twoEventsOneFinished() { bus.post(RequestEvents.start("data", 100l)); bus.post(RequestEvents.start("data", 120l)); bus.post(RequestEvents.finish("data", 120l)); assertThat(requests.events(), is(2)); assertThat(requests.size(), is(1)); }
@Test public void testToString() { bus.post(RequestEvents.start("data", 100l)); bus.post(RequestEvents.start("data", 120l)); bus.post(RequestEvents.finish("data", 120l)); System.out.println(requests.toString()); assertThat(requests.toString(), containsString("\"removed\":1")); assertThat(requests.toString(), containsString("\"added\":2")); }
@Test public void twoEventsDifferentTypesOneFinishedDefaultTypeIsIgnored() { requests = new RequestsBeingExecuted( bus, "typeA"); types.getMap() .put("typeA", requests); bus.post(RequestEvents.start("data", 130l)); bus.post(RequestEvents.start("data", 120l, "typeA", "data2")); bus.post(RequestEvents.finish("data", 120l, "typeA")); assertThat(requests.events(), is(1)); assertThat(requests.size(), is(0)); }
/** * Marks the end of a query identified by the provided correlationId * * @param query - Query data * @param correlationId - Identifier * @return Finish event to pass to the Events systems EventBus */ public static <T> RemoveQuery<T> finish(T query, long correlationId) { return finish(query, correlationId, "default"); }
/** * Publish finish events for each of the specified query types * * <pre> * {@code * RequestEvents.start("get", 1l, bus, "typeA", "custom"); try { return "ok"; } finally { RequestEvents.finish("get", 1l, bus, "typeA", "custom"); } * * } * </pre> * * * @param query Completed query * @param correlationId Identifier * @param bus EventBus to post events to * @param types Query types to post to event bus */ public static <T> void finish(T query, long correlationId, EventBus bus, String... types) { for (String type : types) { RemoveQuery<T> next = finish(query, correlationId, type); bus.post(next); } }