public interface EventHandler
Modifier and Type | Method and Description |
---|---|
void |
onClosed()
EventSource 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
UnsuccessfulResponseException 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.
|
void onOpen() throws java.lang.Exception
java.lang.Exception
- throwing an exception here will cause it to be logged and also sent to onError(Throwable)
void onClosed() throws java.lang.Exception
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()
. This issue was fixed in the 2.3.1 release, but has not
been backported to the 1.x support branch.
java.lang.Exception
- throwing an exception here will cause it to be logged and also sent to onError(Throwable)
void onMessage(java.lang.String event, MessageEvent messageEvent) throws java.lang.Exception
event
- the event name, from the event:
line in the streammessageEvent
- a MessageEvent
object containing all the other event propertiesjava.lang.Exception
- throwing an exception here will cause it to be logged and also sent to onError(Throwable)
void onComment(java.lang.String comment) throws java.lang.Exception
comment
- the comment linejava.lang.Exception
- throwing an exception here will cause it to be logged and also sent to onError(Throwable)
void onError(java.lang.Throwable t)
UnsuccessfulResponseException
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.
t
- a Throwable
object