Author: remy.maucherat(a)jboss.com
Date: 2011-08-24 11:13:51 -0400 (Wed, 24 Aug 2011)
New Revision: 1829
Added:
trunk/java/org/apache/catalina/ThreadBindingListener.java
Modified:
trunk/java/org/apache/catalina/Context.java
trunk/java/org/apache/catalina/core/StandardContext.java
trunk/java/org/apache/catalina/core/StandardHostValve.java
trunk/webapps/docs/changelog.xml
Log:
- Add a dedicated API for thread binding, to improve on the NamingValve.
Modified: trunk/java/org/apache/catalina/Context.java
===================================================================
--- trunk/java/org/apache/catalina/Context.java 2011-08-23 16:02:41 UTC (rev 1828)
+++ trunk/java/org/apache/catalina/Context.java 2011-08-24 15:13:51 UTC (rev 1829)
@@ -1102,6 +1102,18 @@
*/
public boolean isInitialized();
+
+ /**
+ * Get the associated ThreadBindingListener.
+ */
+ public ThreadBindingListener getThreadBindingListener();
+
+ /**
+ * Get the associated ThreadBindingListener.
+ */
+ public void setThreadBindingListener(ThreadBindingListener threadBindingListener);
+
+
}
Added: trunk/java/org/apache/catalina/ThreadBindingListener.java
===================================================================
--- trunk/java/org/apache/catalina/ThreadBindingListener.java (rev
0)
+++ trunk/java/org/apache/catalina/ThreadBindingListener.java 2011-08-24 15:13:51 UTC (rev
1829)
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina;
+
+
+/**
+ * Callback for establishing naming association when entering the application
+ * scope. This corresponds to setting the context classloader.
+ */
+
+public interface ThreadBindingListener {
+
+
+ public void bind();
+ public void unbind();
+
+
+}
Modified: trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContext.java 2011-08-23 16:02:41 UTC (rev
1828)
+++ trunk/java/org/apache/catalina/core/StandardContext.java 2011-08-24 15:13:51 UTC (rev
1829)
@@ -74,6 +74,7 @@
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Loader;
import org.apache.catalina.Manager;
+import org.apache.catalina.ThreadBindingListener;
import org.apache.catalina.Wrapper;
import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.deploy.ErrorPage;
@@ -642,6 +643,13 @@
protected String j2EEServer="none";
+ protected static final ThreadBindingListener DEFAULT_NAMING_LISTENER = (new
ThreadBindingListener() {
+ public void bind() {}
+ public void unbind() {}
+ });
+ protected ThreadBindingListener threadBindingListener = DEFAULT_NAMING_LISTENER;
+
+
// ----------------------------------------------------- Context Properties
@@ -1645,6 +1653,22 @@
}
+ /**
+ * Get the associated ThreadBindingListener.
+ */
+ public ThreadBindingListener getThreadBindingListener() {
+ return threadBindingListener;
+ }
+
+
+ /**
+ * Get the associated ThreadBindingListener.
+ */
+ public void setThreadBindingListener(ThreadBindingListener threadBindingListener) {
+ this.threadBindingListener = threadBindingListener;
+ }
+
+
// ------------------------------------------------------ Public Properties
@@ -4197,14 +4221,12 @@
ClassLoader oldContextClassLoader =
Thread.currentThread().getContextClassLoader();
- if (getResources() == null)
- return oldContextClassLoader;
-
if ((getLoader() != null) && getLoader().getClassLoader() != null) {
Thread.currentThread().setContextClassLoader
(getLoader().getClassLoader());
}
+ threadBindingListener.bind();
lifecycle.fireLifecycleEvent(BIND_THREAD_EVENT, null);
return oldContextClassLoader;
@@ -4218,6 +4240,7 @@
protected void unbindThread(ClassLoader oldContextClassLoader) {
lifecycle.fireLifecycleEvent(UNBIND_THREAD_EVENT, null);
+ threadBindingListener.unbind();
Thread.currentThread().setContextClassLoader(oldContextClassLoader);
Modified: trunk/java/org/apache/catalina/core/StandardHostValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardHostValve.java 2011-08-23 16:02:41 UTC
(rev 1828)
+++ trunk/java/org/apache/catalina/core/StandardHostValve.java 2011-08-24 15:13:51 UTC
(rev 1829)
@@ -122,6 +122,7 @@
if (context.getLoader() != null) {
Thread.currentThread().setContextClassLoader(context.getLoader().getClassLoader());
}
+ context.getThreadBindingListener().bind();
// Enter application scope
Object instances[] = context.getApplicationEventListeners();
@@ -191,6 +192,7 @@
}
}
+ context.getThreadBindingListener().unbind();
// Restore the context classloader
Thread.currentThread().setContextClassLoader(StandardHostValve.class.getClassLoader());
@@ -226,6 +228,7 @@
if (context.getLoader() != null) {
Thread.currentThread().setContextClassLoader(context.getLoader().getClassLoader());
}
+ context.getThreadBindingListener().bind();
// Enter application scope
Object instances[] = context.getApplicationEventListeners();
@@ -307,6 +310,7 @@
}
}
+ context.getThreadBindingListener().unbind();
// Restore the context classloader
Thread.currentThread().setContextClassLoader(StandardHostValve.class.getClassLoader());
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2011-08-23 16:02:41 UTC (rev 1828)
+++ trunk/webapps/docs/changelog.xml 2011-08-24 15:13:51 UTC (rev 1829)
@@ -16,6 +16,16 @@
<body>
+<section name="JBoss Web 7.0.2.Final (remm)">
+ <subsection name="Catalina">
+ <changelog>
+ <update>
+ Add a dedicated API for thread binding purposes. (remm)
+ </update>
+ </changelog>
+ </subsection>
+</section>
+
<section name="JBoss Web 7.0.1.Final (remm)">
<subsection name="Catalina">
<changelog>