public interface SseBroadcaster extends AutoCloseable, Flow.Publisher<OutboundSseEvent>
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.
| Modifier and Type | Method and Description |
|---|---|
void |
broadcast(OutboundSseEvent event)
Publish an SSE event to all subscribed
SseEventSink instances. |
void |
close()
Close all subscribed
SseEventSink instances. |
void |
onClose(Consumer<Flow.Subscriber<? super OutboundSseEvent>> 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
Closeable.close() on the server side. |
void |
onException(BiConsumer<Flow.Subscriber<? super OutboundSseEvent>,Exception> onException)
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 |
subscribe(Flow.Subscriber<? super OutboundSseEvent> subscriber)
Subscribe
OutboundSseEvent subscriber (i.e. |
void onException(BiConsumer<Flow.Subscriber<? super OutboundSseEvent>,Exception> onException)
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.
onException - bi-consumer, taking two parameters: SseEventSink, which is the source of the
exception and the actual Exception.void onClose(Consumer<Flow.Subscriber<? super OutboundSseEvent>> onClose)
Closeable.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 subscribe(Flow.Subscriber<? super OutboundSseEvent> subscriber)
subscribe in interface Flow.Publisher<OutboundSseEvent>subscriber - Subscriber<OutboundSseEvent> to register.void broadcast(OutboundSseEvent event)
SseEventSink instances.event - SSE event to be published.void close()
SseEventSink instances.close in interface AutoCloseableCopyright © 1996-2017, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.