Class ServerSentEvent
For example:
ServerSentEvent serverSentEvent = ServerSentEvent.withEvent("example")
.data("""
{
"testing": 123,
"value": "abc"
}
""")
.id(UUID.randomUUID().toString())
.retry(Duration.ofSeconds(5))
.build();
To acquire an event suitable for heartbeats, use the forHeartbeat()
factory method.
See https://www.soklet.com/docs/server-sent-events for detailed documentation.
Formal specification is available at https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
-
Method Summary
Modifier and TypeMethodDescriptionstatic ServerSentEvent.Builder
builder()
Acquires an "empty" builder forServerSentEvent
instances.static ServerSentEvent
Acquires a reference to the shared "heartbeat" event.getData()
Thedata
payload for this Server-Sent Event.getEvent()
Theevent
value for this Server-Sent Event.getId()
Theid
for this Server-Sent Event, used by clients to populate theLast-Event-ID
request header should a reconnect occur.getRetry()
Theretry
duration for this Server-Sent Event.Is this instance the shared "heartbeat" event (as provided viaforHeartbeat()
)?toString()
static ServerSentEvent.Builder
Acquires a builder forServerSentEvent
instances, seeded with adata
value.static ServerSentEvent.Builder
Acquires a builder forServerSentEvent
instances, seeded with anevent
value.
-
Method Details
-
forHeartbeat
Acquires a reference to the shared "heartbeat" event.- Returns:
- the shared "heartbeat" event
-
withEvent
Acquires a builder forServerSentEvent
instances, seeded with anevent
value.- Parameters:
event
- theevent
value for the instance- Returns:
- the builder
-
withData
Acquires a builder forServerSentEvent
instances, seeded with adata
value.- Parameters:
data
- thedata
value for the instance- Returns:
- the builder
-
builder
Acquires an "empty" builder forServerSentEvent
instances.- Returns:
- the builder
-
toString
-
isHeartbeat
Is this instance the shared "heartbeat" event (as provided viaforHeartbeat()
)?- Returns:
true
if this instance is the shared "heartbeat" event,false
otherwise
-
getId
Theid
for this Server-Sent Event, used by clients to populate theLast-Event-ID
request header should a reconnect occur.Formal specification is available at https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.
- Returns:
- the optional
id
for this Server-Sent Event
-
getEvent
Theevent
value for this Server-Sent Event.Formal specification is available at https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.
- Returns:
- the optional
event
value for this Server-Sent Event
-
getData
Thedata
payload for this Server-Sent Event.Formal specification is available at https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.
- Returns:
- the optional
data
payload for this Server-Sent Event
-
getRetry
Theretry
duration for this Server-Sent Event.Formal specification is available at https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.
- Returns:
- the optional
retry
duration for this Server-Sent Event
-