Top Description Inners Fields Constructors Methods
org.springframework.http.codec

public final Class ServerSentEvent<T>

extends Object
Class Inheritance
Type Parameters
<T>
the type of data that this event contains
Imports
java.time.Duration, org.springframework.lang.Nullable

Representation for a Server-Sent Event for use with Spring's reactive Web support. Flux<ServerSentEvent> or Observable<ServerSentEvent> is the reactive equivalent to Spring MVC's SseEmitter.
Authors
Sebastien Deleuze, Arjen Poutsma
Since
5.0
See Also
ServerSentEventHttpMessageWriter, Server-Sent Events W3C recommendation

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ServerSentEvent.Builder<
the type of data that this event contains
T
>

A mutable builder for a SseEvent.

private static class

Field Summary

Modifier and TypeField and Description
private final String
private final T
private final String
private final String
private final Duration

Constructor Summary

AccessConstructor and Description
private
ServerSentEvent(String id, String event, Duration retry, String comment, T data)

Method Summary

Modifier and TypeMethod and Description
public static <
the type of data that this event contains
T
>
ServerSentEvent.Builder<T>

Returns:

the builder
builder
()

Return a builder for a SseEvent.

public static <
the type of data that this event contains
T
>
ServerSentEvent.Builder<T>

Returns:

the builder
builder
(T data)

Return a builder for a SseEvent, populated with the given data.

public String
comment()

Return the comment of this event, if available.

public T
data()

Return the data field of this event, if available.

public String
event()

Return the event field of this event, if available.

public String
id()

Return the id field of this event, if available.

public Duration
retry()

Return the retry field of this event, if available.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

commentback to summary
private final String comment
Annotations
@Nullable
databack to summary
private final T data
Annotations
@Nullable
eventback to summary
private final String event
Annotations
@Nullable
idback to summary
private final String id
Annotations
@Nullable
retryback to summary
private final Duration retry
Annotations
@Nullable

Constructor Detail

ServerSentEventback to summary
private ServerSentEvent(String id, String event, Duration retry, String comment, T data)

Method Detail

builderback to summary
public static <T> ServerSentEvent.Builder<T> builder()

Return a builder for a SseEvent.

Parameters
<T>
the type of data that this event contains
Returns:ServerSentEvent.Builder<T>

the builder

builderback to summary
public static <T> ServerSentEvent.Builder<T> builder(T data)

Return a builder for a SseEvent, populated with the given data.

Parameters
<T>
the type of data that this event contains
Returns:ServerSentEvent.Builder<T>

the builder

commentback to summary
public String comment()

Return the comment of this event, if available.

Annotations
@Nullable
databack to summary
public T data()

Return the data field of this event, if available.

Annotations
@Nullable
eventback to summary
public String event()

Return the event field of this event, if available.

Annotations
@Nullable
idback to summary
public String id()

Return the id field of this event, if available.

Annotations
@Nullable
retryback to summary
public Duration retry()

Return the retry field of this event, if available.

Annotations
@Nullable
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.springframework.http.codec back to summary

public Interface ServerSentEvent.Builder<T>

Known Direct Implementers
org.springframework.http.codec.ServerSentEvent.BuilderImpl
Type Parameters
<T>
the type of data that this event contains

A mutable builder for a SseEvent.

Method Summary

Modifier and TypeMethod and Description
public ServerSentEvent<T>

Returns:

the built event
build
()

Builds the event.

public ServerSentEvent.Builder<T>

Returns:

this builder
comment
(String
the comment to set
comment
)

Set SSE comment.

public ServerSentEvent.Builder<T>

Returns:

this builder
data
(T
the value of the data field
data
)

Set the value of the data field.

public ServerSentEvent.Builder<T>

Returns:

this builder
event
(String
the value of the event field
event
)

Set the value of the event field.

public ServerSentEvent.Builder<T>

Returns:

this builder
id
(String
the value of the id field
id
)

Set the value of the id field.

public ServerSentEvent.Builder<T>

Returns:

this builder
retry
(Duration
the value of the retry field
retry
)

Set the value of the retry field.

Method Detail

buildback to summary
public ServerSentEvent<T> build()

Builds the event.

Returns:ServerSentEvent<T>

the built event

commentback to summary
public ServerSentEvent.Builder<T> comment(String comment)

Set SSE comment. If a multi-line comment is provided, it will be turned into multiple SSE comment lines as defined in Server-Sent Events W3C recommendation.

Parameters
comment:String

the comment to set

Returns:ServerSentEvent.Builder<T>

this builder

databack to summary
public ServerSentEvent.Builder<T> data(T data)

Set the value of the data field. If the data argument is a multi-line String, it will be turned into multiple data field lines as defined in the Server-Sent Events W3C recommendation. If data is not a String, it will be encoded into JSON.

Parameters
data:T

the value of the data field

Returns:ServerSentEvent.Builder<T>

this builder

eventback to summary
public ServerSentEvent.Builder<T> event(String event)

