• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configure Tomcat to run both Comet Pushlets and regular servlet simultaneously

 
Frank Hilhorst
Greenhorn
Posts: 6
Java jQuery Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Bartender
Pie
Posts: 1052
24
Android C++ Java Linux PHP Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Java jQuery Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Bartender
Pie
Posts: 1052
24
Android C++ Java Linux PHP Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Java jQuery Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Kathik,

This information is exactly what I was looking for.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic