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 of EventSource
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
.
Modifier and Type | Class | Description |
---|---|---|
protected class |
EventSourceServlet.EventSourceEmitter |
Constructor | Description |
---|---|
EventSourceServlet() |
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) |
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
public void init() throws javax.servlet.ServletException
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void destroy()
destroy
in class javax.servlet.GenericServlet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
protected abstract EventSource newEventSource(javax.servlet.http.HttpServletRequest request)
protected void respond(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
java.io.IOException
protected void open(EventSource eventSource, EventSource.Emitter emitter) throws java.io.IOException
java.io.IOException
Copyright © 1995–2017 Webtide. All rights reserved.