Class Sse.Events

java.lang.Object
com.codename1.backend.Sse.Events
Enclosing class:
Sse

public static final class Sse.Events extends Object
The open stream. event, id and retry set fields of the NEXT event, which data(String), json(Object) or send() then writes and flushes.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    A comment line, which every client ignores.
    void
    data(String data)
    Sends one event with this data.
    event(String name)
    Names the next event; a client listens for it with addEventListener(name, ...).
    id(String eventId)
    The id of the next event, which the client sends back as Last-Event-ID when it reconnects.
    void
    json(Object value)
    Sends one event whose data is value as JSON, encoded straight into the buffer.
    The Last-Event-ID the client reconnected with, or null on a first connection.
    void
    Keeps an idle stream open through proxies; the client sees nothing.
    retry(long millis)
    How long the client waits before reconnecting, sent with the next event.
    void
    Sends the pending event/id/retry fields with no data.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • lastEventId

      public String lastEventId()
      The Last-Event-ID the client reconnected with, or null on a first connection. Resume after it.
    • event

      public Sse.Events event(String name)
      Names the next event; a client listens for it with addEventListener(name, ...). Unnamed events are message.
    • id

      public Sse.Events id(String eventId)
      The id of the next event, which the client sends back as Last-Event-ID when it reconnects.
    • retry

      public Sse.Events retry(long millis)
      How long the client waits before reconnecting, sent with the next event.
    • data

      public void data(String data) throws IOException
      Sends one event with this data. Each line of a multi-line value becomes its own data: field, which the client joins back with \n.
      Throws:
      IOException
    • json

      public void json(Object value) throws IOException
      Sends one event whose data is value as JSON, encoded straight into the buffer. JSON has no raw line breaks, so it is always one line.
      Throws:
      IOException
    • send

      public void send() throws IOException
      Sends the pending event/id/retry fields with no data. A browser dispatches nothing for it, but records the id and the retry.
      Throws:
      IOException
    • comment

      public void comment(String text) throws IOException
      A comment line, which every client ignores.
      Throws:
      IOException
    • ping

      public void ping() throws IOException
      Keeps an idle stream open through proxies; the client sees nothing.
      Throws:
      IOException