Author: kkolinko
Date: Tue Jun 12 16:58:38 2012
New Revision: 1349439
URL: http://svn.apache.org/viewvc?rev=1349439&view=rev
Log:
Review of Context.getApplicationLifecycleListeners() calls:
Do less work if there are no listeners or 'notify' flag is false.
I do not expect much effect from this change, because implementation of
Context.getApplicationLifecycleListeners() in StandardContext is lightweight:
it returns a field value. Note that by default it returns an empty array, not
null.
Modified:
tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
tomcat/trunk/java/org/apache/catalina/session/StandardSession.java
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1349439&r1=1349438&r2=1349439&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Jun 12
16:58:38 2012
@@ -4658,7 +4658,7 @@ public class StandardContext extends Con
context.setNewServletContextListenerAllowed(false);
Object instances[] = getApplicationLifecycleListeners();
- if (instances == null)
+ if (instances == null || instances.length == 0)
return (ok);
ServletContextEvent event =
new ServletContextEvent(getServletContext());
@@ -4699,7 +4699,7 @@ public class StandardContext extends Con
boolean ok = true;
Object listeners[] = getApplicationLifecycleListeners();
- if (listeners != null) {
+ if (listeners != null && listeners.length > 0) {
ServletContextEvent event =
new ServletContextEvent(getServletContext());
for (int i = 0; i < listeners.length; i++) {
Modified: tomcat/trunk/java/org/apache/catalina/session/StandardSession.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StandardSession.java?rev=1349439&r1=1349438&r2=1349439&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/StandardSession.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/session/StandardSession.java Tue Jun
12 16:58:38 2012
@@ -402,7 +402,7 @@ public class StandardSession implements
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
Object listeners[] = context.getApplicationLifecycleListeners();
- if (listeners != null) {
+ if (listeners != null && listeners.length > 0) {
HttpSessionEvent event =
new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
@@ -770,32 +770,34 @@ public class StandardSession implements
}
}
try {
- Object listeners[] =
context.getApplicationLifecycleListeners();
- if (notify && (listeners != null)) {
- HttpSessionEvent event =
- new HttpSessionEvent(getSession());
- for (int i = 0; i < listeners.length; i++) {
- int j = (listeners.length - 1) - i;
- if (!(listeners[j] instanceof HttpSessionListener))
- continue;
- HttpSessionListener listener =
- (HttpSessionListener) listeners[j];
- try {
-
context.fireContainerEvent("beforeSessionDestroyed",
- listener);
- listener.sessionDestroyed(event);
- context.fireContainerEvent("afterSessionDestroyed",
- listener);
- } catch (Throwable t) {
- ExceptionUtils.handleThrowable(t);
+ if (notify) {
+ Object listeners[] =
context.getApplicationLifecycleListeners();
+ if (listeners != null && listeners.length > 0) {
+ HttpSessionEvent event =
+ new HttpSessionEvent(getSession());
+ for (int i = 0; i < listeners.length; i++) {
+ int j = (listeners.length - 1) - i;
+ if (!(listeners[j] instanceof HttpSessionListener))
+ continue;
+ HttpSessionListener listener =
+ (HttpSessionListener) listeners[j];
try {
- context.fireContainerEvent(
- "afterSessionDestroyed", listener);
- } catch (Exception e) {
- // Ignore
+
context.fireContainerEvent("beforeSessionDestroyed",
+ listener);
+ listener.sessionDestroyed(event);
+
context.fireContainerEvent("afterSessionDestroyed",
+ listener);
+ } catch (Throwable t) {
+ ExceptionUtils.handleThrowable(t);
+ try {
+ context.fireContainerEvent(
+ "afterSessionDestroyed", listener);
+ } catch (Exception e) {
+ // Ignore
+ }
+ manager.getContainer().getLogger().error
+
(sm.getString("standardSession.sessionEvent"), t);
}
- manager.getContainer().getLogger().error
- (sm.getString("standardSession.sessionEvent"),
t);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]