[jboss-cvs] JBossCache/src/org/jboss/cache ...

Manik Surtani manik at jboss.org
Fri Jun 29 13:40:49 EDT 2007


  User: msurtani
  Date: 07/06/29 13:40:49

  Modified:    src/org/jboss/cache    CacheImpl.java UnversionedNode.java
                        NodeSPI.java
  Log:
  JBCACHE-1116 and JBCACHE-1117
  
  Revision  Changes    Path
  1.97      +69 -67    JBossCache/src/org/jboss/cache/CacheImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -b -r1.96 -r1.97
  --- CacheImpl.java	28 Jun 2007 16:53:35 -0000	1.96
  +++ CacheImpl.java	29 Jun 2007 17:40:49 -0000	1.97
  @@ -76,7 +76,6 @@
   import java.util.ArrayList;
   import java.util.Collections;
   import java.util.HashSet;
  -import java.util.Iterator;
   import java.util.LinkedList;
   import java.util.List;
   import java.util.Map;
  @@ -1829,18 +1828,8 @@
      {
         if (fqn == null) return false;
   
  -      NodeSPI n = root;
  -      Object obj;
  -      for (int i = 0; i < fqn.size(); i++)
  -      {
  -         obj = fqn.get(i);
  -         n = n.getChildDirect(obj);
  -         if (n == null)
  -         {
  -            return false;
  -         }
  -      }
  -      return !n.getChildrenMapDirect().isEmpty();
  +      NodeSPI n = findNode(fqn);
  +      return n != null && n.hasChildrenDirect();
      }
   
      /**
  @@ -2920,7 +2909,20 @@
               NodeSPI backupSubtree = findNode(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
               if (backupSubtree != null)
               {
  -               Map children = backupSubtree.getChildrenMapDirect();
  +               // need to loop through backupSubtree's children
  +               Set childNames = backupSubtree.getChildrenNamesDirect();
  +               if (childNames != null)
  +               {
  +                  for (Object childName : childNames)
  +                  {
  +                     // childName is the name of a buddy group since all child names in this
  +                     // collection are direct children of BUDDY_BACKUP_SUBTREE_FQN
  +                     backupNodeFqn = BuddyManager.getBackupFqn(childName.toString(), fqn);
  +                     actualNode = findNode(backupNodeFqn);
  +                     if (actualNode == null) break;
  +                  }
  +               }
  +               /*Map children = backupSubtree.getChildrenMapDirect();
                  if (children != null)
                  {
                     Iterator childNames = children.keySet().iterator();
  @@ -2929,7 +2931,7 @@
                        backupNodeFqn = BuddyManager.getBackupFqn(childNames.next().toString(), fqn);
                        actualNode = findNode(backupNodeFqn);
                     }
  -               }
  +               }*/
               }
            }
   
  
  
  
  1.31      +65 -9     JBossCache/src/org/jboss/cache/UnversionedNode.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UnversionedNode.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/UnversionedNode.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -b -r1.30 -r1.31
  --- UnversionedNode.java	18 Jun 2007 16:23:22 -0000	1.30
  +++ UnversionedNode.java	29 Jun 2007 17:40:49 -0000	1.31
  @@ -18,6 +18,7 @@
   
   import java.io.Serializable;
   import java.util.AbstractSet;
  +import java.util.Collection;
   import java.util.Collections;
   import java.util.HashMap;
   import java.util.HashSet;
  @@ -71,6 +72,8 @@
       * Map of general data keys to values.
       */
      private final Map<K, V> data = new HashMap<K, V>();
  +   // set reference to a ChildrenNames instance
  +   private Set<Object> childrenNames;
   
      /**
       * Constructs a new node with an FQN of Root.
  @@ -413,7 +416,19 @@
   
      public Set<Object> getChildrenNamesDirect()
      {
  -      return Collections.unmodifiableSet(new HashSet(new ChildrenNames()));
  +      return childrenNames();
  +   }
  +
  +   private Set<Object> childrenNames()
  +   {
  +      if (childrenNames == null)
  +      {
  +         synchronized (this)
  +         {
  +            if (childrenNames == null) childrenNames = new ChildrenNames();
  +         }
  +      }
  +      return childrenNames;
      }
   
      public Set<K> getKeys()
  @@ -494,7 +509,7 @@
   
      public boolean removeChildDirect(Object childName)
      {
  -      return children().remove(childName) != null;
  +      return children != null && children.remove(childName) != null;
      }
   
      public boolean removeChildDirect(Fqn f)
  @@ -512,7 +527,7 @@
   
      public Map<Object, Node<K, V>> getChildrenMapDirect()
      {
  -      return new MapCopy<Object, Node<K, V>>(children());
  +      return children;
      }
   
      public void setChildrenMapDirect(Map<Object, Node<K, V>> children)
  @@ -666,6 +681,11 @@
         return Collections.unmodifiableSet(exclDeleted);
      }
   
  +   public boolean hasChildrenDirect()
  +   {
  +      return children != null && children.size() != 0;
  +   }
  +
      public Set<NodeSPI<K, V>> getChildrenDirect(boolean includeMarkedForRemoval)
      {
         if (includeMarkedForRemoval)
  @@ -759,13 +779,49 @@
            return children.size();
         }
   
  -      private Object writeReplace()
  +      @Override
  +      public boolean add(Object o)
         {
  -         if (children == null)
  +         throw new UnsupportedOperationException("Children names is a read-only set");
  +      }
  +
  +      @Override
  +      public boolean remove(Object o)
            {
  -            return Collections.emptySet();
  +         throw new UnsupportedOperationException("Children names is a read-only set");
            }
  -         return Collections.unmodifiableSet(new HashSet(children.keySet()));
  +
  +      @Override
  +      public boolean addAll(Collection coll)
  +      {
  +         throw new UnsupportedOperationException();
         }
  +
  +      @Override
  +      public boolean removeAll(Collection coll)
  +      {
  +         throw new UnsupportedOperationException();
  +      }
  +
  +      @Override
  +      public boolean retainAll(Collection coll)
  +      {
  +         throw new UnsupportedOperationException();
  +      }
  +
  +      @Override
  +      public void clear()
  +      {
  +         throw new UnsupportedOperationException();
  +      }
  +
  +//      private Object writeReplace()
  +//      {
  +//         if (children == null)
  +//         {
  +//            return Collections.emptySet();
  +//         }
  +//         return Collections.unmodifiableSet(new HashSet(children.keySet()));
  +//      }
      }
   }
  
  
  
  1.21      +8 -1      JBossCache/src/org/jboss/cache/NodeSPI.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeSPI.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/NodeSPI.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -b -r1.20 -r1.21
  --- NodeSPI.java	11 Jun 2007 15:06:02 -0000	1.20
  +++ NodeSPI.java	29 Jun 2007 17:40:49 -0000	1.21
  @@ -79,7 +79,9 @@
   
      /**
       * Returns a map to access the raw children.
  -    * This method will never return null.
  +    * This method may return a null if the node does not have any children.  It is important to note that this method
  +    * returns a direct reference to the underlying child map and is intended for internal use only.  Incorrect use
  +    * may result in very inconsistent state of the cache.
       *
       * @return Map, keyed by child name, values Nodes.
       */
  @@ -428,4 +430,9 @@
       * @see Node#getParent()
       */
      NodeSPI<K, V> getParent();
  +
  +   /**
  +    * @return true if the node has one or more child nodes; false otherwise.
  +    */
  +   boolean hasChildrenDirect();
   }
  
  
  



More information about the jboss-cvs-commits mailing list