/** * Marks the start of a query identified by the provided correlationId, with additional query type and data parameters * * @param query - Query data * @param correlationId - Identifier * @param type - allows queries to be grouped by type * @return Start event to pass to the Events systems EventBus */ public static <T> AddQuery<T> start(T query, long correlationId, String type) { return start(query, correlationId, type, null); }
/** * 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"); }
/** * Marks the start of a query identified by the provided correlationId * * @param query - Query data * @param correlationId - Identifier * @return Start event to pass to the Events systems EventBus */ public static <T> AddQuery<T> start(T query, long correlationId) { return start(query, correlationId, "default", null); }
/** * 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); } }
/** * Publish start 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 start(T query, long correlationId, EventBus bus, String... types) { for (String type : types) { AddQuery<T> next = start(query, correlationId, type, null); bus.post(next); } }
/** * 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); } }
@Test public void oneEvent() { bus.post(RequestEvents.start("data", 100l)); assertThat(requests.events(), is(1)); }