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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Nov 18 06:33:02 EST 2006


Author: bstansberry at jboss.com
Date: 2006-11-18 06:33:01 -0500 (Sat, 18 Nov 2006)
New Revision: 58573

Modified:
   trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java
   trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java
Log:
Use JBC 2 API

Modified: trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java	2006-11-18 11:32:28 UTC (rev 58572)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java	2006-11-18 11:33:01 UTC (rev 58573)
@@ -29,7 +29,7 @@
 import org.jnp.interfaces.Naming;
 
 import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCacheMBean;
+import org.jboss.cache.Cache;
 import org.jboss.ha.framework.interfaces.HAPartition;
 import org.jboss.logging.Logger;
 
@@ -59,7 +59,7 @@
 
    // Constructor --------------------------------------------------------  
   
-   public HAJNDI(HAPartition partition, TreeCacheMBean cache)
+   public HAJNDI(HAPartition partition, Cache cache)
    throws NamingException
    {
       if (partition == null)

Modified: trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java	2006-11-18 11:32:28 UTC (rev 58572)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java	2006-11-18 11:33:01 UTC (rev 58573)
@@ -26,6 +26,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
 
@@ -40,10 +41,10 @@
 import javax.naming.NamingException;
 import javax.naming.NotContextException;
 
+import org.jboss.cache.Cache;
 import org.jboss.cache.CacheException;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
-import org.jboss.cache.TreeCacheMBean;
 import org.jboss.ha.framework.interfaces.HAPartition;
 import org.jboss.logging.Logger;
 import org.jnp.interfaces.Naming;
@@ -68,14 +69,14 @@
    // Attributes --------------------------------------------------------
    private static Logger log = Logger.getLogger(TreeHead.class);
 
-   private TreeCacheMBean m_cache;
+   private Cache m_cache;
    
    private transient HAPartition partition;
    private transient HAJNDI father;
 
    // Constructor --------------------------------------------------------
   
-   public TreeHead (TreeCacheMBean cache, Fqn root)
+   public TreeHead (Cache cache, Fqn root)
       throws NamingException
    {
       super();
@@ -149,9 +150,10 @@
       try
       {
          Fqn temp = new Fqn(m_root, Fqn.fromString(name.toString()));
-         if (m_cache.exists(temp))
+         // TODO why not jst call remove -- why hasChild first?
+         if (m_cache.hasChild(temp))
          {
-            m_cache.remove(temp);
+            m_cache.removeNode(temp);
             return;
          }
       } catch (CacheException ce)
@@ -175,20 +177,20 @@
       else
          ctx = m_root;
       
-      boolean exists = m_cache.exists(ctx);
-      if (!exists)
-      {
-         throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
-      }
-      
-      if (!m_cache.exists(ctx, key))
-      {
-         throw new NameNotFoundException(key + " not bound");
-      }
-      
       try
       {
-         m_cache.remove(ctx, key);
+         Object removed = m_cache.remove(ctx, key);
+         if (removed == null)
+         {
+            if (!m_cache.hasChild(ctx))
+            {
+               throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
+            }
+            else
+            {
+               throw new NameNotFoundException(key + " not bound");
+            }
+         }
       } catch (CacheException ce)
       {
          NamingException ne = new NamingException();
@@ -214,7 +216,7 @@
       // is the name a context?
       try
       {
-         Node n = m_cache.get(new Fqn(m_root, Fqn.fromString(name.toString())));
+         Node n = m_cache.getChild(new Fqn(m_root, Fqn.fromString(name.toString())));
          if (n != null)
          {
             Name fullName = (Name)(name.clone());
@@ -241,26 +243,18 @@
       else
          ctx = m_root;
    
-      boolean exists = m_cache.exists(ctx);
-      if (!exists)
-      {
-         // context not in cache, try local naming server
-         result = internalLookupLocally(name);
-         return result;
-      }
-   
-      if (!m_cache.exists(ctx, key))
-      {
-         // key not in cache, try local naming server
-         result = internalLookupLocally(name);
-         return result;
-      }
-   
       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)
       {
          NamingException ne = new NamingException();
@@ -334,7 +328,7 @@
       else
          ctx = m_root;
       
-      boolean exists = m_cache.exists(ctx);
+      boolean exists = m_cache.hasChild(ctx);
       if (!exists)
       {  
          try
@@ -347,33 +341,32 @@
       }
          
       Vector list = null;
-      Set keys;
       try
       {
          list = new Vector();
-         keys = m_cache.getKeys(ctx);
-         if  (keys != null && !keys.isEmpty())
-         {            
-            Iterator iter = keys.iterator();
-            while (iter.hasNext())
-            {  
-               String key = (String)iter.next();
-               Binding b = (Binding)m_cache.get(ctx, key);
-               list.addElement(new NameClassPair(b.getName(),b.getClassName(),true));
-            }
-         }
 
-         Set children = m_cache.getChildrenNames(ctx);
-         if (children != null && !children.isEmpty())
+         Node base = m_cache.getChild(ctx);
+         if (base != null)
          {
-            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));
+            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));
             }
-         }            
+            
+            Set 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));
+               }
+            }
+         }
       } catch (CacheException ce)
       {
          NamingException ne = new NamingException();
@@ -402,7 +395,7 @@
       else
          ctx = m_root;
       
-      boolean exists = m_cache.exists(ctx);
+      boolean exists = m_cache.hasChild(ctx);
       if (!exists)
       {
          // not found in global jndi, look in local.
@@ -416,33 +409,32 @@
       }
          
       Vector list = null;
-      Set keys;
       try
       {
          list = new Vector();
-         keys = m_cache.getKeys(ctx);
-         if  (keys != null && !keys.isEmpty())
-         {
-            Iterator iter = keys.iterator();
-            while (iter.hasNext())
-            {  
-               String key = (String)iter.next();
-               list.addElement(m_cache.get(ctx, key));
-            }
-         }
          
-         Set children = m_cache.getChildrenNames(ctx);
-         if (children != null && !children.isEmpty())
+         Node node = m_cache.getChild(ctx);
+         if (node != null)
          {
-            Iterator iter2 = children.iterator();
-            while (iter2.hasNext()) {
-                String node = (String)iter2.next();
-                Name fullName = (Name)(name.clone());
-                fullName.add(node);
-                NamingContext subCtx = new NamingContext(null, fullName, getRoot());
-                Binding b = new Binding(node, NamingContext.class.getName(), subCtx, true);
-                list.addElement(b);
+            Map data = node.getData();
+            if (data != null && data.size() > 0)
+            {
+               list.addAll(data.values());
             }
+            
+            Set 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);
+               }
+            }
          }
       } catch (CacheException ce)
       {
@@ -469,7 +461,7 @@
      String str = name.toString();
      Fqn fqn = Fqn.fromString(str);
      Fqn ctx = new Fqn(m_root, fqn);
-     if (m_cache.exists(ctx))
+     if (m_cache.hasChild(ctx))
      {
         throw new NameAlreadyBoundException();
      }
@@ -486,7 +478,7 @@
      else
         pctx = m_root;
      
-     boolean exists = m_cache.exists(pctx);
+     boolean exists = m_cache.hasChild(pctx);
      if (!exists)
      {
         throw new NotContextException(name.getPrefix(size - 1).toString());
@@ -518,7 +510,7 @@
    private void putTreeRoot()
       throws CacheException
    {         
-      if (!m_cache.exists(m_root))
+      if (!m_cache.hasChild(m_root))
       {   
          m_cache.put(m_root, null);
       }
@@ -546,7 +538,7 @@
       else
          ctx = m_root;
    
-      boolean exists = m_cache.exists(ctx);
+      boolean exists = m_cache.hasChild(ctx);
       if (!exists)
       {
          throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
@@ -556,7 +548,9 @@
       }
       if (!rebind)
       {
-         if (m_cache.exists(ctx, key)) {
+         Node node = m_cache.getChild(ctx);
+         if (node != null && (node.get(key) != null))
+         {
             throw new NameAlreadyBoundException(key);
          }
       }




More information about the jboss-cvs-commits mailing list