EventSourceServlet.EventSourceEmitter
public static interface EventSource.Emitter
EventSource.Emitter
is the active half of an event source connection, and allows applications
to operate on the connection by sending events, data or comments, or by closing the connection.
An EventSource.Emitter
instance will be created for each new event source connection.
EventSource.Emitter
instances are fully thread safe and can be used from multiple threads.
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
Closes this event source connection.
|
void |
comment(java.lang.String comment) |
Sends a comment to the client.
|
void |
data(java.lang.String data) |
Sends a default event with data to the client.
|
void |
event(java.lang.String name,
java.lang.String data) |
Sends a named event with data to the client.
|
void event(java.lang.String name, java.lang.String data) throws java.io.IOException
Sends a named event with data to the client.
When invoked as: event("foo", "bar")
, the client will receive the lines:
event: foo data: bar
name
- the event namedata
- the data to be sentjava.io.IOException
- if an I/O failure occurreddata(String)
void data(java.lang.String data) throws java.io.IOException
Sends a default event with data to the client.
When invoked as: data("baz")
, the client will receive the line:
data: baz
When invoked as: data("foo\r\nbar\rbaz\nbax")
, the client will receive the lines:
data: foo data: bar data: baz data: bax
data
- the data to be sentjava.io.IOException
- if an I/O failure occurredvoid comment(java.lang.String comment) throws java.io.IOException
Sends a comment to the client.
When invoked as: comment("foo")
, the client will receive the line:
: foo
comment
- the comment to sendjava.io.IOException
- if an I/O failure occurredvoid close()
Closes this event source connection.
Copyright © 1995–2017 Webtide. All rights reserved.