Class OutboundEvent.Builder
- java.lang.Object
-
- org.glassfish.jersey.media.sse.OutboundEvent.Builder
-
- All Implemented Interfaces:
OutboundSseEvent.Builder
- Enclosing class:
- OutboundEvent
public static class OutboundEvent.Builder extends Object implements OutboundSseEvent.Builder
Used for creatingOutboundEventinstances.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OutboundEventbuild()BuildOutboundEvent.OutboundEvent.Buildercomment(String comment)Set comment string associated with the event.OutboundEvent.Builderdata(GenericType type, Object data)Set event data and a generic java type of event data.OutboundEvent.Builderdata(Class type, Object data)Set event data and java type of event data.OutboundEvent.Builderdata(Object data)Set event data and java type of event data.OutboundEvent.Builderid(String id)Set event id.OutboundEvent.BuildermediaType(MediaType mediaType)Set themedia typeof the event data.OutboundEvent.Buildername(String name)Set event name.OutboundEvent.BuilderreconnectDelay(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.
-
-
-
Method Detail
-
name
public OutboundEvent.Builder name(String name)
Set event name.Will be send as a value of the SSE
"event"field. This field is optional.- Specified by:
namein interfaceOutboundSseEvent.Builder- Parameters:
name- event name.- Returns:
- updated builder instance.
-
id
public OutboundEvent.Builder id(String id)
Set event id.Will be send as a value of the SSE
"id"field. This field is optional.- Specified by:
idin interfaceOutboundSseEvent.Builder- Parameters:
id- event id.- Returns:
- updated builder instance.
-
reconnectDelay
public OutboundEvent.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
OutboundEventinstance is indicated bySseFeature.RECONNECT_NOT_SETvalue returned fromOutboundEvent.getReconnectDelay().- Specified by:
reconnectDelayin interfaceOutboundSseEvent.Builder- Parameters:
milliseconds- reconnection delay in milliseconds. Negative values un-set the reconnection delay.- Returns:
- updated builder instance.
- Since:
- 2.3
-
mediaType
public OutboundEvent.Builder mediaType(MediaType mediaType)
Set themedia typeof the event data.This information is mandatory. The default value is
MediaType.TEXT_PLAIN.- Specified by:
mediaTypein interfaceOutboundSseEvent.Builder- Parameters:
mediaType-MediaTypeof event data. Must not benull.- Returns:
- updated builder instance.
- Throws:
NullPointerException- in case themediaTypeparameter isnull.
-
comment
public OutboundEvent.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.
- Specified by:
commentin interfaceOutboundSseEvent.Builder- Parameters:
comment- comment string.- Returns:
- updated builder instance.
-
data
public OutboundEvent.Builder data(Class type, Object data)
Set event data and java type of event data. Type information will be used forMessageBodyWriterlookup.Note that multiple invocations of this method result in previous even data being replaced with new one.
- Specified by:
datain interfaceOutboundSseEvent.Builder- Parameters:
type- java type of supplied data. Must not benull.data- event data. Must not benull.- Returns:
- updated builder instance.
- Throws:
NullPointerException- in case eithertypeordataparameter isnull.
-
data
public OutboundEvent.Builder data(GenericType type, Object data)
Set event data and a generic java type of event data. Type information will be used forMessageBodyWriterlookup.Note that multiple invocations of this method result in previous even data being replaced with new one.
- Specified by:
datain interfaceOutboundSseEvent.Builder- Parameters:
type- generic type of supplied data. Must not benull.data- event data. Must not benull.- Returns:
- updated builder instance.
- Throws:
NullPointerException- in case eithertypeordataparameter isnull.- Since:
- 2.3
-
data
public OutboundEvent.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 asGenericEntity.Note that multiple invocations of this method result in previous even data being replaced with new one.
- Specified by:
datain interfaceOutboundSseEvent.Builder- Parameters:
data- event data. Must not benull.- Returns:
- updated builder instance.
- Throws:
NullPointerException- in case thedataparameter isnull.- Since:
- 2.3
-
build
public OutboundEvent build()
BuildOutboundEvent.There are two valid configurations:
- if a
commentis set, all other parameters are optional. If eventdataandmedia typeis set, event data will be serialized after the comment. - if a
commentis not set, at least the eventdatamust be set. All other parameters are optional.
- Specified by:
buildin interfaceOutboundSseEvent.Builder- Returns:
- new
OutboundEventinstance. - Throws:
IllegalStateException- when called with invalid configuration (neither a comment nor event data are set).
- if a
-
-