Package org.eclipse.jetty.servlets
Class EventSourceServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.eclipse.jetty.servlets.EventSourceServlet
-
- All Implemented Interfaces:
java.io.Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public abstract class EventSourceServlet extends javax.servlet.http.HttpServlet
A servlet that implements the event source protocol, also known as "server sent events".
This servlet must be subclassed to implement abstract method
newEventSource(HttpServletRequest)
to return an instance ofEventSource
that allows application to listen for event source events and to emit event source events.This servlet supports the following configuration parameters:
heartBeatPeriod
, that specifies the heartbeat period, in seconds, used to check whether the connection has been closed by the client; defaults to 10 seconds.
NOTE: there is currently no support for
last-event-id
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
EventSourceServlet.EventSourceEmitter
-
Constructor Summary
Constructors Constructor Description EventSourceServlet()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
destroy()
protected void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
init()
protected abstract EventSource
newEventSource(javax.servlet.http.HttpServletRequest request)
protected void
open(EventSource eventSource, EventSource.Emitter emitter)
protected void
respond(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
-
-
-
Method Detail
-
init
public void init() throws javax.servlet.ServletException
- Overrides:
init
in classjavax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
-
destroy
public void destroy()
- Specified by:
destroy
in interfacejavax.servlet.Servlet
- Overrides:
destroy
in classjavax.servlet.GenericServlet
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
newEventSource
protected abstract EventSource newEventSource(javax.servlet.http.HttpServletRequest request)
-
respond
protected void respond(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
- Throws:
java.io.IOException
-
open
protected void open(EventSource eventSource, EventSource.Emitter emitter) throws java.io.IOException
- Throws:
java.io.IOException
-
-