Class ServerSentEvent
For example:
ServerSentEvent event = ServerSentEvent.withEvent("example")
.data("""
{
"testing": 123,
"value": "abc"
}
""")
.id(UUID.randomUUID().toString())
.retry(Duration.ofSeconds(5))
.build();
Threadsafe instances can be acquired via these builder factory methods:
withEvent(String)(builder primed with an event value)withData(String)(builder primed with a data value)withDefaults()("empty" builder suitable for constructing special cases likeretry-only orid-only events.)
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 final classBuilder used to construct instances ofServerSentEventviawithEvent(String),withData(String), orwithDefaults(). -
Method Summary
Modifier and TypeMethodDescriptiongetData()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.toString()static ServerSentEvent.BuilderAcquires a builder forServerSentEventinstances, seeded with adatavalue.static ServerSentEvent.BuilderAcquires an "empty" builder forServerSentEventinstances, useful for creating special cases likeretry-only orid-only events.static ServerSentEvent.BuilderAcquires a builder forServerSentEventinstances, seeded with aneventvalue.
-
Method Details
-
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
-
withDefaults
Acquires an "empty" builder forServerSentEventinstances, useful for creating special cases likeretry-only orid-only events.- Returns:
- the builder
-
toString
-
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
-