« Back to Configuring

Comet Integration

Background on Comet #

Comet, or long polling, is a mechanism that allows server-to-client communication. It is designed to avoid the performance and scalability shortcomings of standard polling. However, comet implementations can vary greatly. In Liferay 6.1 an API was introduced to help write portable comet code.

There are 2 major components to the system. First is the Liferay integration with the Comet implementation of choice. Currently Liferay 6.1 has integration with the Tomcat Comet implementation. This integration handles connection management and delivery/sending of data from/to a user. This component communicates with the business logic via the CometHandler interface.

For every comet connection, a new CometHandler instance is cloned from a prototype and initialized with a CometSession object. The CometHandler will then receive data from the comet connection and eventually be destroyed, either by the client, Liferay, or by the business logic.

Along with a CometHandler, the business logic is given a CometSession object which wraps a CometRequest/CometResponse pair. These two classes function in much the same way as the ServletRequest and ServletResponse objects in the standard servlet spec. CometRequest includes various data that identifies the connection. The CometResponse is used to deliver data to the user.

Using the Tomcat CometProcessor #

Enabling the Tomcat Comet implementation conists of 2 steps:

  1. Configuring the Tomcat NIO connector. The Tomcat CometProcessor must use the NIO connector. Otherwise performance and scalability issues could arise. See the Tomcat documentation here
  2. Adding the entries to the Liferay webapp web.xml:
  <servlet-name>Comet Poller Servlet</servlet-name>
    <param-value>com.liferay.portal.poller.PollerCometHandler</param-value>  </init-param>

  <servlet-name>Comet Poller Servlet</servlet-name>

Note the cometHandlerImpl parameter. This parameter is used to tell the CatalinaCometProcessor what CometHandler implementation is to be used for this CometProcessor. The PollerCometHandler was written to be functionally similar to the PollerServlet. The only liferay feature that currently uses Poller is the Chat portlet. While the chat portlet can use comet, the engineering team is still working on other improvements to allow it to take advantage of comet.

0 Attachments
Average (1 Vote)
The average rating is 3.0 stars out of 5.
Threaded Replies Author Date
Great to know this new feature.Thanks. Sohui Gu December 12, 2011 4:40 AM
I've managed to get tomcat running the nio... Kirk Stork May 11, 2012 5:38 PM

Great to know this new feature.Thanks.
Posted on 12/12/11 4:40 AM.
I've managed to get tomcat running the nio connector

May 12, 2012 12:18:56 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8081"]

and URLs of the form /poller/...
seem to be acknowledged as legitimate URLs. I.e., you can brows to them and not get a page error.

But the chat portlet still seems to be using the regular polling mechanism.

POST http://localhost:8081/poller/send
200 OK 12ms everyt...3174000 (line 1)


Must something be done to the chat portlet to make it stop polling and start simply receiving from the portlet?

For example, I'm sometimes seeing this scroll by...

"NetworkError: 404 Not Found - http://localhost:8081/poller/receive"
Posted on 5/11/12 5:38 PM.