Module io.jooby
Package io.jooby

Class ServerSentMessage

java.lang.Object
io.jooby.ServerSentMessage

public class ServerSentMessage extends Object
Server-Sent message.
Since:
2.5.0
Author:
edgar
  • Constructor Details

    • ServerSentMessage

      public ServerSentMessage(@NonNull Object data)
      Creates a new message.
      Parameters:
      data - Data. Must not be null.
  • Method Details

    • getId

      @Nullable public Object getId()
      The event ID to set the EventSource object's last event ID value.
      Returns:
      The event ID to set the EventSource object's last event ID value.
    • setId

      @NonNull public ServerSentMessage setId(@Nullable Object id)
      Set The event ID to set the EventSource object's last event ID value.
      Parameters:
      id - Event ID. Converted to String.
      Returns:
      This message.
    • getEvent

      @Nullable public String getEvent()
      A string identifying the type of event described. If this is specified, an event will be dispatched on the browser to the listener for the specified event name; the website source code should use addEventListener() to listen for named events. The onmessage handler is called if no event name is specified for a message.
      Returns:
      Event type.
    • setEvent

      @NonNull public ServerSentMessage setEvent(@Nullable String event)
      Set event type.
      Parameters:
      event - Event type.
      Returns:
      This message.
    • getData

      @NonNull public Object getData()
      The data field for the message. When the EventSource receives multiple consecutive lines that begin with data:, it will concatenate them, inserting a newline character between each one. Trailing newlines are removed.
      Returns:
      Data.
    • getRetry

      @Nullable public Long getRetry()
      The reconnection time to use when attempting to send the event. This must be an integer, specifying the reconnection time in milliseconds. If a non-integer value is specified, the field is ignored.
      Returns:
      Retry option.
    • setRetry

      @NonNull public ServerSentMessage setRetry(@Nullable Long retry)
      Set retry option.
      Parameters:
      retry - Retry option.
      Returns:
      This message.
    • encode

      @NonNull public DataBuffer encode(@NonNull Context ctx)
      Encode message as event source stream format.
      Parameters:
      ctx - Web context. To encode complex objects.
      Returns:
      Encoded data.