Top Description Inners Fields Methods
javax.ws.rs.sse

public Interface OutboundSseEvent

extends SseEvent
Imports
java.lang.reflect.Type, javax.ws.rs.core.GenericType, .MediaType

Representation of a single outbound Server-sent event.

Used on the server side, when creating and sending an event to a client or when broadcasting.

Author
Marek Potociar
Since
2.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
OutboundSseEvent.Builder

A builder class used for creating OutboundSseEvent instances.

Field Summary

Inherited from javax.ws.rs.sse.SseEvent:
RECONNECT_NOT_SET

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

event data. May return null, if the event does not contain any data.
getData
()

Get event data.

public Type

Returns:

generic data type. May return null, if the event does not contain any data.
getGenericType
()

Get generic data type.

public MediaType

Returns:

data MediaType.
getMediaType
()

Get media type of the event data.

public Class<?>

Returns:

data type. May return null, if the event does not contain any data.
getType
()

Get data type.

Inherited from javax.ws.rs.sse.SseEvent:
getCommentgetIdgetNamegetReconnectDelayisReconnectDelaySet

Method Detail

getDataback to summary
public Object getData()

Get event data.

The event data, if specified, are serialized and sent as one or more SSE event "data" fields (depending on the line breaks in the actual serialized data content). The data are serialized using an available javax.ws.rs.ext.MessageBodyWriter that is selected based on the event type, getGenericType() generic type} and getMediaType() media type}.

Returns:Object

event data. May return null, if the event does not contain any data.

getGenericTypeback to summary
public Type getGenericType()

Get generic data type.

This information is used to select a proper javax.ws.rs.ext.MessageBodyWriter to be used for serializing the event data.

Returns:Type

generic data type. May return null, if the event does not contain any data.

getMediaTypeback to summary
public MediaType getMediaType()

Get media type of the event data.

This information is used to a select proper javax.ws.rs.ext.MessageBodyWriter to be used for serializing the event data.

Returns:MediaType

data MediaType.

getTypeback to summary
public Class<?> getType()

Get data type.

This information is used to select a proper javax.ws.rs.ext.MessageBodyWriter to be used for serializing the event data.

Returns:Class<?>

data type. May return null, if the event does not contain any data.

javax.ws.rs.sse back to summary

public Interface OutboundSseEvent.Builder


A builder class used for creating OutboundSseEvent instances.

Method Summary

Modifier and TypeMethod and Description
public OutboundSseEvent

Returns:

new OutboundSseEvent instance.
build
()

Build OutboundSseEvent.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
comment
(String
comment string.
comment
)

Set comment string associated with the event.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
data
(Class<T>
java type of supplied data. Must not be null.
type
,
Object
event data. Must not be null.
data
)

Set event data and java type of event data.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
data
(GenericType<T>
generic type of supplied data. Must not be null.
type
,
Object
event data. Must not be null.
data
)

Set event data and a generic java type of event data.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
data
(Object
event data. Must not be null.
data
)

Set event data and java type of event data.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
id
(String
event id.
id
)

Set the event id.

Will be send as a value of the SSE "id" field.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
mediaType
(final MediaType
MediaType of event data. Must not be null.
mediaType
)

Set the media type of the event data.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
name
(String
event name.
name
)

Set event name.

public OutboundSseEvent.Builder

Returns:

updated builder instance.
reconnectDelay
(long
reconnection delay in milliseconds. Negative values un-set the reconnection delay.
milliseconds
)

Set reconnection delay (in milliseconds) that indicates how long the event receiver should wait before attempting to reconnect in case a connection to SSE event source is lost.

Method Detail

buildback to summary
public OutboundSseEvent build()

Build OutboundSseEvent.

There are two valid configurations:

  • if a comment is set, all other parameters are optional. If event data and media type is set, event data will be serialized after the comment.
  • if a comment is not set, at least the event data must be set. All other parameters are optional.
Returns:OutboundSseEvent

new OutboundSseEvent instance.

Exceptions
IllegalStateException:
when called with invalid configuration (neither a comment nor event data are set).
commentback to summary
public OutboundSseEvent.Builder comment(String comment)

Set comment string associated with the event.

The comment will be serialized with the event, before event data are serialized. If the event does not contain any data, a separate "event" that contains only the comment will be sent. This information is optional, provided the event data are set.

Note that multiple invocations of this method result in a previous comment being replaced with a new one. To achieve multi-line comments, a multi-line comment string has to be used.

Parameters
comment:String

comment string.

Returns:OutboundSseEvent.Builder

updated builder instance.

databack to summary
public OutboundSseEvent.Builder data(Class<T> type, Object data)

Set event data and java type of event data.

Type information will be used for javax.ws.rs.ext.MessageBodyWriter lookup.

Note that multiple invocations of this method result in previous even data being replaced with new one.

Parameters
type:Class<T>

java type of supplied data. Must not be null.

data:Object

event data. Must not be null.

Returns:OutboundSseEvent.Builder

updated builder instance.

Exceptions
NullPointerException:
in case either type or data parameter is null.
databack to summary
public OutboundSseEvent.Builder data(GenericType<T> type, Object data)

Set event data and a generic java type of event data.

Type information will be used for javax.ws.rs.ext.MessageBodyWriter lookup.

Note that multiple invocations of this method result in previous even data being replaced with new one.

Parameters
type:GenericType<T>

generic type of supplied data. Must not be null.

data:Object

event data. Must not be null.

Returns:OutboundSseEvent.Builder

updated builder instance.

Exceptions
NullPointerException:
in case either type or data parameter is null.
databack to summary
public OutboundSseEvent.Builder data(Object data)

Set event data and java type of event data.

This is a convenience method that derives the event data type information from the runtime type of the event data. The supplied event data may be represented as javax.ws.rs.core.GenericEntity.

Note that multiple invocations of this method result in previous even data being replaced with new one.

Parameters
data:Object

event data. Must not be null.

Returns:OutboundSseEvent.Builder

updated builder instance.

Exceptions
NullPointerException:
in case the data parameter is null.
idback to summary
public OutboundSseEvent.Builder id(String id)

Set the event id.

Will be send as a value of the SSE "id" field. This field is optional.

Parameters
id:String

event id.

Returns:OutboundSseEvent.Builder

updated builder instance.

mediaTypeback to summary
public OutboundSseEvent.Builder mediaType(final MediaType mediaType)

Set the media type of the event data.

This information is mandatory. The default value is MediaType#TEXT_PLAIN.

Parameters
mediaType:MediaType

MediaType of event data. Must not be null.

Returns:OutboundSseEvent.Builder

updated builder instance.

Exceptions
NullPointerException:
in case the mediaType parameter is null.
nameback to summary
public OutboundSseEvent.Builder name(String name)

Set event name.

Will be send as a value of the SSE "event" field. This field is optional.

Parameters
name:String

event name.

Returns:OutboundSseEvent.Builder

updated builder instance.

reconnectDelayback to summary
public OutboundSseEvent.Builder reconnectDelay(long milliseconds)

Set reconnection delay (in milliseconds) that indicates how long the event receiver should wait before attempting to reconnect in case a connection to SSE event source is lost.

Will be send as a value of the SSE "retry" field. This field is optional.

Absence of a value of this field in an OutboundSseEvent instance is indicated by SseEvent#RECONNECT_NOT_SET value returned from getReconnectDelay().

Parameters
milliseconds:long

reconnection delay in milliseconds. Negative values un-set the reconnection delay.

Returns:OutboundSseEvent.Builder

updated builder instance.