[jboss-cvs] JBossAS SVN: r74736 - trunk/cluster/src/main/org/jboss/ha/jndi.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 17 17:36:48 EDT 2008


Author: pferraro
Date: 2008-06-17 17:36:48 -0400 (Tue, 17 Jun 2008)
New Revision: 74736

Modified:
   trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java
   trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java
   trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java
   trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java
   trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java
Log:
Re-committing rolled back change after fixing Java 5/6 source code incompatibility.

Modified: trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java	2008-06-17 21:33:25 UTC (rev 74735)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java	2008-06-17 21:36:48 UTC (rev 74736)
@@ -36,7 +36,6 @@
 import java.rmi.MarshalledObject;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -44,6 +43,7 @@
 import javax.management.ObjectName;
 import javax.management.Query;
 import javax.management.QueryExp;
+import javax.naming.Binding;
 import javax.net.ServerSocketFactory;
 
 import org.jboss.cache.Cache;
@@ -79,20 +79,20 @@
    /**
     * The jnp server socket through which the HAJNDI stub is vended
     */
-   protected ServerSocket bootstrapSocket;
+   ServerSocket bootstrapSocket;
 
    /**
     * The Naming interface server implementation
     */
-   protected HAJNDI theServer;
+   HAJNDI theServer;
    /**
     * The mapping from the long method hash to the Naming Method
     */
-   protected Map marshalledInvocationMapping;
+   private Map<Long, Method> marshalledInvocationMapping;
    /**
     * The protocol stub returned to clients by the bootstrap lookup
     */
-   protected Naming stub;
+   Naming stub;
    /**
     * The HAPartition
     */
@@ -100,7 +100,7 @@
    /**
     * The cache used to store HA-JNDI bindings
     */
-   protected Cache cache;
+   private Cache<String, Binding> cache;
 
    /**
     * The proxy factory service that generates the Naming stub
@@ -111,48 +111,48 @@
     * The interface to bind to. This is useful for multi-homed hosts that want
     * control over which interfaces accept connections.
     */
-   protected InetAddress bindAddress;
+   InetAddress bindAddress;
    /**
     * The bootstrapSocket listen queue depth
     */
-   protected int backlog = 50;
+   private int backlog = 50;
    /**
     * The jnp protocol listening port. The default is 1100, the same as the RMI
     * registry default port.
     */
-   protected int port = 1100;
+   int port = 1100;
 
    /**
     * The autodiscovery multicast group
     */
-   protected String adGroupAddress = NamingContext.DEFAULT_DISCOVERY_GROUP_ADDRESS;
+   String adGroupAddress = NamingContext.DEFAULT_DISCOVERY_GROUP_ADDRESS;
    /**
     * The autodiscovery port
     */
-   protected int adGroupPort = NamingContext.DEFAULT_DISCOVERY_GROUP_PORT;
+   int adGroupPort = NamingContext.DEFAULT_DISCOVERY_GROUP_PORT;
    /**
     * The interface to bind the Multicast socket for autodiscovery to
     */
-   protected InetAddress discoveryBindAddress;
+   InetAddress discoveryBindAddress;
    /** The runable task for discovery request packets */
-   protected AutomaticDiscovery autoDiscovery = null;
+   private AutomaticDiscovery autoDiscovery = null;
    /** A flag indicating if autodiscovery should be disabled */
-   protected boolean discoveryDisabled = false;
+   private boolean discoveryDisabled = false;
    /** The autodiscovery Multicast reply TTL */
-   protected int autoDiscoveryTTL = 16;
+   int autoDiscoveryTTL = 16;
    /**
     * An optional custom server socket factory for the bootstrap lookup
     */
-   protected ServerSocketFactory jnpServerSocketFactory;
+   private ServerSocketFactory jnpServerSocketFactory;
    /**
     * The class name of the optional custom JNP server socket factory
     */
-   protected String jnpServerSocketFactoryName;
+   private String jnpServerSocketFactoryName;
 
    /**
     * The thread pool used to handle jnp stub lookup requests
     */
-   protected ThreadPool lookupPool;
+   ThreadPool lookupPool;
 
    // Public --------------------------------------------------------
 
@@ -166,19 +166,19 @@
     * @return A Map<Long hash, Method> of the Naming interface
     * @jmx:managed-attribute
     */
-   public Map getMethodMap()
+   public Map<Long, Method> getMethodMap()
    {
-      return marshalledInvocationMapping;
+      return this.marshalledInvocationMapping;
    }
 
    public String getPartitionName()
    {
-      return clusterPartition.getPartitionName();
+      return this.clusterPartition.getPartitionName();
    }
 
    public HAPartition getHAPartition()
    {
-      return clusterPartition;
+      return this.clusterPartition;
    }
 
    public void setHAPartition(HAPartition clusterPartition)
@@ -186,19 +186,19 @@
       this.clusterPartition = clusterPartition;
    }
    
