User: starksm
Date: 01/11/26 20:49:28
Modified: src/main/org/jboss/naming ENCFactory.java NamingService.java
Log:
Merge the 2.4 branch changes that allow child class loaders to access the
java:comp contexts previously created by a parent class loader. Use
a WeakHashMap to allow the class loaders to be garbage collected.
Revision Changes Path
1.6 +45 -34 jboss/src/main/org/jboss/naming/ENCFactory.java
Index: ENCFactory.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/naming/ENCFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ENCFactory.java 2001/08/03 17:15:55 1.5
+++ ENCFactory.java 2001/11/27 04:49:28 1.6
@@ -7,22 +7,21 @@
package org.jboss.naming;
import java.util.Hashtable;
-import javax.naming.*;
-import javax.naming.spi.*;
+import java.util.WeakHashMap;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
import org.jnp.server.NamingServer;
import org.jnp.interfaces.NamingContext;
/**
- * Implementation of "java:" namespace factory. The context is associated
- * with the thread, so the root context must be set before this is used in a
thread
- *
- * SA FIXME: the java: namespace should be global. the java:comp/env subcontext
should
- * be threadlocal
+ * Implementation of "java:comp" namespace factory. The context is associated
+ * with the thread class loader.
*
- * @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard Oberg</a>
- * @version $Revision: 1.5 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
+ * @version $Revision: 1.6 $
*/
public class ENCFactory
implements ObjectFactory
@@ -30,43 +29,55 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- static Hashtable encs = new Hashtable();
-
+ private static WeakHashMap encs = new WeakHashMap();
+ private static ClassLoader topLoader;
+
// Static --------------------------------------------------------
-
+ public static void setTopClassLoader(ClassLoader topLoader)
+ {
+ ENCFactory.topLoader = topLoader;
+ }
+ public static ClassLoader getTopClassLoader()
+ {
+ return ENCFactory.topLoader;
+ }
+
// Constructors --------------------------------------------------
-
+
// Public --------------------------------------------------------
// ObjectFactory implementation ----------------------------------
- public Object getObjectInstance(Object obj,
- Name name,
- Context nameCtx,
- Hashtable environment)
- throws Exception
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+ Hashtable environment)
+ throws Exception
{
synchronized (encs)
{
// Get naming for this component
- NamingServer srv =
(NamingServer)encs.get(Thread.currentThread().getContextClassLoader());
-
- // If this is the first time we see this name
- if (srv == null)
+ ClassLoader ctxClassLoader =
Thread.currentThread().getContextClassLoader();
+ Context compCtx = (Context) encs.get(ctxClassLoader);
+
+ /* If this is the first time we see ctxClassLoader first check to see
+ if a parent ClassLoader has created an ENC namespace.
+ */
+ if (compCtx == null)
{
- srv = new NamingServer();
- encs.put(Thread.currentThread().getContextClassLoader(), srv);
+ ClassLoader loader = ctxClassLoader;
+ while( loader != null && loader != topLoader && compCtx == null )
+ {
+ compCtx = (Context) encs.get(loader);
+ loader = loader.getParent();
+ }
+ // If we did not find an ENC create it
+ if( compCtx == null )
+ {
+ NamingServer srv = new NamingServer();
+ compCtx = new NamingContext(environment, null, srv);
+ encs.put(ctxClassLoader, compCtx);
+ }
}
- return new NamingContext(environment, null, srv);
+ return compCtx;
}
}
-
- // Y overrides ---------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
- // Inner classes -------------------------------------------------
}
1.20 +7 -2 jboss/src/main/org/jboss/naming/NamingService.java
Index: NamingService.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/naming/NamingService.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- NamingService.java 2001/11/26 03:19:46 1.19
+++ NamingService.java 2001/11/27 04:49:28 1.20
@@ -28,7 +28,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>.
- * @version $Revision: 1.19 $
+ * @version $Revision: 1.20 $
*
* Revisions:
* 20010622 scott.stark: Report IntialContext env for problem tracing
@@ -161,7 +161,12 @@
if( providerURL != null )
log.warn("Saw Context.PROVIDER_URL in server jndi.properties,
url="+providerURL);
- // Create "java:comp/env"
+ /* Bind an ObjectFactory to "java:comp" so that "java:comp/env" lookups
+ produce a unique context for each thread contexxt ClassLoader that
+ performs the lookup.
+ */
+ ClassLoader topLoader = Thread.currentThread().getContextClassLoader();
+ ENCFactory.setTopClassLoader(topLoader);
RefAddr refAddr = new StringRefAddr("nns", "ENC");
Reference envRef = new Reference("javax.naming.Context", refAddr,
ENCFactory.class.getName(), null);
Context ctx = (Context)iniCtx.lookup("java:");
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development