Hi this post is a follow up from
http://issues.apache.org/bugzilla/show_bug.cgi?id=42198 where this post does
not belong.

I want to find out if my understanding of the comet api in tomcat is right
concerning how connections are handled and event are triggered. I have a
very simple test webapp which streams a couple of messages to a browser via
XHR. The pseudo code of the comet servlet looks looks like this:

switch (event)
case BEGIN:
  start worker thread which will post messages up the response and call
event.close when finished
 
case END:
case ERROR:
  signal worker thread that it must stop sending messages

case READ:
throw IOException // expect that ERROR is triggered

Now when opening the streaming connection I can specify if the connection
should be kept alive or closed after the request has finished. This done be
setting the response header "Connection: close".

When using a Keep-Alive connection there is no instant END event triggered
when event.close() is called. Thats because the connection itself is not
closed. After a while when the keep alive connection times out the client
will release it and the END event will be triggered.

When not using Keep Alive the end event is triggered instantly after the
event.close() method is called. The response has been committed at this time
and will be recycled after this method call.

The problem is that the comet event object is in two different states
although the same method has been called.

On one hand, when the underlying objects have been recycled a call to
method.close() yields a NullPointerException and on the other hand, when the
response has been closed but the connection is still there an asynch process
can continue to write to the response stream without being notified that
it's writing nowhere.

In my opinion in should be the other way round:

I don't think that a event.close() call should throw a NPE when the event is
already closed. But I would rather catch an exception when I am writing to
response object that has been closed.

Maybe I am getting something wrong, but I think that the api should rather
reflect a request model, where the end event is triggered when the response
is closed. Now it seems that it more reflects the connection model. I am
sure that one can live with it as it is though.

Or maybe I'm just wrong?

Cheers, Daniel

-- 
View this message in context: 
http://www.nabble.com/comet-events-and-connections-tf3647567.html#a10187852
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to