Top Description Methods
javax.ws.rs.sse

public Interface SseEventSink

extends AutoCloseable
Imports
java.util.concurrent.CompletionStage

Outbound Server-Sent Events stream.

The instance of SseEventSink can be only acquired by injection of a resource method parameter:

@GET
@Path("eventStream")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void eventStream(@Context SseEventSink eventSink) {
    // ...
}
The injected instance is then considered as a return type, so the resource method doesn't return anything, similarly as in server-side async processing.

The underlying client connection is kept open and the application code is able to send events. A server-side instance implementing the interface corresponds exactly to a single client HTTP connection.

The injected instance is thread safe.

Author
Marek Potociar (marek.potociar at oracle.com)
Since
2.1

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares java.lang.AutoCloseable.close.

Close the SseEventSink instance and release all associated resources.
public boolean

Returns:

true when closed, false otherwise.
isClosed
()

Check if the stream has been closed already.

public CompletionStage<?>

Returns:

completion stage that completes when the event has been sent. If there is a problem during sending of an event, completion stage will be completed exceptionally.
send
(OutboundSseEvent
event to be written.
event
)

Send an outbound Server-sent event to this sink.

Method Detail

closeback to summary
public void close()

Redeclares java.lang.AutoCloseable.close.

Close the SseEventSink instance and release all associated resources.

Subsequent calls have no effect and are ignored. Once the SseEventSink is closed, invoking any method other than this one and isClosed() would result in an IllegalStateException being thrown.

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Check if the stream has been closed already.

Please note that the client connection represented by this SseServerSink can be closed by the client side when a client decides to close connection and disconnect from the server.

Returns:boolean

true when closed, false otherwise.

sendback to summary
public CompletionStage<?> send(OutboundSseEvent event)

Send an outbound Server-sent event to this sink.

Event will be serialized and sent to the client.

Parameters
event:OutboundSseEvent

event to be written.

Returns:CompletionStage<?>

completion stage that completes when the event has been sent. If there is a problem during sending of an event, completion stage will be completed exceptionally.