-   public Cache getClusteredCache()
-   {     
-      return cache;
+   public Cache<String, Binding> getClusteredCache()
+   {
+      return this.cache;
    }
 
-   public void setClusteredCache(Cache cache)
+   public void setClusteredCache(Cache<String, Binding> cache)
    {
       this.cache = cache;
    }
 
    public ObjectName getProxyFactoryObjectName()
    {
-      return proxyFactory;
+      return this.proxyFactory;
    }
 
    public void setProxyFactoryObjectName(ObjectName proxyFactory)
@@ -208,36 +208,40 @@
 
    public void setPort(int p)
    {
-      port = p;
+      this.port = p;
    }
 
    public int getPort()
    {
-      return port;
+      return this.port;
    }
 
    public String getBindAddress()
    {
       String address = null;
-      if (bindAddress != null)
-         address = bindAddress.getHostAddress();
+      if (this.bindAddress != null)
+      {
+         address = this.bindAddress.getHostAddress();
+      }
       return address;
    }
 
    public void setBindAddress(String host) throws java.net.UnknownHostException
    {
-      bindAddress = InetAddress.getByName(host);
+      this.bindAddress = InetAddress.getByName(host);
    }
 
    public int getBacklog()
    {
-      return backlog;
+      return this.backlog;
    }
 
    public void setBacklog(int backlog)
    {
       if (backlog <= 0)
+      {
          backlog = 50;
+      }
       this.backlog = backlog;
    }
 
@@ -265,6 +269,7 @@
    {
       return this.adGroupPort;
    }
+   
    public void setAutoDiscoveryGroup(int adGroup)
    {
       this.adGroupPort = adGroup;
@@ -272,39 +277,35 @@
 
    public String getAutoDiscoveryBindAddress()
    {
-      String address = null;
-      if (discoveryBindAddress != null)
-         address = discoveryBindAddress.getHostAddress();
-      return address;      
+      return (this.discoveryBindAddress != null) ? this.discoveryBindAddress.getHostAddress() : null;
    }
-   public void setAutoDiscoveryBindAddress(String address)
-      throws UnknownHostException
+   
+   public void setAutoDiscoveryBindAddress(String address) throws UnknownHostException
    {
-      discoveryBindAddress = InetAddress.getByName(address);
+      this.discoveryBindAddress = InetAddress.getByName(address);
    }
 
    public int getAutoDiscoveryTTL()
    {
-      return autoDiscoveryTTL;
+      return this.autoDiscoveryTTL;
    }
 
    public void setAutoDiscoveryTTL(int ttl)
    {
-      autoDiscoveryTTL = ttl;
+      this.autoDiscoveryTTL = ttl;
    }
 
-   public void setJNPServerSocketFactory(String factoryClassName)
-      throws ClassNotFoundException, InstantiationException, IllegalAccessException
+   public void setJNPServerSocketFactory(String factoryClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
       this.jnpServerSocketFactoryName = factoryClassName;
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
-      Class clazz = loader.loadClass(jnpServerSocketFactoryName);
-      jnpServerSocketFactory = (ServerSocketFactory) clazz.newInstance();
+      Class<?> clazz = loader.loadClass(this.jnpServerSocketFactoryName);
+      this.jnpServerSocketFactory = (ServerSocketFactory) clazz.newInstance();
    }
 
    public void setLookupPool(BasicThreadPoolMBean poolMBean)
    {
-      lookupPool = poolMBean.getInstance();
+      this.lookupPool = poolMBean.getInstance();
    }
 /*
    public void startService(HAPartition haPartition)
@@ -313,95 +314,104 @@
       this.startService();
    }
 */
-   protected void createService()
-      throws Exception
+   @Override
+   protected void createService() throws Exception
    {
-      if (clusterPartition == null)
+      if (this.clusterPartition == null)
+      {
          throw new IllegalStateException("HAPartition property must be set before starting HAJNDI service");
+      }
       
-      if (cache == null)
+      if (this.cache == null)
+      {
          throw new IllegalStateException("ClusteredCache property must be set before starting HAJNDI service");
+      }
       
-      if (log.isDebugEnabled())
-         log.debug("Initializing HAJNDI server on partition: " + clusterPartition.getPartitionName());       
+      this.log.debug("Initializing HAJNDI server on partition: " + this.clusterPartition.getPartitionName());
       
       // Start HAJNDI service
-      theServer = new HAJNDI(clusterPartition, cache);
+      this.theServer = new HAJNDI(this.clusterPartition, this.cache);
 
       // Build the Naming interface method map
-      HashMap tmpMap = new HashMap(13);
+      Map<Long, Method> map = new HashMap<Long, Method>(13);
       Method[] methods = Naming.class.getMethods();
-      for (int m = 0; m < methods.length; m++)
+      for (Method method: methods)
       {
-         Method method = methods[m];
          Long hash = new Long(MarshalledInvocation.calculateHash(method));
-         tmpMap.put(hash, method);
+         map.put(hash, method);
       }
-      marshalledInvocationMapping = Collections.unmodifiableMap(tmpMap);
+      this.marshalledInvocationMapping = Collections.unmodifiableMap(map);
       
       // share instance for in-vm discovery
-      NamingContext.setHANamingServerForPartition(clusterPartition.getPartitionName(), theServer);
+      NamingContext.setHANamingServerForPartition(this.clusterPartition.getPartitionName(), this.theServer);
    }
 
+   @Override
    protected void startService()
       throws Exception
    {
-      log.debug("Obtaining the HAJNDI transport proxy");
-      stub = this.getNamingProxy();
-      this.theServer.setHAStub(stub);
-      if (port >= 0)
+      this.log.debug("Obtaining the HAJNDI transport proxy");
+      this.stub = this.getNamingProxy();
+      this.theServer.setHAStub(this.stub);
+      if (this.port >= 0)
       {
-         log.debug("Starting HAJNDI bootstrap listener");
-         initBootstrapListener();
+         this.log.debug("Starting HAJNDI bootstrap listener");
+         this.initBootstrapListener();
       }
 
       // Automatic Discovery for unconfigured clients
-      if (adGroupAddress != null && discoveryDisabled == false)
+      if (this.adGroupAddress != null && this.discoveryDisabled == false)
       {
          try
          {
-            autoDiscovery = new AutomaticDiscovery();
-            autoDiscovery.start();
-            lookupPool.run(autoDiscovery);
+            this.autoDiscovery = new AutomaticDiscovery();
+            this.autoDiscovery.start();
+            this.lookupPool.run(this.autoDiscovery);
          }
          catch (Exception e)
          {
-            log.warn("Failed to start AutomaticDiscovery", e);
+            this.log.warn("Failed to start AutomaticDiscovery", e);
          }
       }
-      log.debug("initializing HAJNDI");
-      theServer.init();
+      this.log.debug("initializing HAJNDI");
+      this.theServer.init();
    }
 
+   @Override
    protected void stopService() throws Exception
    {
       // un-share instance for in-vm discovery
-      NamingContext.removeHANamingServerForPartition(clusterPartition.getPartitionName());
+      NamingContext.removeHANamingServerForPartition(this.clusterPartition.getPartitionName());
 
       // Stop listener
-      ServerSocket s = bootstrapSocket;
-      bootstrapSocket = null;
+      ServerSocket s = this.bootstrapSocket;
+      this.bootstrapSocket = null;
       if (s != null)
       {
-         log.debug("Closing the HAJNDI bootstrap listener");
+         this.log.debug("Closing the HAJNDI bootstrap listener");
          s.close();
       }
 
       // Stop HAJNDI service
-      log.debug("Stopping the HAJNDI service");
-      theServer.stop();
+      this.log.debug("Stopping the HAJNDI service");
+      this.theServer.stop();
 
-      log.debug("Stopping AutomaticDiscovery");
-      if (autoDiscovery != null && discoveryDisabled == false)
-         autoDiscovery.stop();
+      this.log.debug("Stopping AutomaticDiscovery");
+      if (this.autoDiscovery != null && this.discoveryDisabled == false)
+      {
+         this.autoDiscovery.stop();
+      }
    }
    
+   @Override
    protected void destroyService() throws Exception
    {
-      log.debug("Destroying the HAJNDI service");
+      this.log.debug("Destroying the HAJNDI service");
       // server may be null if service failed on startup
-      if (theServer != null)
-         theServer.destroy();
+      if (this.theServer != null)
+      {
+         this.theServer.destroy();
+      }
    }
 
    /**
@@ -417,7 +427,7 @@
       if (invocation instanceof MarshalledInvocation)
       {
          MarshalledInvocation mi = (MarshalledInvocation) invocation;
-         mi.setMethodMap(marshalledInvocationMapping);
+         mi.setMethodMap(this.marshalledInvocationMapping);
       }
       // Invoke the Naming method via reflection
       Method method = invocation.getMethod();
@@ -425,15 +435,17 @@
       Object value = null;
       try
       {
-         value = method.invoke(theServer, args);
+         value = method.invoke(this.theServer, args);
       }
       catch (InvocationTargetException e)
       {
          Throwable t = e.getTargetException();
          if (t instanceof Exception)
+         {
             throw (Exception) t;
-         else
-            throw new UndeclaredThrowableException(t, method.toString());
+         }
+
+         throw new UndeclaredThrowableException(t, method.toString());
       }
 
       return value;
@@ -448,30 +460,36 @@
       try
       {
          // Get the default ServerSocketFactory is one was not specified
-         if (jnpServerSocketFactory == null)
-            jnpServerSocketFactory = ServerSocketFactory.getDefault();
-         bootstrapSocket = jnpServerSocketFactory.createServerSocket(port, backlog, bindAddress);
+         if (this.jnpServerSocketFactory == null)
+         {
+            this.jnpServerSocketFactory = ServerSocketFactory.getDefault();
+         }
+         this.bootstrapSocket = this.jnpServerSocketFactory.createServerSocket(this.port, this.backlog, this.bindAddress);
          // If an anonymous port was specified get the actual port used
-         if (port == 0)
-            port = bootstrapSocket.getLocalPort();
-         String msg = "Started HAJNDI bootstrap; jnpPort=" + port
-            + ", backlog=" + backlog + ", bindAddress=" + bindAddress;
-         log.info(msg);
+         if (this.port == 0)
+         {
+            this.port = this.bootstrapSocket.getLocalPort();
+         }
+         String msg = "Started HAJNDI bootstrap; jnpPort=" + this.port
+            + ", backlog=" + this.backlog + ", bindAddress=" + this.bindAddress;
+         this.log.info(msg);
       }
       catch (IOException e)
       {
-         log.error("Could not start HAJNDI bootstrap listener on port " + port, e);
+         this.log.error("Could not start HAJNDI bootstrap listener on port " + this.port, e);
       }
 
-      if (lookupPool == null)
-         lookupPool = new BasicThreadPool("HANamingBootstrap Pool");
+      if (this.lookupPool == null)
+      {
+         this.lookupPool = new BasicThreadPool("HANamingBootstrap Pool");
+      }
       AcceptHandler handler = new AcceptHandler();
-      lookupPool.run(handler);
+      this.lookupPool.run(handler);
    }
 
    // Protected -----------------------------------------------------
    
-   protected HAPartition findHAPartitionWithName(String name) throws Exception
+   protected HAPartition findHAPartitionWithName(String name)
    {
       HAPartition result = null;
       // Class name match does not work with the AOP proxy :(
@@ -482,12 +500,12 @@
       QueryExp matchPartitionName = Query.match(Query.attr("PartitionName"),
          Query.value(name));
       QueryExp exp = Query.and(matchName, matchPartitionName);
-      Set mbeans = this.getServer().queryMBeans(null, exp);
+      Set<?> mbeans = this.getServer().queryMBeans(null, exp);
       if (mbeans != null && mbeans.size() > 0)
       {
-         for (Iterator iter = mbeans.iterator(); iter.hasNext();)
+         for (Object mbean: mbeans)
          {
-            ObjectInstance inst = (ObjectInstance) iter.next();
+            ObjectInstance inst = (ObjectInstance) mbean;
             try
             {
                ClusterPartitionMBean cp =
@@ -498,7 +516,10 @@
                result = cp.getHAPartition();
                break;
             }
-            catch (Exception e) {}
+            catch (Exception e)
+            {
+               // Ignore
+            }
          }
       }
 
@@ -513,8 +534,7 @@
     */
    protected Naming getNamingProxy() throws Exception
    {
-      Naming proxy = (Naming) server.getAttribute(proxyFactory, "Proxy");
-      return proxy;
+      return (Naming) this.server.getAttribute(this.proxyFactory, "Proxy");
    }
 
    // Private -------------------------------------------------------
@@ -522,17 +542,17 @@
    private class AutomaticDiscovery
       implements Runnable
    {
-      protected Logger log = Logger.getLogger(AutomaticDiscovery.class);
+      private Logger log = Logger.getLogger(AutomaticDiscovery.class);
       /** The socket for auto discovery requests */
-      protected MulticastSocket socket = null;
+      private MulticastSocket socket = null;
       /** The ha-jndi addres + ':' + port string */
-      protected byte[] ipAddress = null;
+      private byte[] ipAddress = null;
       /** The multicast group address */
-      protected InetAddress group = null;
-      protected boolean stopping = false;
-      // Thread that is executing the run() method      
-      protected Thread receiverThread = null;
-      protected boolean receiverStopped = true;
+      private InetAddress group = null;
+      private boolean stopping = false;
+      // Thread that is executing the run() method
+      private Thread receiverThread = null;
+      private boolean receiverStopped = true;
 
       public AutomaticDiscovery() throws Exception
       {
@@ -540,21 +560,23 @@
 
       public void start() throws Exception
       {
-         stopping = false;
+         this.stopping = false;
          // Use the jndi bind address if there is no discovery address
-         if (discoveryBindAddress == null)
-            discoveryBindAddress = bindAddress;
-         socket = new MulticastSocket(adGroupPort);
+         if (DetachedHANamingService.this.discoveryBindAddress == null)
+         {
+            DetachedHANamingService.this.discoveryBindAddress = DetachedHANamingService.this.bindAddress;
+         }
+         this.socket = new MulticastSocket(DetachedHANamingService.this.adGroupPort);
          // If there is a bind address valid, set the socket interface to it
-         if (discoveryBindAddress != null && discoveryBindAddress.isAnyLocalAddress() == false)
+         if (DetachedHANamingService.this.discoveryBindAddress != null && DetachedHANamingService.this.discoveryBindAddress.isAnyLocalAddress() == false)
          {
-            socket.setInterface(discoveryBindAddress);
+            this.socket.setInterface(DetachedHANamingService.this.discoveryBindAddress);
          }
-         socket.setTimeToLive(autoDiscoveryTTL);
-         group = InetAddress.getByName(adGroupAddress);
-         socket.joinGroup(group);
+         this.socket.setTimeToLive(DetachedHANamingService.this.autoDiscoveryTTL);
+         this.group = InetAddress.getByName(DetachedHANamingService.this.adGroupAddress);
+         this.socket.joinGroup(this.group);
 
-         String address = getBindAddress();
+         String address = DetachedHANamingService.this.getBindAddress();
          /* An INADDR_ANY (0.0.0.0 || null) address is useless as the value
             sent to a remote client so check for this and use the local host
             address instead.
@@ -563,87 +585,99 @@
          {
             address = InetAddress.getLocalHost().getHostAddress();
          }
-         ipAddress = (address + ":" + port).getBytes();
+         this.ipAddress = (address + ":" + DetachedHANamingService.this.port).getBytes();
 
-         log.info("Listening on " + socket.getInterface() + ":" + socket.getLocalPort()
-            + ", group=" + adGroupAddress
-            + ", HA-JNDI address=" + new String(ipAddress));
+         this.log.info("Listening on " + this.socket.getInterface() + ":" + this.socket.getLocalPort()
+            + ", group=" + DetachedHANamingService.this.adGroupAddress
+            + ", HA-JNDI address=" + new String(this.ipAddress));
       }
 
       public void stop()
       {
          try
          {
-            stopping = true;
+            this.stopping = true;
             
             // JBAS-2834 -- try to stop the receiverThread
-            if (receiverThread != null 
-                  && receiverThread != Thread.currentThread()
-                  && receiverThread.isInterrupted() == false)
+            if (this.receiverThread != null
+                  && this.receiverThread != Thread.currentThread()
+                  && this.receiverThread.isInterrupted() == false)
             {
                // Give it a moment to die on its own (unlikely)
-               receiverThread.join(5);
-               if (!receiverStopped)
-                  receiverThread.interrupt(); // kill it
+               this.receiverThread.join(5);
+               if (!this.receiverStopped)
+               {
+                  this.receiverThread.interrupt(); // kill it
+               }
             }
             
-            socket.leaveGroup(group);
-            socket.close();
+            this.socket.leaveGroup(this.group);
+            this.socket.close();
          }
          catch (Exception ex)
          {
-            log.error("Stopping AutomaticDiscovery failed", ex);
+            this.log.error("Stopping AutomaticDiscovery failed", ex);
          }
       }
 
       public void run()
       {
-         boolean trace = log.isTraceEnabled();
-         log.debug("Discovery request thread begin");
+         boolean trace = this.log.isTraceEnabled();
+         this.log.debug("Discovery request thread begin");
          
          // JBAS-2834 Cache a reference to this thread so stop()
          // can interrupt it if necessary
-         receiverThread = Thread.currentThread();
+         this.receiverThread = Thread.currentThread();
 
-         receiverStopped = false;
+         this.receiverStopped = false;
          
          // Wait for a datagram
          while (true)
          {
             // Stopped by normal means
-            if (stopping)
+            if (this.stopping)
+            {
                break;
+            }
             try
             {
                if (trace)
-                  log.trace("HA-JNDI AutomaticDiscovery waiting for queries...");
+               {
+                  this.log.trace("HA-JNDI AutomaticDiscovery waiting for queries...");
+               }
                byte[] buf = new byte[256];
                DatagramPacket packet = new DatagramPacket(buf, buf.length);
-               socket.receive(packet);
+               this.socket.receive(packet);
                if (trace)
-                  log.trace("HA-JNDI AutomaticDiscovery Packet received.");
+               {
+                  this.log.trace("HA-JNDI AutomaticDiscovery Packet received.");
+               }
 
                // Queue the response to the thread pool
-               DiscoveryRequestHandler handler = new DiscoveryRequestHandler(log,
-                  packet, socket, ipAddress);
-               lookupPool.run(handler);
+               DiscoveryRequestHandler handler = new DiscoveryRequestHandler(this.log,
+                  packet, this.socket, this.ipAddress);
+               DetachedHANamingService.this.lookupPool.run(handler);
                if (trace)
-                  log.trace("Queued DiscoveryRequestHandler");
+               {
+                  this.log.trace("Queued DiscoveryRequestHandler");
+               }
             }
             catch (Throwable t)
             {
-               if (stopping == false)
-                  log.warn("Ignored error while processing HAJNDI discovery request:", t);
+               if (this.stopping == false)
+               {
+                  this.log.warn("Ignored error while processing HAJNDI discovery request:", t);
+               }
             }
          }
-         receiverStopped = true;
-         log.debug("Discovery request thread end");
+         this.receiverStopped = true;
+         this.log.debug("Discovery request thread end");
       }
    }
 
    /**
     * The class used as the runnable for writing the bootstrap stub
-    */ 
+    */
    private class DiscoveryRequestHandler implements Runnable
    {
       private Logger log;
@@ -661,85 +695,105 @@
       }
       public void run()
       {
-         boolean trace = log.isTraceEnabled();
+         boolean trace = this.log.isTraceEnabled();
          if( trace )
-            log.trace("DiscoveryRequestHandler begin");
+         {
+            this.log.trace("DiscoveryRequestHandler begin");
+         }
          // Return the naming server IP address and port to the client
          try
          {
             // See if the discovery is restricted to a particular parition
-            String requestData = new String(packet.getData()).trim();
+            String requestData = new String(this.packet.getData()).trim();
             if( trace )
-               log.trace("RequestData: "+requestData);
+            {
+               this.log.trace("RequestData: "+requestData);
+            }
             int colon = requestData.indexOf(':');
             if (colon > 0)
             {
                // Check the partition name
                String name = requestData.substring(colon + 1);
-               if (name.equals(clusterPartition.getPartitionName()) == false)
+               if (name.equals(DetachedHANamingService.this.clusterPartition.getPartitionName()) == false)
                {
-                  log.debug("Ignoring discovery request for partition: " + name);
+                  this.log.debug("Ignoring discovery request for partition: " + name);
                   if( trace )
-                     log.trace("DiscoveryRequestHandler end");
+                  {
+                     this.log.trace("DiscoveryRequestHandler end");
+                  }
                   return;
                }
             }
-            DatagramPacket p = new DatagramPacket(ipAddress, ipAddress.length,
-               packet.getAddress(), packet.getPort());
+            DatagramPacket p = new DatagramPacket(this.ipAddress, this.ipAddress.length,
+               this.packet.getAddress(), this.packet.getPort());
             if (trace)
-               log.trace("Sending AutomaticDiscovery answer: " + new String(ipAddress) + 
-                         " to " + packet.getAddress() + ":" + packet.getPort());
-            socket.send(p);
+            {
+               this.log.trace("Sending AutomaticDiscovery answer: " + new String(this.ipAddress) +
+                         " to " + this.packet.getAddress() + ":" + this.packet.getPort());
+            }
+            this.socket.send(p);
             if (trace)
-               log.trace("AutomaticDiscovery answer sent.");
+            {
+               this.log.trace("AutomaticDiscovery answer sent.");
+            }
          }
          catch (IOException ex)
          {
-            log.error("Error writing response", ex);
-         }         
+            this.log.error("Error writing response", ex);
+         }
          if( trace )
-            log.trace("DiscoveryRequestHandler end");
+         {
+            this.log.trace("DiscoveryRequestHandler end");
+         }
       }
    }
 
    /**
     * The class used as the runnable for the bootstrap lookup thread pool.
-    */ 
+    */
    private class AcceptHandler implements Runnable
    {
+      AcceptHandler()
+      {
+      }
+      
       public void run()
       {
-         boolean trace = log.isTraceEnabled();
-         while (bootstrapSocket != null)
+         boolean trace = DetachedHANamingService.this.log.isTraceEnabled();
+         while (DetachedHANamingService.this.bootstrapSocket != null)
          {
             Socket socket = null;
             // Accept a connection
             try
             {
-               socket = bootstrapSocket.accept();
-               if( trace )
-                  log.trace("Accepted bootstrap client: "+socket);
+               socket = DetachedHANamingService.this.bootstrapSocket.accept();
+               if (trace)
+               {
+                  DetachedHANamingService.this.log.trace("Accepted bootstrap client: "+socket);
+               }
                BootstrapRequestHandler handler = new BootstrapRequestHandler(socket);
-               lookupPool.run(handler);
+               DetachedHANamingService.this.lookupPool.run(handler);
             }
             catch (IOException e)
             {
                // Stopped by normal means
-               if (bootstrapSocket == null)
+               if (DetachedHANamingService.this.bootstrapSocket == null)
+               {
                   return;
-               log.error("Naming accept handler stopping", e);
+               }
+               DetachedHANamingService.this.log.error("Naming accept handler stopping", e);
             }
             catch(Throwable e)
             {
-               log.error("Unexpected exception during accept", e);
+               DetachedHANamingService.this.log.error("Unexpected exception during accept", e);
             }
-         }      
+         }
       }
    }
 
    /**
     * The class used as the runnable for writing the bootstrap stub
-    */ 
+    */
    private class BootstrapRequestHandler implements Runnable
    {
       private Socket socket;
@@ -752,21 +806,21 @@
          // Return the naming server stub
          try
          {
-            OutputStream os = socket.getOutputStream();
+            OutputStream os = this.socket.getOutputStream();
             ObjectOutputStream out = new ObjectOutputStream(os);
-            MarshalledObject replyStub = new MarshalledObject(stub);
+            MarshalledObject replyStub = new MarshalledObject(DetachedHANamingService.this.stub);
             out.writeObject(replyStub);
             out.close();
          }
          catch (IOException ex)
          {
-            log.debug("Error writing response to " + socket, ex);
+            DetachedHANamingService.this.log.debug("Error writing response to " + this.socket, ex);
          }
          finally
          {
             try
             {
-               socket.close();
+               this.socket.close();
             }
             catch (IOException e)
             {

Modified: trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java	2008-06-17 21:33:25 UTC (rev 74735)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java	2008-06-17 21:36:48 UTC (rev 74736)
@@ -21,9 +21,11 @@
   */
 package org.jboss.ha.jndi;
 
+import java.lang.reflect.Method;
 import java.net.UnknownHostException;
 import java.util.Map;
 import javax.management.ObjectName;
+import javax.naming.Binding;
 
 import org.jboss.cache.Cache;
 import org.jboss.ha.framework.interfaces.HAPartition;
@@ -67,14 +69,14 @@
     * 
     * @return the cache
     */
-   Cache getClusteredCache();
+   Cache<String, Binding> getClusteredCache();
    
    /**
     * Sets the underlying cache used by this service.
     * 
     * @param cache the cache
     */
-   void setClusteredCache(Cache cache);
+   void setClusteredCache(Cache<String, Binding> cache);
 
    /** Get the proxy factory service name used to create the Naming transport
     * proxy.
@@ -137,8 +139,7 @@
    /** Set the auto-discovery bootstrap multicast bind address. If not specified
     * and a BindAddress is specified, the BindAddress will be used.
     */
-   void setAutoDiscoveryBindAddress(String adAddress)
-      throws UnknownHostException;
+   void setAutoDiscoveryBindAddress(String adAddress) throws UnknownHostException;
 
    /** Get the TTL (time-to-live) for autodiscovery IP multicast packets */
    int getAutoDiscoveryTTL();
@@ -158,7 +159,7 @@
     *
     * @return A Map<Long hash, Method> of the Naming interface
     */
-   public Map getMethodMap();
+   public Map<Long, Method> getMethodMap();
 
    /** Expose the Naming service via JMX for detached invokers.
     *

Modified: trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java	2008-06-17 21:33:25 UTC (rev 74735)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java	2008-06-17 21:36:48 UTC (rev 74736)
@@ -23,17 +23,17 @@
 
 import java.util.Collection;
 
+import javax.naming.Binding;
 import javax.naming.Name;
+import javax.naming.NameClassPair;
 import javax.naming.NamingException;
 
-import org.jnp.interfaces.Naming;
-
-import org.jboss.cache.Fqn;
 import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
 import org.jboss.ha.framework.interfaces.HAPartition;
-import org.jboss.logging.Logger;
+import org.jnp.interfaces.Naming;
 
-/** 
+/**
  *  This class utilizes JBossCache to provide a distributed JNDI implementation.
  *  Lookups will look for Names in HAJNDI then delegate to the local InitialContext.
  *
@@ -48,54 +48,56 @@
    static final long serialVersionUID = -6277328603304171620L;
   
    public static final String ROOT = "__HA_JNDI__";
-   public static final Fqn ROOTFQN = new Fqn(new Object[] { ROOT });
+   public static final Fqn<String> ROOTFQN = new Fqn<String>(ROOT);
    
    // Attributes --------------------------------------------------------
-   private static Logger log = Logger.getLogger(HAJNDI.class);
-   
-   protected HAPartition partition;
-   protected TreeHead delegate;
-   protected Naming haStub;
+   private HAPartition partition;
+   private TreeHead delegate;
+   private Naming haStub;
 
-   // Constructor --------------------------------------------------------  
+   // Constructor --------------------------------------------------------
   
-   public HAJNDI(HAPartition partition, Cache cache)
-   throws NamingException
+   public HAJNDI(HAPartition partition, Cache<String, Binding> cache)
    {
       if (partition == null)
+      {
          throw new IllegalArgumentException("Null partition");
+      }
+      
       if (cache == null)
+      {
          throw new IllegalArgumentException("Null cache");
+      }
+      
       this.partition = partition;
-      delegate = new TreeHead(cache, HAJNDI.ROOTFQN);
-      delegate.setPartition(this.partition);
-      delegate.setHARMIHead(this);
-
+      this.delegate = new TreeHead(cache, HAJNDI.ROOTFQN);
+      this.delegate.setPartition(this.partition);
+      this.delegate.setHARMIHead(this);
    }
    
    // Public --------------------------------------------------------
 
-   public void init() throws Exception
+   public void init()
    {
-      delegate.init();
+      this.delegate.init();
    }
 
-   public void stop() throws Exception
+   public void stop()
    {
-      delegate.stop();
+      this.delegate.stop();
    }
 
-   public void destroy() throws Exception
+   public void destroy()
    {
-      delegate.destroy();
+      this.delegate.destroy();
    }
 
-   public void setHAStub (Naming stub)
+   public void setHAStub(Naming stub)
    {
       this.haStub = stub;
    }
 
-   public Naming getHAStub ()
+   public Naming getHAStub()
    {
       return this.haStub;
    }
@@ -103,45 +105,38 @@
    // Naming implementation -----------------------------------------
    
 
-   public synchronized void bind(Name name, Object obj, String className)
-      throws NamingException
+   public synchronized void bind(Name name, Object obj, String className) throws NamingException
    {
-      delegate.bind (name, obj, className);
+      this.delegate.bind(name, obj, className);
    }
 
-   public synchronized void rebind(Name name, Object obj, String className)
-      throws NamingException
+   public synchronized void rebind(Name name, Object obj, String className) throws NamingException
    {
-      delegate.rebind (name, obj, className);
+      this.delegate.rebind(name, obj, className);
    }
 
-   public synchronized void unbind(Name name)
-      throws NamingException
+   public synchronized void unbind(Name name) throws NamingException
    {
-      delegate.unbind (name);
+      this.delegate.unbind(name);
    }
 
-   public Object lookup(Name name)
-      throws NamingException
+   public Object lookup(Name name) throws NamingException
    {
-      return delegate.lookup (name);
+      return this.delegate.lookup(name);
    }
 
-   public Collection list(Name name)
-      throws NamingException
+   public Collection<NameClassPair> list(Name name) throws NamingException
    {
-      return delegate.list(name) ;
+      return this.delegate.list(name) ;
    }
     
-   public Collection listBindings(Name name)
-      throws NamingException
+   public Collection<Binding> listBindings(Name name) throws NamingException
    {
-      return delegate.listBindings(name);
+      return this.delegate.listBindings(name);
    }
    
-   public javax.naming.Context createSubcontext(Name name)
-      throws NamingException
+   public javax.naming.Context createSubcontext(Name name) throws NamingException
    {
-      return delegate.createSubcontext(name);
+      return this.delegate.createSubcontext(name);
    }
 }

Modified: trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java	2008-06-17 21:33:25 UTC (rev 74735)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java	2008-06-17 21:36:48 UTC (rev 74736)
@@ -21,12 +21,12 @@
   */
 package org.jboss.ha.jndi;
 
+import java.rmi.server.RMIClientSocketFactory;
 import java.rmi.server.RMIServerSocketFactory;
-import java.rmi.server.RMIClientSocketFactory;
 
 import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
+import org.jboss.ha.framework.interfaces.RoundRobin;
 import org.jboss.ha.framework.server.HARMIServerImpl;
-import org.jboss.ha.framework.interfaces.RoundRobin;
 import org.jnp.interfaces.Naming;
 
 /** Management Bean for HA-JNDI service for the legacy version that is coupled
@@ -46,20 +46,20 @@
    
    // Attributes ----------------------------------------------------
    /** An optional custom client socket factory */
-   protected RMIClientSocketFactory clientSocketFactory;
+   private RMIClientSocketFactory clientSocketFactory;
    /** An optional custom server socket factory */
-   protected RMIServerSocketFactory serverSocketFactory;
+   private RMIServerSocketFactory serverSocketFactory;
    /** The class name of the optional custom client socket factory */
-   protected String clientSocketFactoryName;
+   private String clientSocketFactoryName;
    /** The class name of the optional custom server socket factory */
-   protected String serverSocketFactoryName;
+   private String serverSocketFactoryName;
    /** The class name of the load balancing policy */
-   protected String loadBalancePolicy = RoundRobin.class.getName();
+   private String loadBalancePolicy = RoundRobin.class.getName();
    /** The RMI port on which the Naming implementation will be exported. The
     default is 0 which means use any available port. */
-   protected int rmiPort = 0;
+   private int rmiPort = 0;
    protected String replicantName = "HAJNDI";
-   HARMIServerImpl rmiserver;
+   private HARMIServerImpl rmiserver;
 
    // Public --------------------------------------------------------
 
@@ -70,69 +70,69 @@
 
    public void setRmiPort(int p)
    {
-      rmiPort = p;
+      this.rmiPort = p;
    }
    public int getRmiPort()
    {
-      return rmiPort;
+      return this.rmiPort;
    }
    
    public String getClientSocketFactory()
    {
-      return serverSocketFactoryName;
+      return this.serverSocketFactoryName;
    }
+   
    public void setClientSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
       this.clientSocketFactoryName = factoryClassName;
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
-      Class clazz = loader.loadClass(clientSocketFactoryName);
-      clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
+      Class<?> clazz = loader.loadClass(this.clientSocketFactoryName);
+      this.clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
    }
    
    public String getServerSocketFactory()
    {
-      return serverSocketFactoryName;
+      return this.serverSocketFactoryName;
    }
    public void setServerSocketFactory(String factoryClassName)
       throws ClassNotFoundException, InstantiationException, IllegalAccessException
    {
       this.serverSocketFactoryName = factoryClassName;
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
-      Class clazz = loader.loadClass(serverSocketFactoryName);
-      serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
+      Class<?> clazz = loader.loadClass(this.serverSocketFactoryName);
+      this.serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
    }
 
    public String getLoadBalancePolicy()
    {
-      return loadBalancePolicy;
+      return this.loadBalancePolicy;
    }
    public void setLoadBalancePolicy(String policyClassName)
    {
-      loadBalancePolicy = policyClassName;
+      this.loadBalancePolicy = policyClassName;
    }
    
+   @Override
    protected void stopService() throws Exception
    {
       super.stopService();
       // Unexport server
-      log.debug("destroy ha rmiserver");
+      this.log.debug("destroy ha rmiserver");
       this.rmiserver.destroy ();
    }
 
+   @Override
    protected Naming getNamingProxy() throws Exception
    {
-      Class clazz;
-      LoadBalancePolicy policy;
-      
-      rmiserver = new HARMIServerImpl(clusterPartition, replicantName, Naming.class,
-         theServer, rmiPort, clientSocketFactory, serverSocketFactory, bindAddress);
+      this.rmiserver = new HARMIServerImpl(this.clusterPartition, this.replicantName, Naming.class,
+         this.theServer, this.rmiPort, this.clientSocketFactory, this.serverSocketFactory, this.bindAddress);
 
       ClassLoader cl = Thread.currentThread().getContextClassLoader();
-      clazz = cl.loadClass(loadBalancePolicy);
-      policy = (LoadBalancePolicy)clazz.newInstance();
+      Class<?> clazz = cl.loadClass(this.loadBalancePolicy);
+      LoadBalancePolicy policy = (LoadBalancePolicy)clazz.newInstance();
 
-      Naming proxy = (Naming) rmiserver.createHAStub(policy);
+      Naming proxy = (Naming) this.rmiserver.createHAStub(policy);
       return proxy;
    }
 }

Modified: trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java	2008-06-17 21:33:25 UTC (rev 74735)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java	2008-06-17 21:36:48 UTC (rev 74736)
@@ -21,14 +21,13 @@
   */
 package org.jboss.ha.jndi;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Vector;
 
 import javax.naming.Binding;
 import javax.naming.Context;
@@ -64,82 +63,84 @@
    static final long serialVersionUID = 6342802270002172451L;
 
    private static final NamingParser parser = new NamingParser();
-   private final Fqn m_root;
+   private final Fqn<String> m_root;
    
    // Attributes --------------------------------------------------------
    private static Logger log = Logger.getLogger(TreeHead.class);
 
-   private Cache m_cache;
+   private Cache<String, Binding> m_cache;
    
    private transient HAPartition partition;
    private transient HAJNDI father;
 
    // Constructor --------------------------------------------------------
   
-   public TreeHead (Cache cache, Fqn root)
-      throws NamingException
+   public TreeHead(Cache<String, Binding> cache, Fqn<String> root)
    {
       super();
-      m_cache = cache;
-      m_root = root;
+      this.m_cache = cache;
+      this.m_root = root;
    }
 
    // Public --------------------------------------------------------
 
-   public void init() throws Exception
+   public void init()
    {
       log.debug("HAJNDI registering RPC Handler with HAPartition");
-      partition.registerRPCHandler("HAJNDI", this);
+      this.partition.registerRPCHandler("HAJNDI", this);
       log.debug("initializing HAJNDITreeCache root");
-      putTreeRoot();
+      this.putTreeRoot();
    }
 
-   public void stop() throws Exception
+   public void stop()
    {
       
    }
 
-   public void destroy() throws Exception
+   public void destroy()
    {
       log.debug("HAJNDI unregistering RPCHandler with HAPartition");
-      partition.unregisterRPCHandler("HAJNDI", this);
+      this.partition.unregisterRPCHandler("HAJNDI", this);
    }
 
-   public void setPartition (HAPartition partition)
+   public void setPartition(HAPartition partition)
    {
       this.partition = partition;
    }
 
-   public void setHARMIHead (HAJNDI father)
+   public void setHARMIHead(HAJNDI father)
    {
       this.father = father;
    }
 
    // Naming implementation -----------------------------------------
   
-   public void bind(Name name, Object obj, String className)
-      throws NamingException
+   public void bind(Name name, Object obj, String className) throws NamingException
    {
-      if( log.isTraceEnabled() )
+      if (log.isTraceEnabled())
+      {
          log.trace("bind, name="+name);
+      }
       
-      internalBind(name, obj, className, false);
+      this.internalBind(name, obj, className, false);
    }
    
-   public void rebind(Name name, Object obj, String className)
-      throws NamingException
+   public void rebind(Name name, Object obj, String className) throws NamingException
    {
-      if( log.isTraceEnabled() )
+      if (log.isTraceEnabled())
+      {
          log.trace("rebind, name="+name);
+      }
 
-      internalBind(name, obj, className, true);
+      this.internalBind(name, obj, className, true);
    }
 
-   public void unbind(Name name)
-      throws NamingException
+   public void unbind(Name name) throws NamingException
    {
-      if( log.isTraceEnabled() )
+      if (log.isTraceEnabled())
+      {
          log.trace("unbind, name="+name);
+      }
       if (name.isEmpty())
       {
          // Empty names are not allowed
@@ -149,130 +150,131 @@
       // is the name a context?
       try
       {
-         Fqn temp = new Fqn(m_root, Fqn.fromString(name.toString()));
+         Fqn<String> temp = new Fqn<String>(this.m_root, Fqn.fromString(name.toString()));
          // TODO why not jst call remove -- why hasChild first?
-         if (m_cache.getRoot().hasChild(temp))
+         if (this.m_cache.getRoot().hasChild(temp))
          {
-            m_cache.removeNode(temp);
+            this.m_cache.removeNode(temp);
             return;
          }
-      } catch (CacheException ce)
+      }
+      catch (CacheException ce)
       {
-         // don't chain CacheException since JBoss Cache may not be on remote client's classpath 
+         // don't chain CacheException since JBoss Cache may not be on remote client's classpath
          NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
          ne.setStackTrace(ce.getStackTrace());
          throw ne;
       }
       
-      int size = name.size(); 
+      int size = name.size();
       
       // get the context and key
-      Fqn ctx;
+      Fqn<String> ctx;
       String key = name.get(size - 1);
       if (size > 1) // find subcontext to which the key is bound
-      {  
+      {
          String prefix = name.getPrefix(size - 1).toString();
-         Fqn fqn = Fqn.fromString(prefix);
-         ctx = new Fqn(m_root, fqn); 
+         Fqn<String> fqn = Fqn.fromString(prefix);
+         ctx = new Fqn<String>(this.m_root, fqn);
       }
       else
-         ctx = m_root;
+      {
+         ctx = this.m_root;
+      }
       
       try
       {
-         Object removed = m_cache.remove(ctx, key);
+         Object removed = this.m_cache.remove(ctx, key);
          if (removed == null)
          {
-            if (!m_cache.getRoot().hasChild(ctx))
+            if (!this.m_cache.getRoot().hasChild(ctx))
             {
-               throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
+                throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
             }
-            else
-            {
-               throw new NameNotFoundException(key + " not bound");
-            }
+
+            throw new NameNotFoundException(key + " not bound");
          }
-      } catch (CacheException ce)
+      }
+      catch (CacheException ce)
       {
-         // don't chain CacheException since JBoss Cache may not be on remote client's classpath 
+         // don't chain CacheException since JBoss Cache may not be on remote client's classpath
          NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
          ne.setStackTrace(ce.getStackTrace());
          throw ne;
       }
    }
    
-   public Object lookup(Name name)
-      throws NamingException
+   public Object lookup(Name name) throws NamingException
    {
       boolean trace = log.isTraceEnabled();
-      if( trace )
+      if (trace)
+      {
          log.trace("lookup, name="+name);
+      }
    
-      Object result = null;
       if (name.isEmpty())
       {
-         // Return this      
-         return new NamingContext(null, (Name)(parser.parse("")), getRoot());
+         // Return this
+         return new NamingContext(null, parser.parse(""), this.getRoot());
       }
 
       // is the name a context?
       try
       {
-         Node n = m_cache.getRoot().getChild(new Fqn(m_root, Fqn.fromString(name.toString())));
+         Node<String, Binding> n = this.m_cache.getRoot().getChild(new Fqn<String>(this.m_root, Fqn.fromString(name.toString())));
          if (n != null)
          {
-            Name fullName = (Name)(name.clone());
-            return new NamingContext(null, fullName, getRoot());
+            Name fullName = (Name) name.clone();
+            return new NamingContext(null, fullName, this.getRoot());
          }
-      } catch (CacheException ce)
+      }
+      catch (CacheException ce)
       {
-         // don't chain CacheException since JBoss Cache may not be on remote client's classpath 
+         // don't chain CacheException since JBoss Cache may not be on remote client's classpath
          NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
          ne.setStackTrace(ce.getStackTrace());
          throw ne;
       }
    
-      int size = name.size(); 
+      int size = name.size();
    
       // get the context and key
-      Fqn ctx;
+      Fqn<String> ctx;
       String key = name.get(size - 1);
       if (size > 1) // find subcontext to which the key is bound
-      {  
+      {
          String prefix = name.getPrefix(size - 1).toString();
-         Fqn fqn = Fqn.fromString(prefix);
-         ctx = new Fqn(m_root, fqn); 
+         Fqn<String> fqn = Fqn.fromString(prefix);
+         ctx = new Fqn<String>(this.m_root, fqn);
       }
       else
-         ctx = m_root;
+      {
+         ctx = this.m_root;
+      }
    
       try
       {
-         Binding b = (Binding)m_cache.get(ctx, key);
-         if (b != null)
-         {
-            result = b.getObject();
-         }
-         else
-         {
-            // key not in cache, try local naming server
-            result = internalLookupLocally(name);
-         }
-      } catch (CacheException ce)
+         Binding b = this.m_cache.get(ctx, key);
+         
+         // if key not in cache, try local naming server
+         return (b != null) ? b.getObject() : this.internalLookupLocally(name);
+      }
+      catch (CacheException ce)
       {
-         // don't chain CacheException since JBoss Cache may not be on remote client's classpath 
+         // don't chain CacheException since JBoss Cache may not be on remote client's classpath
          NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
          ne.setStackTrace(ce.getStackTrace());
          throw ne;
       }
-      return result;
    }
 
    public Object lookupLocally(Name name) throws NamingException
    {
       boolean trace = log.isTraceEnabled();
-      if( trace )
+      if (trace)
+      {
          log.trace("lookupLocally, name="+name);
+      }
 
       // TODO: This is a really big hack here
       // We cannot do InitialContext().lookup(name) because
@@ -284,16 +286,15 @@
          {
             return NamingContext.localServer.lookup(name);
          }
-         else
-         {
-            InitialContext ctx = new InitialContext();
-            return ctx.lookup(name);
-         }
+
+         return new InitialContext().lookup(name);
       }
       catch (NamingException e)
       {
-         if( trace )
+         if (trace)
+         {
             log.trace("lookupLocally failed, name=" + name, e);
+         }
          throw e;
       }
       catch (java.rmi.RemoteException e)
@@ -301,230 +302,244 @@
          NamingException ne = new NamingException("unknown remote exception");
          ne.setRootCause(e);
          if( trace )
+         {
             log.trace("lookupLocally failed, name=" + name, e);
+         }
          throw ne;
       }
       catch (RuntimeException e)
       {
-         if( trace )
+         if (trace)
+         {
             log.trace("lookupLocally failed, name=" + name, e);
+         }
          throw e;
       }
    }
    
