/** * Send an event. * * <pre>{@code * sse.send(new MyObject()); * }</pre> * * <pre>{@code * sse.send(new MyObject(), "json").whenComplete((id, x) -> { * if (x == null) { * handleSuccess(); * } else { * handleError(x); * } * }); * }</pre> * * The <code>id</code> of the success callback correspond to the {@link Event#id()}. * * @param data Event data. * @return A future. The success callback contains the {@link Event#id()}. */ @Nonnull public CompletableFuture<Optional<Object>> send(final Object data) { return event(data).send(); }
/** * Send an event and set media type. * * <pre>{@code * sse.send(new MyObject(), "json"); * }</pre> * * <pre>{@code * sse.send(new MyObject(), "json").whenComplete((id, x) -> { * if (x == null) { * handleSuccess(); * } else { * handleError(x); * } * }); * }</pre> * * The <code>id</code> of the success callback correspond to the {@link Event#id()}. * * @param data Event data. * @param type Media type, like: json, xml. * @return A future. The success callback contains the {@link Event#id()}. */ @Nonnull public CompletableFuture<Optional<Object>> send(final Object data, final MediaType type) { return event(data).type(type).send(); }
/** * Send an event. * * <pre>{@code * sse.send(new MyObject()); * }</pre> * * <pre>{@code * sse.send(new MyObject(), "json").whenComplete((id, x) -> { * if (x == null) { * handleSuccess(); * } else { * handleError(x); * } * }); * }</pre> * * The <code>id</code> of the success callback correspond to the {@link Event#id()}. * * @param data Event data. * @return A future. The success callback contains the {@link Event#id()}. */ @Nonnull public CompletableFuture<Optional<Object>> send(final Object data) { return event(data).send(); }
/** * Send an event and set media type. * * <pre>{@code * sse.send(new MyObject(), "json"); * }</pre> * * <pre>{@code * sse.send(new MyObject(), "json").whenComplete((id, x) -> { * if (x == null) { * handleSuccess(); * } else { * handleError(x); * } * }); * }</pre> * * The <code>id</code> of the success callback correspond to the {@link Event#id()}. * * @param data Event data. * @param type Media type, like: json, xml. * @return A future. The success callback contains the {@link Event#id()}. */ @Nonnull public CompletableFuture<Optional<Object>> send(final Object data, final MediaType type) { return event(data).type(type).send(); }