[jboss-cvs] JBossAS SVN: r76103 - in projects/naming/trunk/jnpserver/src/main/java/org: jnp/server and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 22 10:44:29 EDT 2008


Author: alesj
Date: 2008-07-22 10:44:29 -0400 (Tue, 22 Jul 2008)
New Revision: 76103

Modified:
   projects/naming/trunk/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java
   projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java
   projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingServer.java
Log:
[JBNAME-4]; changing the store table type to concurrent hash map.
Adding util methods to allow override of actual NamingServer impl.

Modified: projects/naming/trunk/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java	2008-07-22 14:13:00 UTC (rev 76102)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jboss/naming/ENCFactory.java	2008-07-22 14:44:29 UTC (rev 76103)
@@ -21,20 +21,19 @@
 */
 package org.jboss.naming;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.WeakHashMap;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
-import java.security.PrivilegedAction;
-import java.security.AccessController;
 import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.NamingException;
 import javax.naming.spi.ObjectFactory;
 
+import org.jnp.interfaces.NamingContext;
 import org.jnp.server.NamingServer;
-import org.jnp.interfaces.NamingContext;
 
 /**
  *   Implementation of "java:comp" namespace factory. The context is associated
@@ -82,6 +81,7 @@
    }
 
    // Static --------------------------------------------------------
+   
    public static void setTopClassLoader(ClassLoader topLoader)
    {
       ENCFactory.topLoader = topLoader;
@@ -91,12 +91,6 @@
       return ENCFactory.topLoader;
    }
 
-
-
-
-   // Constructors --------------------------------------------------
-
-
    // Public --------------------------------------------------------
 
    // ObjectFactory implementation ----------------------------------
@@ -144,13 +138,22 @@
       }
    }
 
+   /**
+    * Util method for possible override.
+    *
+    * @return new naming server instance
+    * @throws NamingException for any error
+    */
+   protected NamingServer createServer() throws NamingException
+   {
+      return new NamingServer();
+   }
+
    protected Context createContext(Hashtable environment)
            throws NamingException
    {
-      Context compCtx;
-      NamingServer srv = new NamingServer();
-      compCtx = new NamingContext(environment, null, srv);
-      return compCtx;
+      NamingServer srv = createServer();
+      return new NamingContext(environment, null, srv);
    }
 
    private static class GetTCLAction implements PrivilegedAction
@@ -158,13 +161,11 @@
       static PrivilegedAction ACTION = new GetTCLAction();
       public Object run()
       {
-         ClassLoader loader = Thread.currentThread().getContextClassLoader();
-         return loader;
+         return Thread.currentThread().getContextClassLoader();
       }
       static ClassLoader getContextClassLoader()
       {
-         ClassLoader loader = (ClassLoader) AccessController.doPrivileged(ACTION);
-         return loader;
+         return (ClassLoader) AccessController.doPrivileged(ACTION);
       }
    }
 
@@ -187,8 +188,7 @@
       }
       ClassLoader getParent()
       {
-         ClassLoader parent = (ClassLoader) AccessController.doPrivileged(this);
-         return parent;
+         return (ClassLoader) AccessController.doPrivileged(this);
       }
    }
 }

Modified: projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java	2008-07-22 14:13:00 UTC (rev 76102)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java	2008-07-22 14:44:29 UTC (rev 76103)
@@ -89,6 +89,17 @@
       this.UseGlobalService = flag;
    }
 
+   /**
+    * Util method for possible override.
+    *
+    * @return new naming instance
+    * @throws Exception for any error
+    */
+   protected Naming createServer() throws Exception
+   {
+      return new NamingServer();
+   }
+   
    public void start()
       throws Exception
    {
@@ -100,7 +111,7 @@
             theServer = NamingContext.localServer;
          // If not, or there is no server create one
          if( theServer == null )
-            theServer = new NamingServer();
+            theServer = createServer();
          else
          {
             // We need to wrap the server to allow exporting it
@@ -149,11 +160,9 @@
       ctx.rebind("comp", envRef);
       ctx.close();
       iniCtx.close();
-
    }
 
    public void stop()
    {
    }
-
 }

Modified: projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingServer.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingServer.java	2008-07-22 14:13:00 UTC (rev 76102)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingServer.java	2008-07-22 14:44:29 UTC (rev 76103)
@@ -22,10 +22,10 @@
 package org.jnp.server;
 
 import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Vector;
+import java.util.concurrent.ConcurrentHashMap;
 import javax.naming.Binding;
 import javax.naming.CannotProceedException;
 import javax.naming.Context;
@@ -39,10 +39,10 @@
 import javax.naming.Reference;
 import javax.naming.spi.ResolveResult;
 
+import org.jboss.logging.Logger;
 import org.jnp.interfaces.Naming;
 import org.jnp.interfaces.NamingContext;
 import org.jnp.interfaces.NamingParser;
-import org.jboss.logging.Logger;
 
 /**
  * The JNDI naming server implementation class.
@@ -63,7 +63,7 @@
 
    // Attributes ----------------------------------------------------
    
-   protected Hashtable table = new Hashtable();
+   protected Map table = createTable();
    protected Name prefix;
    protected NamingParser parser = new NamingParser();
    protected NamingServer parent;
@@ -71,6 +71,7 @@
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
+
    public NamingServer()
       throws NamingException
    {
@@ -80,12 +81,32 @@
    public NamingServer(Name prefix, NamingServer parent)
       throws NamingException
    {
-      if (prefix == null) prefix = parser.parse("");
-      this.prefix = prefix;
-      
+      if (prefix == null)
+         prefix = parser.parse("");
+      this.prefix = prefix;      
       this.parent = parent;
    }
-   
+
+   // Protected -----------------------------------------------------
+
+   protected Map createTable()
+   {
+      return new ConcurrentHashMap();  
+   }
+
+   /**
+    * Create sub naming.
+    *
+    * @param prefix the prefix
+    * @param parent the parent naming server
+    * @return new sub instance
+    * @throws NamingException for any error
+    */
+   protected NamingServer createNamingServer(Name prefix, NamingServer parent) throws NamingException
+   {
+      return new NamingServer(prefix, parent);
+   }
+
    // Public --------------------------------------------------------
 
    // Naming implementation -----------------------------------------
@@ -318,12 +339,13 @@
 //         System.out.println("list "+name);
          
          Vector list = new Vector();
-         Enumeration keys = table.keys();
-         while (keys.hasMoreElements())
+         Iterator iter = table.entrySet().iterator();
+         while(iter.hasNext())
          {
-            String key = (String)keys.nextElement();
-            Binding b = getBinding(key);
-            
+            Map.Entry entry = (Map.Entry)iter.next();
+            String key = (String)entry.getKey();
+            Binding b = (Binding)entry.getValue();
+
             list.addElement(new NameClassPair(b.getName(),b.getClassName(),true));
          }
          return list;
@@ -471,7 +493,7 @@
          {
             Name fullName = (Name) prefix.clone();
             fullName.addAll(name);
-            NamingServer subContext = new NamingServer(fullName, this);
+            NamingServer subContext = createNamingServer(fullName, this);
             setBinding(name, subContext, NamingContext.class.getName());
             subCtx = new NamingContext(null, fullName, getRoot());
          }




More information about the jboss-cvs-commits mailing list