Set the value of the event field.

Parameters
event:String

the value of the event field

Returns:ServerSentEvent.Builder<T>

this builder

idback to summary
public ServerSentEvent.Builder<T> id(String id)

Set the value of the id field.

Parameters
id:String

the value of the id field

Returns:ServerSentEvent.Builder<T>

this builder

retryback to summary
public ServerSentEvent.Builder<T> retry(Duration retry)

Set the value of the retry field.

Parameters
retry:Duration

the value of the retry field

Returns:ServerSentEvent.Builder<T>

this builder

org.springframework.http.codec back to summary

private Class ServerSentEvent.BuilderImpl<T>

extends Object
implements ServerSentEvent.Builder<T>
Class Inheritance
All Implemented Interfaces
org.springframework.http.codec.ServerSentEvent.Builder

Field Summary

Modifier and TypeField and Description
private String
private T
private String
private String
private Duration

Constructor Summary

AccessConstructor and Description
public
public
BuilderImpl(T data)

Method Summary

Modifier and TypeMethod and Description
public ServerSentEvent<T>
public ServerSentEvent.Builder<T>
comment(String
the comment to set
comment
)

Implements org.springframework.http.codec.ServerSentEvent.Builder.comment.

Set SSE comment.
public ServerSentEvent.Builder<T>
data(T
the value of the data field
data
)

Implements org.springframework.http.codec.ServerSentEvent.Builder.data.

Set the value of the data field.
public ServerSentEvent.Builder<T>
event(String
the value of the event field
event
)

Implements org.springframework.http.codec.ServerSentEvent.Builder.event.

Set the value of the event field.
public ServerSentEvent.Builder<T>
id(String
the value of the id field
id
)

Implements org.springframework.http.codec.ServerSentEvent.Builder.id.

Set the value of the id field.
public ServerSentEvent.Builder<T>
retry(Duration
the value of the retry field
retry
)

Implements org.springframework.http.codec.ServerSentEvent.Builder.retry.

Set the value of the retry field.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

commentback to summary
private String comment
Annotations
@Nullable
databack to summary
private T data
Annotations
@Nullable
eventback to summary
private String event
Annotations
@Nullable
idback to summary
private String id
Annotations
@Nullable
retryback to summary
private Duration retry
Annotations
@Nullable

Constructor Detail

BuilderImplback to summary
public BuilderImpl()
BuilderImplback to summary
public BuilderImpl(T data)

Method Detail

buildback to summary
public ServerSentEvent<T> build()

Implements org.springframework.http.codec.ServerSentEvent.Builder.build.

Doc from org.springframework.http.codec.ServerSentEvent.Builder.build.

Builds the event.

Returns:ServerSentEvent<T>

the built event

Annotations
@Override
commentback to summary
public ServerSentEvent.Builder<T> comment(String comment)

Implements org.springframework.http.codec.ServerSentEvent.Builder.comment.

Doc from org.springframework.http.codec.ServerSentEvent.Builder.comment.

Set SSE comment. If a multi-line comment is provided, it will be turned into multiple SSE comment lines as defined in Server-Sent Events W3C recommendation.

Parameters
comment:String

the comment to set

Returns:ServerSentEvent.Builder<T>

this builder

Annotations
@Override
databack to summary
public ServerSentEvent.Builder<T> data(T data)

Implements org.springframework.http.codec.ServerSentEvent.Builder.data.

Doc from org.springframework.http.codec.ServerSentEvent.Builder.data.

Set the value of the data field. If the data argument is a multi-line String, it will be turned into multiple data field lines as defined in the Server-Sent Events W3C recommendation. If data is not a String, it will be encoded into JSON.

Parameters
data:T

the value of the data field

Returns:ServerSentEvent.Builder<T>

this builder

Annotations
@Override
eventback to summary
public ServerSentEvent.Builder<T> event(String event)

Implements org.springframework.http.codec.ServerSentEvent.Builder.event.

Doc from org.springframework.http.codec.ServerSentEvent.Builder.event.

Set the value of the event field.

Parameters
event:String

the value of the event field

Returns:ServerSentEvent.Builder<T>

this builder

Annotations
@Override
idback to summary
public ServerSentEvent.Builder<T> id(String id)

Implements org.springframework.http.codec.ServerSentEvent.Builder.id.

Doc from org.springframework.http.codec.ServerSentEvent.Builder.id.

Set the value of the id field.

Parameters
id:String

the value of the id field

Returns:ServerSentEvent.Builder<T>

this builder

Annotations
@Override
retryback to summary
public ServerSentEvent.Builder<T> retry(Duration retry)

Implements org.springframework.http.codec.ServerSentEvent.Builder.retry.

Doc from org.springframework.http.codec.ServerSentEvent.Builder.retry.

Set the value of the retry field.

Parameters
retry:Duration

the value of the retry field

Returns:ServerSentEvent.Builder<T>

this builder

Annotations
@Override