Interface BackgroundEventHandler
-
public interface BackgroundEventHandler
Interface for an object that will receive SSE events fromBackgroundEventSource
.
-
-
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 anStreamHttpErrorException
if the server returns an unexpected HTTP status), but only after theConnectionErrorHandler
(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 toonError(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
returningConnectionErrorHandler.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 callingclose()
.- Throws:
java.lang.Exception
- throwing an exception here will cause it to be logged and also sent toonError(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 theevent:
line in the streammessageEvent
- aMessageEvent
object containing all the other event properties- Throws:
java.lang.Exception
- throwing an exception here will cause it to be logged and also sent toonError(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 toonError(Throwable)
-
onError
void onError(java.lang.Throwable t)
This method will be called for all exceptions that occur on the socket connection (including anStreamHttpErrorException
if the server returns an unexpected HTTP status), but only after theConnectionErrorHandler
(if any) has processed it. If you need to do anything that affects the state of the connection, useConnectionErrorHandler
.This method is not called if the error was already passed to a
ConnectionErrorHandler
which returnedConnectionErrorHandler.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
- aThrowable
object
-
-