-   public Collection list(Name name)
-      throws NamingException
+   public Collection<NameClassPair> list(Name name) throws NamingException
    {
-      if( log.isTraceEnabled() )
+      if (log.isTraceEnabled())
+      {
          log.trace("list, name="+name);
-      Collection result = null;
+      }
    
       // get the context
-      Fqn ctx;
+      Fqn<String> ctx;
       String ctxName = "";
       int size = name.size();
       if (size >= 1)
-      {  
+      {
          ctxName = name.toString();
-         Fqn fqn = Fqn.fromString(ctxName);
-         ctx = new Fqn(m_root, fqn); 
+         Fqn<String> fqn = Fqn.fromString(ctxName);
+         ctx = new Fqn<String>(this.m_root, fqn);
       }
       else
-         ctx = m_root;
+      {
+         ctx = this.m_root;
+      }
       
-      boolean exists = m_cache.getRoot().hasChild(ctx);
+      boolean exists = this.m_cache.getRoot().hasChild(ctx);
       if (!exists)
-      {  
+      {
          try
          {
-            return enum2list(new InitialContext().list(name));
-         } catch (NamingException e)
+            return Collections.list(new InitialContext().list(name));
+         }
+         catch (NamingException e)
          {
             throw new NotContextException(ctxName+ " not a context");
          }
       }
-         
-      Vector list = null;
+      
       try
       {
-         list = new Vector();
+         List<NameClassPair> list = new LinkedList<NameClassPair>();
 
-         Node base = m_cache.getRoot().getChild(ctx);
+         Node<String, Binding> base = this.m_cache.getRoot().getChild(ctx);
          if (base != null)
          {
-            Map data = base.getData();
-            for (Iterator it = data.values().iterator(); it.hasNext();)
-            {               
-               Binding b = (Binding) it.next();
-               list.addElement(new NameClassPair(b.getName(),b.getClassName(),true));
+            for (Binding b: base.getData().values())
+            {
+               list.add(new NameClassPair(b.getName(),b.getClassName(),true));
             }
             
-            Set children = base.getChildrenNames();
+            // Why doesn't this return Set<String>?
+            Set<Object> children = base.getChildrenNames();
             if (children != null && !children.isEmpty())
             {
-               Iterator iter2 = children.iterator();
-               while (iter2.hasNext()) {
-                   String node = (String)iter2.next();
-                   Name fullName = (Name)(name.clone());
-                   fullName.add(node);
-                   list.addElement(new NameClassPair(node, NamingContext.class.getName(),true));
+               for (Object child: children)
+               {
+                  String node = (String) child;
+                  Name fullName = (Name) name.clone();
+                  fullName.add(node);
+                  list.add(new NameClassPair(node, NamingContext.class.getName(),true));
                }
             }
          }
-      } catch (CacheException ce)
+         
+         return list;
+      }
+      catch (CacheException ce)
       {
-         // don't chain CacheException since JBoss Cache may not be on remote client's classpath 
+         // don't chain CacheException since JBoss Cache may not be on remote client's classpath
          NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
          ne.setStackTrace(ce.getStackTrace());
          throw ne;
       }
-      return list;
    }
 
-   public Collection listBindings(Name name)
-      throws NamingException
+   public Collection<Binding> listBindings(Name name) throws NamingException
    {
-      if( log.isTraceEnabled() )
+      if (log.isTraceEnabled())
+      {
          log.trace("listBindings, name="+name);
+      }
       
       // get the context
-      Fqn ctx;
+      Fqn<String> ctx;
       String ctxName = "";
       int size = name.size();
       if (size >= 1)
-      {  
+      {
          ctxName = name.toString();
-         Fqn fqn = Fqn.fromString(ctxName);
-         ctx = new Fqn(m_root, fqn); 
+         Fqn<String> fqn = Fqn.fromString(ctxName);
+         ctx = new Fqn<String>(this.m_root, fqn);
       }
       else
-         ctx = m_root;
+      {
+         ctx = this.m_root;
+      }
       
-      boolean exists = m_cache.getRoot().hasChild(ctx);
+      boolean exists = this.m_cache.getRoot().hasChild(ctx);
       if (!exists)
       {
          // not found in global jndi, look in local.
          try
          {
-            return enum2list(new InitialContext().listBindings(name));
-         } catch (NamingException e)
+            return Collections.list(new InitialContext().listBindings(name));
+         }
+         catch (NamingException e)
          {
             throw new NotContextException(ctxName+ " not a context");
          }
       }
-         
-      Vector list = null;
+      
       try
       {
-         list = new Vector();
+         List<Binding> list = new LinkedList<Binding>();
          
-         Node node = m_cache.getRoot().getChild(ctx);
+         Node<String, Binding> node = this.m_cache.getRoot().getChild(ctx);
          if (node != null)
          {
-            Map data = node.getData();
-            if (data != null && data.size() > 0)
+            Map<String, Binding> data = node.getData();
+            if (data != null && !data.isEmpty())
             {
                list.addAll(data.values());
             }
             
-            Set children = node.getChildrenNames();
+            // Why doesn't this return Set<String>?
+            Set<Object> children = node.getChildrenNames();
             if (children != null && !children.isEmpty())
             {
-               Iterator iter2 = children.iterator();
-               while (iter2.hasNext()) {
-                   String child = (String)iter2.next();
-                   Name fullName = (Name)(name.clone());
-                   fullName.add(child);
-                   NamingContext subCtx = new NamingContext(null, fullName, getRoot());
-                   Binding b = new Binding(child, NamingContext.class.getName(), subCtx, true);
-                   list.addElement(b);
+               for (Object obj: children)
+               {
+                  String child = (String) obj;
+                  Name fullName = (Name) name.clone();
+                  fullName.add(child);
+                  NamingContext subCtx = new NamingContext(null, fullName, this.getRoot());
+                  list.add(new Binding(child, NamingContext.class.getName(), subCtx, true));
                }
             }
          }
-      } catch (CacheException ce)
+         
+         return list;
+      }
+      catch (CacheException ce)
       {
-         // don't chain CacheException since JBoss Cache may not be on remote client's classpath 
+         // don't chain CacheException since JBoss Cache may not be on remote client's classpath
          NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
          ne.setStackTrace(ce.getStackTrace());
          throw ne;
       }
-      return list;
    }
 
-   public javax.naming.Context createSubcontext(Name name)
-      throws NamingException
+   public Context createSubcontext(Name name) throws NamingException
    {
+      if (log.isTraceEnabled())
+      {
+         log.trace("createSubcontext, name="+name);
+      }
       
-      if( log.isTraceEnabled() )
-         log.trace("createSubcontext, name="+name);
       int size = name.size();
-      if( size == 0 )
+      
+      if (size == 0)
+      {
          throw new InvalidNameException("Cannot pass an empty name to createSubcontext");
+      }
 
-     Context subCtx = null;
-     
-     // does the new context already exist?
-     String str = name.toString();
-     Fqn fqn = Fqn.fromString(str);
-     Fqn ctx = new Fqn(m_root, fqn);
-     if (m_cache.getRoot().hasChild(ctx))
-     {
-        throw new NameAlreadyBoundException();
-     }
-     
-     // does the prefix context already exist?
-     Fqn pctx;
-     String newctx = name.get(size - 1);
-     if (size > 1) // find subcontext to which the context will be added
-     {  
-        String prefix = name.getPrefix(size - 1).toString();
-        Fqn fqn2 = Fqn.fromString(prefix);
-        pctx = new Fqn(m_root, fqn2); 
-     }
-     else
-        pctx = m_root;
-     
-     boolean exists = m_cache.getRoot().hasChild(pctx);
-     if (!exists)
-     {
-        throw new NotContextException(name.getPrefix(size - 1).toString());
-     }
+      // does the new context already exist?
+      String str = name.toString();
+      Fqn<String> fqn = Fqn.fromString(str);
+      Fqn<String> ctx = new Fqn<String>(this.m_root, fqn);
+      if (this.m_cache.getRoot().hasChild(ctx))
+      {
+         throw new NameAlreadyBoundException();
+      }
+      
+      // does the prefix context already exist?
+      Fqn<String> pctx;
+      String newctx = name.get(size - 1);
+      if (size > 1) // find subcontext to which the context will be added
+      {
+         String prefix = name.getPrefix(size - 1).toString();
+         Fqn<String> fqn2 = Fqn.fromString(prefix);
+         pctx = new Fqn<String>(this.m_root, fqn2);
+      }
+      else
+      {
+         pctx = this.m_root;
+      }
+      
+      boolean exists = this.m_cache.getRoot().hasChild(pctx);
+      if (!exists)
+      {
+         throw new NotContextException(name.getPrefix(size - 1).toString());
+      }
 
-     Fqn newf = new Fqn(pctx, Fqn.fromString(newctx));
-     try
-     {
-        m_cache.put(newf, new HashMap());
-     } catch (CacheException ce)
-     {
-        // don't chain CacheException since JBoss Cache may not be on remote client's classpath 
-        NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
-        ne.setStackTrace(ce.getStackTrace());
-        throw ne;
-     }
+      Fqn<String> newf = new Fqn<String>(pctx, Fqn.fromString(newctx));
+      try
+      {
+         this.m_cache.put(newf, new HashMap<String, Binding>());
+      }
+      catch (CacheException ce)
+      {
+         // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+         NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
+         ne.setStackTrace(ce.getStackTrace());
+         throw ne;
+      }
    
-     Name fullName = (Name) parser.parse("");
-     fullName.addAll(name);
-     subCtx = new NamingContext(null, fullName, getRoot());
-
-     return subCtx;
+      Name fullName = parser.parse("");
+      fullName.addAll(name);
+      
+      return new NamingContext(null, fullName, this.getRoot());
    }
 
-   public Naming getRoot ()
+   public Naming getRoot()
    {
-      return father.getHAStub();
+      return this.father.getHAStub();
    }
    
-   private void putTreeRoot()
-      throws CacheException
-   {         
-      if (!m_cache.getRoot().hasChild(m_root))
-      {   
-         m_cache.put(m_root, null);
+   private void putTreeRoot() throws CacheException
+   {
+      if (!this.m_cache.getRoot().hasChild(this.m_root))
+      {
+         this.m_cache.put(this.m_root, null);
       }
-   }   
+   }
   
-   private void internalBind(Name name, Object obj, String className, boolean rebind)
-      throws NamingException
+   private void internalBind(Name name, Object obj, String className, boolean rebind) throws NamingException
    {
       if (name.isEmpty())
       {  // Empty names are not allowed
@@ -532,76 +547,78 @@
       }
 
       int size = name.size();
-     
+      
       // get the context and key
-      Fqn ctx;
+      Fqn<String> ctx;
       String key = name.get(size - 1);
       if (size > 1) // find subcontext to which the key will be added
-      {  
+      {
          String prefix = name.getPrefix(size - 1).toString();
-         Fqn fqn = Fqn.fromString(prefix);
-         ctx = new Fqn(m_root, fqn); 
+         Fqn<String> fqn = Fqn.fromString(prefix);
+         ctx = new Fqn<String>(this.m_root, fqn);
       }
       else
-         ctx = m_root;
+      {
+         ctx = this.m_root;
+      }
    
-      boolean exists = m_cache.getRoot().hasChild(ctx);
+      boolean exists = this.m_cache.getRoot().hasChild(ctx);
       if (!exists)
       {
          throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
-         // note - NamingServer throws a CannotProceedException if the client attempts to bind 
+         // note - NamingServer throws a CannotProceedException if the client attempts to bind
          //        to a Reference object having an "nns" address.  This implementation simply
          //        throws the NotContextException that's used when "nns" isn't present.
       }
       if (!rebind)
       {
-         Node node = m_cache.getRoot().getChild(ctx);
-         if (node != null && (node.get(key) != null))
+         Node<String, Binding> node = this.m_cache.getRoot().getChild(ctx);
+         if ((node != null) && (node.get(key) != null))
          {
             throw new NameAlreadyBoundException(key);
          }
       }
-      try {
-         m_cache.put(ctx, key, new Binding(key, className, obj, true));
-      }
-      catch (Exception e)
-      {
-         System.out.println(e.toString());
-      }     
+      
+      this.m_cache.put(ctx, key, new Binding(key, className, obj, true));
    }
 
-   private Object internalLookupLocally(Name name)
-      throws NamingException
+   private Object internalLookupLocally(Name name) throws NamingException
    {
       boolean trace = log.isTraceEnabled();
-      Object result = null;
+
       try
       {
          // not found in global jndi, look in local.
-         result = lookupLocally(name);
+         return this.lookupLocally(name);
       }
       catch (NameNotFoundException nnfe)
       {
          // if we get here, this means we need to try on every node.
          Object[] args = new Object[1];
          args[0] = name;
-         List rsp = null;
+         List<?> rsp = null;
          Exception cause = null;
          try
          {
-            if( trace )
+            if (trace)
+            {
                log.trace("calling lookupLocally(" + name + ") on HAJNDI cluster");
-            rsp = partition.callMethodOnCluster("HAJNDI", "lookupLocally", args, new Class[]{Name.class}, true);
+            }
+            rsp = this.partition.callMethodOnCluster("HAJNDI", "lookupLocally", args, new Class[] { Name.class }, true);
          }
          catch (Exception ignored)
          {
-            if( trace )               
+            if (trace)
+            {
                log.trace("Clustered lookupLocally("+name+") failed", ignored);
+            }
             cause = ignored;
          }
 
-         if( trace )
+         if (trace)
+         {
             log.trace("Returned results size: "+ (rsp != null ? rsp.size() : 0));
+         }
          if (rsp == null || rsp.size() == 0)
          {
             NameNotFoundException nnfe2 = new NameNotFoundException(name.toString());
@@ -611,33 +628,19 @@
 
          for (int i = 0; i < rsp.size(); i++)
          {
-            result = rsp.get(i);
-            if( trace )
+            Object result = rsp.get(i);
+            if (trace)
             {
                String type = (result != null ? result.getClass().getName() : "null");
                log.trace("lookupLocally, i="+i+", value="+result+", type="+type);
             }
             // Ignore null and Exception return values
-            if ( result != null && !(result instanceof Exception) )
+            if ((result != null) && !(result instanceof Exception))
+            {
                return result;
+            }
          }
          throw nnfe;
       }
-      return result;
    }
-   
-   private ArrayList enum2list (javax.naming.NamingEnumeration en)
-   {
-      ArrayList rtn = new ArrayList();
-      try
-      {
-         while (en.hasMore())
-         {
-            rtn.add(en.next());
-         }
-         en.close();
-      }
-      catch (NamingException ignored) {}
-      return rtn;
-   }
 }




More information about the jboss-cvs-commits mailing list