|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.sun.grizzly.messagesbus.MessagesBus
public class MessagesBus
Servlet implementation of the Grizzly Comet Protocol (GCP). The GCP protocol is a very basic protocol that can be used by browser to share data, using the comet technique, between serveral clients without having to poll for it. The protocol is very simple. First, a client must subscribe to a topic:
http://host:port/contextPath?
subscribe=[topic name]&cometTechnique=[polling|log-polling|http-streaming]&message[text]
Mandatory: subscribe and cometTechnique.
When issuing the URL above, the connection will be automatically suspended
based on the cometTechnique specified. To share data
between application, a browser just need to send the following request:
http://host:port/contextPath?publish=[topic name]&message[text]
The Servlet can be used as it is or extended to add extra features like
filtering messages, security, login, etc.
To use this Servlet, just add in your web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<description>Grizzly Messages Bus Servlet</description>
<display-name>Grizzly Messages Bus Servlet</display-name>
<servlet>
<description>MessagesBus</description>
<servlet-name>MessagesBus</servlet-name>
<servlet-class>com.sun.grizzly.messagesbus.MessagesBus</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessagesBus</servlet-name>
<url-pattern>/mb</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>25</session-timeout>
</session-config>
</web-app>
By default, a connection will be timed out after a expirationDelay
.
The default is 30 seconds, but this can be configured by adding, in web.xml:
<init-param>
<param-name>expirationDelay</param-name>
<param-value>60000</param-value>
</init-param>
The Grizzly Comet NotificationHandler
can also be replaced by adding:
<init-param>
<param-name>notificationHandler</param-name>
<param-value>com.foo.bar.ScriptFilterNotificationHandler</param-value>
</init-param>
A request can also be automatically suspended when the request URI only
contains the publish GCP action.
<init-param>
<param-name>suspendOnTheFly</param-name>
<param-value>true</param-value>
</init-param>
Nested Class Summary | |
---|---|
static class |
MessagesBus.CometType
The Comet technique supported. |
Constructor Summary | |
---|---|
MessagesBus()
|
Method Summary | |
---|---|
protected CometContext |
createCometContext(String topic)
Create a Grizzly Comet CometContext |
protected void |
doGet(HttpServletRequest req,
HttpServletResponse res)
|
protected void |
doPost(HttpServletRequest req,
HttpServletResponse res)
Basic implementation of the Grizzly Comet Protocol (GCP). |
long |
getExpirationDelay()
Return the time a connection can stay idle. |
void |
init(ServletConfig config)
|
protected void |
push(HttpServletRequest req,
HttpServletResponse res)
Inspect the request, looking for the GCP parameters publish and message. |
void |
setExpirationDelay(long expirationDelay)
Set the maximum idle time a connection can stay suspended. |
protected MessagesBus.CometType |
suspend(HttpServletRequest req,
HttpServletResponse res)
Suspend the connection if the request contains the GCP suscribe and cometTechnique action. |
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
---|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MessagesBus()
Method Detail |
---|
public void init(ServletConfig config) throws ServletException
init
in interface Servlet
init
in class GenericServlet
ServletException
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
doGet
in class HttpServlet
ServletException
IOException
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
doPost
in class HttpServlet
req
- The requestres
- The response
ServletException
IOException
protected void push(HttpServletRequest req, HttpServletResponse res) throws IOException
req
- The http requestres
- The http response.
IOException
protected MessagesBus.CometType suspend(HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException, IOException
req
- res
-
MessagesBus.CometType
used to suspend the connection.
UnsupportedEncodingException
IOException
protected final CometContext createCometContext(String topic)
CometContext
topic
- The name of the CometContext
CometContext
public long getExpirationDelay()
public void setExpirationDelay(long expirationDelay)
expirationDelay
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |