On 27/04/2010 05:19, Konstantin Kolinko wrote:
- if (t instanceof ServletContextListener) {
- // TODO SERVLET3 - also need to check caller? spec isn't clear
+ if (t instanceof HttpSessionListener
+ || t instanceof ServletContextListener) {
+ // TODO SERVLET3 - if ServletContextListener then also need to
check caller? spec isn't clear
context.addApplicationLifecycleListener(t);
match = true;
}
Regarding the "TODO SERVLET3" comment in the above fragment:
Reading the first few sentences at the beginning of Chapter 4.4,
( "These methods can only be called during the initialization of the
application either
from the contexInitialized method of a ServletContextListener
implementation or from the onStartup method of a
ServletContainerInitializer implementation." )
it looks that it is a state check:
That wasn't how I read it. My reading, and hence the TODO, comment was
does the spec mean that calls to this method can only be made from:
- ServletContextListener#contexInitialized()
- ServletContainerInitializer#onStartup()
and we should be checking the call stack to confirm that is the case.
Such a test wouldn't be practical and I don't see what purpose it would
serve. As such, I don't think that is what was meant but as I was
reading the spec I found the language was unclear so I added the TODO. I
think it can be safely removed at this point.
a) Before we start calling ServletContextListener.contextInitialized()
any listeners allowed in addListener() can be added.
b) Once we started calling
ServletContextListener.contextInitialized(), a new
ServletContextListener cannot be added anymore.
Ah. I think this might be the correct interpretation of the text Pid is
referring to in https://issues.apache.org/bugzilla/show_bug.cgi?id=49181
c) Once contextInitialized() calls are done, no more listeners,
servlets, filters can be added programmatically.
Implementing this as a call chain check as the comment suggests, thus
using try+catch+check stack, seems too costly and impractical.
+1.
PS. I am not ready to implement this right now, but maybe somebody is.
Me neither, but I'll add some more commentary to 49181.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org