Interface BackgroundEventHandler


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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void onClosed()
      BackgroundEventSource calls this method when the stream connection has been closed.
      void onComment​(java.lang.String comment)
      EventSource calls this method when it has received a comment line from the stream (any line starting with a colon).
      void onError​(java.lang.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.
      void onMessage​(java.lang.String event, MessageEvent messageEvent)
      EventSource calls this method when it has received a new event from the stream.
      void onOpen()
      EventSource calls this method when the stream connection has been opened.
    • Method Detail

      • onOpen

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

        void onClosed()
               throws java.lang.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:
        java.lang.Exception - throwing an exception here will cause it to be logged and also sent to onError(Throwable)
      • onMessage

        void onMessage​(java.lang.String event,
                       MessageEvent messageEvent)
                throws java.lang.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:
        java.lang.Exception - throwing an exception here will cause it to be logged and also sent to onError(Throwable)
      • onComment

        void onComment​(java.lang.String comment)
                throws java.lang.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:
        java.lang.Exception - throwing an exception here will cause it to be logged and also sent to onError(Throwable)
      • onError

        void onError​(java.lang.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