2010/4/27  <kkoli...@apache.org>:
> Author: kkolinko
> Date: Tue Apr 27 09:01:37 2010
> New Revision: 938363
>
> URL: http://svn.apache.org/viewvc?rev=938363&view=rev
> Log:
> If the class implements both interfaces then call 
> addApplicationLifecycleListener only once.
>
> Modified:
>    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
>
> Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=938363&r1=938362&r2=938363&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java 
> (original)
> +++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Tue 
> Apr 27 09:01:37 2010
> @@ -1266,13 +1266,9 @@ public class ApplicationContext
>             match = true;
>         }
>
> -        if (t instanceof HttpSessionListener) {
> -            context.addApplicationLifecycleListener(t);
> -            match = true;
> -        }
> -
> -        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:

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.

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.


PS. I am not ready to implement this right now, but maybe somebody is.


Best regards,
Konstantin Kolinko

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

Reply via email to