Package org.eclipse.jetty.servlets
Class EventSourceServlet.EventSourceEmitter
- java.lang.Object
-
- org.eclipse.jetty.servlets.EventSourceServlet.EventSourceEmitter
-
- All Implemented Interfaces:
java.lang.Runnable
,EventSource.Emitter
- Enclosing class:
- EventSourceServlet
protected class EventSourceServlet.EventSourceEmitter extends java.lang.Object implements EventSource.Emitter, java.lang.Runnable
-
-
Constructor Summary
Constructors Constructor Description EventSourceEmitter(EventSource eventSource, javax.servlet.AsyncContext async)
-
Method Summary
All Methods Instance Methods Concrete Methods 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.protected void
flush()
void
run()
-
-
-
Constructor Detail
-
EventSourceEmitter
public EventSourceEmitter(EventSource eventSource, javax.servlet.AsyncContext async) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
event
public void event(java.lang.String name, java.lang.String data) throws java.io.IOException
Description copied from interface:EventSource.Emitter
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
- Specified by:
event
in interfaceEventSource.Emitter
- Parameters:
name
- the event namedata
- the data to be sent- Throws:
java.io.IOException
- if an I/O failure occurred- See Also:
EventSource.Emitter.data(String)
-
data
public void data(java.lang.String data) throws java.io.IOException
Description copied from interface:EventSource.Emitter
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
- Specified by:
data
in interfaceEventSource.Emitter
- Parameters:
data
- the data to be sent- Throws:
java.io.IOException
- if an I/O failure occurred
-
comment
public void comment(java.lang.String comment) throws java.io.IOException
Description copied from interface:EventSource.Emitter
Sends a comment to the client.
When invoked as:
comment("foo")
, the client will receive the line:: foo
- Specified by:
comment
in interfaceEventSource.Emitter
- Parameters:
comment
- the comment to send- Throws:
java.io.IOException
- if an I/O failure occurred
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
flush
protected void flush() throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close()
Description copied from interface:EventSource.Emitter
Closes this event source connection.
- Specified by:
close
in interfaceEventSource.Emitter
-
-