Package com.jsgalactic.axiom.http
Class ServerSentEvent
java.lang.Object
com.jsgalactic.axiom.http.ServerSentEvent
One event of a server-sent event stream (see
Response.sse(com.jsgalactic.axiom.http.EventStreamBody)). Immutable.
An event is framed on the wire as event:, id:, retry: and one
data: line per line of the data, followed by a blank line. Line breaks are what separate fields
in this format, so the text of a field must never be able to start a new one:
- the data may contain line breaks (CR, LF or CRLF); each line is sent as its own
data:line, and the client joins them again with LF, so no input can add a field; - the event name and the id may not contain CR or LF (nor NUL, for the id), and such a value
is rejected with
IllegalArgumentExceptionrather than altered.
-
Method Summary
Modifier and TypeMethodDescriptiondata()Returns the data as given.static ServerSentEventCreates an event with data and the default event namemessage.booleaninthashCode()id()Returns the event ID.name()Returns the event name.static ServerSentEventCreates an event with a name, which clients select withaddEventListener.retry()Returns the reconnection delay.toString()Returns a copy with an event ID, which a reconnecting client returns inLast-Event-ID.Returns a copy that tells the client how long to wait before reconnecting.
-
Method Details
-
data
Creates an event with data and the default event namemessage.- Parameters:
data- text of the event; may be empty and may contain line breaks- Returns:
- the event
-
named
Creates an event with a name, which clients select withaddEventListener.- Parameters:
name- event name; not empty, without CR or LFdata- text of the event; may be empty and may contain line breaks- Returns:
- the event
- Throws:
IllegalArgumentException- if the name is empty or contains CR or LF
-
withId
Returns a copy with an event ID, which a reconnecting client returns inLast-Event-ID.- Parameters:
id- event ID; without CR, LF or NUL; empty resets the client's last ID- Returns:
- the event
- Throws:
IllegalArgumentException- if the ID contains CR, LF or NUL
-
withRetry
Returns a copy that tells the client how long to wait before reconnecting.- Parameters:
retry- reconnection delay, from one millisecond toInteger.MAX_VALUEmilliseconds- Returns:
- the event
- Throws:
IllegalArgumentException- if the delay is outside that range
-
name
Returns the event name.- Returns:
- the name, or null for the default event
-
id
Returns the event ID.- Returns:
- the ID, or null when none is sent
-
retry
Returns the reconnection delay.- Returns:
- the delay, or null when none is sent
-
data
Returns the data as given.- Returns:
- the data
-
equals
-
hashCode
public int hashCode() -
toString
-