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.Builderbuilder()Acquires an "empty" builder forServerSentEventinstances.static ServerSentEventAcquires a reference to the shared "heartbeat" event.getData()Thedatapayload for this Server-Sent Event.getEvent()Theeventvalue for this Server-Sent Event.getId()Theidfor this Server-Sent Event, used by clients to populate theLast-Event-IDrequest header should a reconnect occur.getRetry()Theretryduration for this Server-Sent Event.Is this instance the shared "heartbeat" event (as provided viaforHeartbeat())?toString()static ServerSentEvent.BuilderAcquires a builder forServerSentEventinstances, seeded with adatavalue.static ServerSentEvent.BuilderAcquires a builder forServerSentEventinstances, seeded with aneventvalue.
-
Method Details
-
forHeartbeat
Acquires a reference to the shared "heartbeat" event.- Returns:
- the shared "heartbeat" event
-
withEvent
Acquires a builder forServerSentEventinstances, seeded with aneventvalue.- Parameters:
event- theeventvalue for the instance- Returns:
- the builder
-
withData
Acquires a builder forServerSentEventinstances, seeded with adatavalue.- Parameters:
data- thedatavalue for the instance- Returns:
- the builder
-
builder
Acquires an "empty" builder forServerSentEventinstances.- Returns:
- the builder
-
toString
-
isHeartbeat
Is this instance the shared "heartbeat" event (as provided viaforHeartbeat())?- Returns:
trueif this instance is the shared "heartbeat" event,falseotherwise
-
getId
Theidfor this Server-Sent Event, used by clients to populate theLast-Event-IDrequest 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
idfor this Server-Sent Event
-
getEvent
Theeventvalue 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
eventvalue for this Server-Sent Event
-
getData
Thedatapayload 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
datapayload for this Server-Sent Event
-
getRetry
Theretryduration 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
retryduration for this Server-Sent Event
-