This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Configure Tomcat to run both Comet Pushlets and regular servlet simultaneously Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Configure Tomcat to run both Comet Pushlets and regular servlet simultaneously" Watch "Configure Tomcat to run both Comet Pushlets and regular servlet simultaneously" New topic
Author

Configure Tomcat to run both Comet Pushlets and regular servlet simultaneously

Frank Hilhorst
Greenhorn

Joined: Aug 17, 2011
Posts: 6


Guys,

I have written a conventional servlet application.
Now I want to add a new servlet that supports COMET long polling.

In researching this I found that I would have to use the following connector to support COMET pushlets.

<Connector connectionTimeout="20000" port="8080" protocol="org.apache.
coyote.http11.Http11NioProtocol" redirectPort="8443"/>

I want however that single TOMCAT installation can support both the conventional servlet requests as well as the long polling requests.

Can somebody tell me how to configure Tomcat so that it can handle both types of requests.
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 491
    
    5
Comet support and events are activated for a servlet only if it implements org.apache.catalina.CometProcessor. Otherwise, its normal servlet doGet/doPost service methods are invoked.
Frank Hilhorst
Greenhorn

Joined: Aug 17, 2011
Posts: 6


This sounds like it doesn't matter which connector you use.
I read that Comet requires non blocking sockets (in other words use the NIO connector).
Which connector should I use?
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 491
    
    5
Frank Hilhorst wrote:
This sounds like it doesn't matter which connector you use.
I read that Comet requires non blocking sockets (in other words use the NIO connector).
Which connector should I use?


You have to use HTTP NIO connector (edit: or APR connector, but I haven't tried that out) , because the blocking nature of regular HTTP connector makes Comet functionality impossible.

NIO connector - like all asynchronous designs - is capable of both asynchronous and synchronous operation. Generally, it's impossible to make a synchronous flow asynchronous, but it's possible to make any asynchronous flow behave synchronously. If you open tomcat source code, you'll find StandardValve and HttpNioConnector full of code like "if (comet) {...} else {...}". So, NIO connector is a superset of blocking connector.

If servlet doesn't implement CometProcessor, it's treated as a regular servlet and the flow is like old synchronous servlet.
If it does implement, it's treated as an asynchronous comet pushlet.

Tomcat Comet Reference
Frank Hilhorst
Greenhorn

Joined: Aug 17, 2011
Posts: 6


Thanks Kathik,

This information is exactly what I was looking for.
 
wood burning stoves
 
subject: Configure Tomcat to run both Comet Pushlets and regular servlet simultaneously
 
Similar Threads
How to detect unused/Inactive sessions from code and remove it
How to enable APR or NIO connectors on tomcat 6 / windows
help Comet Tomcat
Http Long polling
Send data to front end when back end update