Interface BackgroundEventHandler


public interface BackgroundEventHandler
Interface for an object that will receive SSE events from BackgroundEventSource.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    BackgroundEventSource calls this method when the stream connection has been closed.
    void
    onComment(String comment)
    EventSource calls this method when it has received a comment line from the stream (any line starting with a colon).
    void
    This method will be called for all exceptions that occur on the socket connection (including an StreamHttpErrorException if the server returns an unexpected HTTP status), but only after the ConnectionErrorHandler (if any) has processed it.
    void
    onMessage(String event, MessageEvent messageEvent)
    EventSource calls this method when it has received a new event from the stream.
    void
    EventSource calls this method when the stream connection has been opened.
  • Method Details

    • onOpen

      void onOpen() throws Exception
      EventSource calls this method when the stream connection has been opened.
      Throws:
      Exception - throwing an exception here will cause it to be logged and also sent to onError(Throwable)
    • onClosed

      void onClosed() throws Exception
      BackgroundEventSource calls this method when the stream connection has been closed.

      This method is not called if the connection was closed due to a ConnectionErrorHandler returning ConnectionErrorHandler.Action.SHUTDOWN; EventSource assumes that if you registered such a handler and made it return that value, then you already know that the connection is being closed.

      There is a known issue where onClosed() may or may not be called if the stream has been permanently closed by calling close().

      Throws:
      Exception - throwing an exception here will cause it to be logged and also sent to onError(Throwable)
    • onMessage

      void onMessage(String event, MessageEvent messageEvent) throws Exception
      EventSource calls this method when it has received a new event from the stream.
      Parameters:
      event - the event name, from the event: line in the stream
      messageEvent - a MessageEvent object containing all the other event properties
      Throws:
      Exception - throwing an exception here will cause it to be logged and also sent to onError(Throwable)
    • onComment

      void onComment(String comment) throws Exception
      EventSource calls this method when it has received a comment line from the stream (any line starting with a colon).
      Parameters:
      comment - the comment line
      Throws:
      Exception - throwing an exception here will cause it to be logged and also sent to onError(Throwable)
    • onError

      void onError(Throwable t)
      This method will be called for all exceptions that occur on the socket connection (including an StreamHttpErrorException if the server returns an unexpected HTTP status), but only after the ConnectionErrorHandler (if any) has processed it. If you need to do anything that affects the state of the connection, use ConnectionErrorHandler.

      This method is not called if the error was already passed to a ConnectionErrorHandler which returned ConnectionErrorHandler.Action.SHUTDOWN; EventSource assumes that if you registered such a handler and made it return that value, then you do not want to handle the same error twice.

      Parameters:
      t - a Throwable object