public interface SseBroadcaster extends AutoCloseable
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.
Modifier and Type | Method and Description |
---|---|
CompletionStage<?> |
broadcast(OutboundSseEvent event)
Publish an SSE event to all registered
SseEventSink instances. |
void |
close()
Close the broadcaster and all registered
SseEventSink instances. |
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. |
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.
|
void |
register(SseEventSink sseEventSink)
Register provided
SseEventSink instance to this SseBroadcaster . |
void onError(BiConsumer<SseEventSink,Throwable> onError)
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.
onError
- bi-consumer, taking two parameters: SseEventSink
, which is the source of the
error and the actual Throwable
instance.void onClose(Consumer<SseEventSink> onClose)
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.
onClose
- consumer taking single parameter, a SseEventSink
, which was closed.void register(SseEventSink sseEventSink)
SseEventSink
instance to this SseBroadcaster
.sseEventSink
- to be registered.CompletionStage<?> broadcast(OutboundSseEvent event)
SseEventSink
instances.event
- SSE event to be published.void close()
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.
close
in interface AutoCloseable
Copyright © 2019 Eclipse Foundation.
Use is subject to license terms.