tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: Comet API
Date Sat, 01 Oct 2011 11:04:39 GMT
2011/10/1 Konstantin Kolinko <knst.kolinko@gmail.com>:
> Hi!
>
> I was reading the Comet API documentation, that is "aio.html" in the
> docs and Javadoc of catalina.comet.* classes.
>
> Here are several notes.
>

Answering several of my notes below.

>
> CometEvent.java:
> ===============
> - #setTimeout():
>  a) @param timeout says it is positive value.
>
> With recent Mark's fixes to timeout handling it also accepts "-1" as
> the infinite timeout. It works great with Nio.
> (I'll add setting -1 timeout to ChatServlet.).
>
> With Http11AprProtocol you cannot set timeout: the method throws
> java.lang.UnsupportedOperationException.
>
> I think the value of "0" shall still be undocumented (I do not know
> what it will do and it does not seem to be useful), so just "-1" can
> be added.
>
> b) Javadoc here says:
>    "The
>     web application SHOULD NOT attempt to reuse the request and
> response objects after a timeout
>     as the <code>error(HttpServletRequest,
> HttpServletResponse)</code> method indicates."
>
> It contradicts with description of EventSubType TIMEOUT here and in
> aio.html, that says that this event is not fatal and
> "the connection will not be closed unless the servlet uses the close
> method of the event".
>
> c) I am not sure whether setTimeout() can be called in READ event. The
> Javadoc here says just that it cannot be called outside of events
> ("asynchronously"), but aio.html explicitly mentions that BEGIN event
> should be used to call setTimeout().
>
> d) In "Comet timeouts" section in aio.html it is said that the default
> timeout for "soTimeout" for Nio and "soTimeout*50" for Apr. I have not
> looked where it is actually set in the code,  but in HTTP Connector
> documentation there is not attribute "soTimeout"
>
> - #close():
> a) "The servlet should perform any needed cleanup as if it had
> received an END or ERROR event."
>
> Does it need to perform the cleanup?
>
> The description of EventType.READ event here and in aio.html also
> mentions to perform cleanup before calling cose().
>
> From description of SESSION_END subtype of END event my understanding
> would be that
> it would receive it (maybe unless it was called in END or ERROR
> events) and could cleanup there.
>
> So, what SESSION_END is for?
>
> - (Javadoc for EventType, EventSubType has no <p>,<br> and thus will
> be unreadable.)
> - (In SESSION_END do s/session/Comet session/ and do the same
> replacement in aio.html, to avoid ambiguity).
>
> CometProcessor
> ================
> a) ("When this interface is implemented, the service method of the servlet will
>  never be called".
>
> -Actually the service() method will be called - It is called if the
> connector does not support Comet,
> as ChatServlet example shows. The same applies to CometFilter as well
> ).
>
> aio.html
> ==========
> a) Is CometEvent object available only as an argument of the event() method?
>
> Can it be stored by cometprocessor between the events that it receives?
> Or only HttpServletResponse and HttpServletRequest can be stored and
> reused between events?
>
> Thus, can a servlet call the CometEvent.close() method while it is
> between events?
>
> b) Can CometProcessor#event() be called for several events for the same
> request&response pair at the same time? I guess that it cannot happen.
>
> c) It is said "At any time, the servlet may end processing of the
> request by using the close method of the event object."
>
> Nothing is said about such methods of Servlet API as
> OutputStream.close(), InputStream.close().
> I guess they should result in receiving an END event, and in the END
> event the sevlet will call CometEvent.close() to stop Comet
> processing.
>
> d) It is good to know that many Response methods will throw
> IllegalStateException as aio.html clearly says that the response is
> committed after BEGIN event.
>
> What if we never called flush() on the output stream? Is it still "committed"?
>
> If it is committed only "after BEGIN event",
> can the servlet or filter call response.sendError() while it is in BEGIN event?
>
> e) If a Connector is stopped, will it be SERVER_SHUTDOWN subtype of END event.
> Though I think that during shutdown maybe WEBAPP_RELOAD will come first?
> Will the event come if connector is stopped through JMX?
> When a web application is stopped will it be WEBAPP_RELOAD?
>
> Can these events come asynchronously with regards to other
> BEGIN/READ/END/ERROR events for the same request&response pair?
>

1. CometEventImpl is 1:1 associated with o.a.c.connector.Request.

It is created by Request.getEvent()

2. CometEventImpl is passed further as is.

There is no recyclable facade around it.

3. WEBAPP_RELOAD subtype of END event is created by CometConnectionManagerValve.
It is fired on BEFORE_STOP_EVENT.
4. CometConnectionManagerValve.keeps list of all Request objects that
are using comet (in this webapp), as well as keeps sublists of it in
HttpSessions (in this webapp).
5. WEBAPP_RELOAD subtype of END event is fired asynchronously, without
any relation to request processing that might be at the same time for
the same Request.

Because it reuses CometEventImpl instance, there easily can be a race
condition if another thread tries to send READ event using the same
event instance at the same time.
I am not sure whether processing of incoming requests is already
stopped when BEFORE_STOP_EVENT. is processed.

6. After firing WEBAPP_RELOAD, CometConnectionManagerValve explicitly
calls event.close().

7. SESSION_END event is also fired by CometConnectionManagerValve  and
only by this valve.
8. The same caveats of asynchronous firing as for WEBAPP_RELOAD before.
Also here there is certainly no guarantee that there is no request
processing at the same time in another thread.
9. The same caveat of event.close() called explicitly.
10. This event is sent directly to the servlet.  It does not pass
through the usual chain of valves and cannot be handled by another
valves or CometFilter filters.
11. It is HttpSession end, not Comet session end that I thought it is.
12. I do not see where this feature is mentioned: In aio.html it is
not written that invalidation of a session causes closing of other
Comet requests.
13. There is no mention of CometConnectionManagerValve in config/valve.html
14. Need to mention in aio.html what subevent types require this
valve. (Those are WEBAPP_RELOAD and SESSION_END).


15. SERVER_SHUTDOWN event is fired by CoyoteAdapter when Connector is
being stopped.

I am not sure whether other requests can be processed at the same
time, but at least things here look much better than with
CometConnectionManagerValve above.

Searching for SocketStatus.STOP, I see that
AprEndpoint fires it in its #closePollset() and #destroy() for
pollsset and add queue respectively, but I am not sure what happens
for the requests that are currently processing a READ event.

NioEndpoint - I am not sure there. SocketStatus.STOP is fired in its
#processKey() and its #processSendfile(), and processKey() is called
from timeout() and from run().

Apparently Poller.run() can exit on if(close) without calling
processKey() and thus without firing this event.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message