« Zurück zu 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>
  <servlet-name>Comet Poller Servlet</servlet-name>
  <servlet-class>com.liferay.support.tomcat.longpoll.comet.CatalinaCometProcessor</servlet-class>
  <init-param>
    <param-name>cometHandlerImpl</param-name>
    <param-value>com.liferay.portal.poller.PollerCometHandler</param-value>  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>Comet Poller Servlet</servlet-name>
  <url-pattern>/poller/*</url-pattern>
</servlet-mapping>

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 Anhänge
26640 Angesehen
Durchschnitt (2 Stimmen)
Die durchschnittliche Bewertung ist 4.0 von max. 5 Sternen.
Kommentare
Antworten im Thread Autor Datum
Great to know this new feature.Thanks. Sohui Gu 12. Dezember 2011 04:40
I've managed to get tomcat running the nio... Kirk Stork 11. Mai 2012 17:38

Great to know this new feature.Thanks.
Gepostet am 12.12.11 04:40.
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)

etc

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"
Gepostet am 11.05.12 17:38.