Top Description Methods
javax.ws.rs.sse

public Interface SseBroadcaster

extends AutoCloseable
Imports
java.util.concurrent.CompletionStage, java.util.function.BiConsumer, .Consumer

Server-Sent events broadcasting facility.

Server broadcaster can be used to manage multiple server sinks. It enables sending events to all registered event outputs and provides facility to effectively handle exceptions and closures of individual registered event outputs.

Instance of this interface is thread safe, meaning that it can be shared and its method invoked from different threads without causing inconsistent internal state.

Author
Marek Potociar
Since
2.1

Method Summary

Modifier and TypeMethod and Description
public CompletionStage<?>

Returns:

completion stage that completes when the event has been broadcast to all registered event sinks.
broadcast
(final OutboundSseEvent
SSE event to be published.
event
)

Publish an SSE event to all registered SseEventSink instances.

public void
close()

Redeclares java.lang.AutoCloseable.close.

Close the broadcaster and all registered SseEventSink instances.
public void
onClose(Consumer<SseEventSink>
consumer taking single parameter, a SseEventSink, which was closed.
onClose
)

Register a listener, which will be called when the SSE event output has been closed (either by client closing the connection or by calling SseEventSink#close() on the server side.

public void
onError(BiConsumer<SseEventSink, Throwable>
bi-consumer, taking two parameters: SseEventSink, which is the source of the error and the actual Throwable instance.
onError
)

Register a listener, which will be called when an exception was thrown by a given SSE event output when trying to write to it or close it.

public void
register(SseEventSink
to be registered.
sseEventSink
)

Register provided SseEventSink instance to this SseBroadcaster.

Method Detail

broadcastback to summary
public CompletionStage<?> broadcast(final OutboundSseEvent event)

Publish an SSE event to all registered SseEventSink instances.

Parameters
event:OutboundSseEvent

SSE event to be published.

Returns:CompletionStage<?>

completion stage that completes when the event has been broadcast to all registered event sinks.

closeback to summary
public void close()

Redeclares java.lang.AutoCloseable.close.

Close the broadcaster and all registered SseEventSink instances.

Any other resources associated with the SseBroadcaster should be released.

Subsequent calls have no effect and are ignored. Once the SseBroadcaster is closed, invoking any other method on the broadcaster instance would result in an IllegalStateException being thrown.

Annotations
@Override
onCloseback to summary
public void onClose(Consumer<SseEventSink> onClose)

Register a listener, which will be called when the SSE event output has been closed (either by client closing the connection or by calling SseEventSink#close() on the server side.

This operation is potentially slow, especially if large number of listeners get registered in the broadcaster. The SseBroadcaster implementation is optimized to efficiently handle small amounts of concurrent listener registrations and removals and large amounts of registered listener notifications.

Parameters
onClose:Consumer<SseEventSink>

consumer taking single parameter, a SseEventSink, which was closed.

onErrorback to summary
public void onError(BiConsumer<SseEventSink, Throwable> onError)

Register a listener, which will be called when an exception was thrown by a given SSE event output when trying to write to it or close it.

This operation is potentially slow, especially if large number of listeners get registered in the broadcaster. The SseBroadcaster implementation is optimized to efficiently handle small amounts of concurrent listener registrations and removals and large amounts of registered listener notifications.

Parameters
onError:BiConsumer<SseEventSink, Throwable>

bi-consumer, taking two parameters: SseEventSink, which is the source of the error and the actual Throwable instance.

registerback to summary
public void register(SseEventSink sseEventSink)

Register provided SseEventSink instance to this SseBroadcaster.

Parameters
sseEventSink:SseEventSink

to be registered.