Interface BackgroundEventHandler
public interface BackgroundEventHandler
Interface for an object that will receive SSE events from
BackgroundEventSource.-
Method Summary
Modifier and TypeMethodDescriptionvoidonClosed()BackgroundEventSource calls this method when the stream connection has been closed.voidEventSource calls this method when it has received a comment line from the stream (any line starting with a colon).voidThis method will be called for all exceptions that occur on the socket connection (including anStreamHttpErrorExceptionif the server returns an unexpected HTTP status), but only after theConnectionErrorHandler(if any) has processed it.voidonMessage(String event, MessageEvent messageEvent) EventSource calls this method when it has received a new event from the stream.voidonOpen()EventSource calls this method when the stream connection has been opened.
-
Method Details
-
onOpen
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 toonError(Throwable)
-
onClosed
BackgroundEventSource calls this method when the stream connection has been closed.This method is not called if the connection was closed due to a
ConnectionErrorHandlerreturningConnectionErrorHandler.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:
Exception- throwing an exception here will cause it to be logged and also sent toonError(Throwable)
-
onMessage
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- aMessageEventobject containing all the other event properties- Throws:
Exception- throwing an exception here will cause it to be logged and also sent toonError(Throwable)
-
onComment
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 toonError(Throwable)
-
onError
This method will be called for all exceptions that occur on the socket connection (including anStreamHttpErrorExceptionif 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
ConnectionErrorHandlerwhich 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- aThrowableobject
-