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

Manik Surtani msurtani at jboss.com
Mon Nov 27 11:15:44 EST 2006


  User: msurtani
  Date: 06/11/27 11:15:44

  Modified:    src/org/jboss/cache  NodeImpl.java
  Log:
  JBCACHE-872
  
  Revision  Changes    Path
  1.20      +107 -40   JBossCache/src/org/jboss/cache/NodeImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/NodeImpl.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- NodeImpl.java	26 Nov 2006 20:35:13 -0000	1.19
  +++ NodeImpl.java	27 Nov 2006 16:15:44 -0000	1.20
  @@ -10,10 +10,9 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.factories.NodeFactory;
   import org.jboss.cache.lock.IdentityLock;
  -import org.jboss.cache.lock.NodeLock;
   import org.jboss.cache.lock.LockingException;
  +import org.jboss.cache.lock.NodeLock;
   import org.jboss.cache.lock.TimeoutException;
  -import org.jboss.cache.lock.UpgradeException;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodCallFactory;
   import org.jboss.cache.marshall.MethodDeclarations;
  @@ -22,7 +21,6 @@
   import java.io.ObjectStreamException;
   import java.io.Serializable;
   import java.util.AbstractSet;
  -import java.util.Collection;
   import java.util.Collections;
   import java.util.HashMap;
   import java.util.HashSet;
  @@ -31,8 +29,6 @@
   import java.util.Set;
   import java.util.concurrent.ConcurrentHashMap;
   
  -import javax.naming.OperationNotSupportedException;
  -
   /**
    * Basic data node class.
    */
  @@ -109,8 +105,10 @@
            if (mapSafe)
            {
               if (data.getClass().getName().startsWith("java.util.Collections"))
  +            {
                  throw new IllegalArgumentException("What's this crap? " + data);
  -            this.data = data; // ? is this safe
  +            }
  +            this.data = data;// ? is this safe
            }
            else
            {
  @@ -204,14 +202,18 @@
      public synchronized Object get(Object key)
      {
         if (data == null)
  +      {
            return null;
  +      }
         return data.get(key);
      }
   
      public synchronized boolean containsKey(Object key)
      {
         if (data == null)
  +      {
            return false;
  +      }
         return data.containsKey(key);
      }
   
  @@ -272,9 +274,13 @@
         if (cache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
         {
            if (data == null)
  +         {
               return;
  +         }
            if (log.isTraceEnabled())
  +         {
               log.trace("put " + data.size() + " erase=" + erase);
  +         }
            synchronized (this)
            {
               if (erase)
  @@ -292,7 +298,9 @@
         {
            // TODO add erase option to Cache (?)
            if (erase)
  +         {
               ((TreeCacheProxyImpl) cache).treeCache.removeData(fqn);         
  +         }
            cache.put(fqn, data);
         }      
      }
  @@ -395,10 +403,14 @@
            synchronized (this)
            {
   			if (data == null)
  +            {
   			   result = null;
  +            }
   			else
  +            {
   			   result = data.remove(key);
            }
  +         }
            cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
            return result;
         }
  @@ -434,10 +446,14 @@
         if (lock_ != null)
         {
            if (isReadLocked())
  +         {
               sb.append(" RL");
  +         }
            if (isWriteLocked())
  +         {
               sb.append(" WL");
         }
  +      }
         sb.append("]");
         return sb.toString();
      }
  @@ -446,7 +462,17 @@
      {
         if (lock_ != null)
         {
  +         if (log.isTraceEnabled())
  +         {
  +            boolean wOwner = lock_.isWriteLocked() && lock_.getWriterOwner().equals(caller);
  +            log.trace("releasing " + (wOwner ? "WL" : "RL") + ": fqn=" + fqn + ", caller=" + caller);
  +         }
            lock_.release(caller);
  +         if (log.isTraceEnabled())
  +         {
  +            boolean wOwner = lock_.isWriteLocked() && lock_.getWriterOwner().equals(caller);
  +            log.trace("released " + (wOwner ? "WL" : "RL") + ": fqn=" + fqn + ", caller=" + caller);
  +         }
         }
      }
   
  @@ -460,8 +486,9 @@
   
      public void releaseAllForce()
      {
  -      for (Node n: children.values()) {
  -         ((NodeImpl)n).releaseAllForce();
  +      for (Node n : children.values())
  +      {
  +         ((NodeImpl) n).releaseAllForce();
         }
         releaseForce();
      }
  @@ -469,7 +496,9 @@
      public Node addChild(Fqn f)
      {
         if (log.isTraceEnabled())
  +      {
            log.trace("adding child " + f + " to " + getFqn());
  +      }
         if (cache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
         {
            Node newNode = this;
  @@ -508,9 +537,11 @@
   		 synchronized (this)
   		 {
   			if (data != null)
  +            {
   			   data.clear();
   		 }
         }
  +      }
         else
         {
   		 ((TreeCacheProxyImpl) cache).treeCache.removeData(getFqn());
  @@ -539,7 +570,9 @@
      public synchronized Set getKeys()
      {
         if (data == null)
  +      {
            return Collections.emptySet();
  +      }
         return Collections.unmodifiableSet(data.keySet());
      }
   
  @@ -551,7 +584,9 @@
      public void move(Node newParent) throws NodeNotExistsException
      {
         if (log.isTraceEnabled())
  +      {
            log.trace(this.getFqn() + " move to " + newParent.getFqn());
  +      }
         // TODO
         // move must be added to Cache
         ((TreeCacheProxyImpl) cache).treeCache.move(newParent.getFqn(), getFqn());
  @@ -560,14 +595,18 @@
      public void putIfNull(Object k, Object v)
      {
         if (cache.get(getFqn(), k) == null)
  +      {
            put(k, v);
      }
  +   }
   
      public void putIfNull(Map m)
      {
         if (getData().isEmpty())
  +      {
            put(m);
      }
  +   }
   
      public void removeChild(Fqn fqn)
      {
  @@ -622,7 +661,9 @@
      public void removeChildren()
      {
         if (children != null)
  +      {
            children.clear();
  +      }
         children = null;
      }
   
  @@ -630,10 +671,12 @@
      {
         printIndent(sb, indent);
         sb.append(Fqn.SEPARATOR).append(getName()).append(" ").append(getData().size());
  -      if (children != null) {
  -         for (Node node : children.values()) {
  +      if (children != null)
  +      {
  +         for (Node node : children.values())
  +         {
               sb.append("\n");
  -            ((TreeNode)node).print(sb, indent + INDENT);
  +            ((TreeNode) node).print(sb, indent + INDENT);
            }
         }
      }
  @@ -676,11 +719,15 @@
      public void setFqn(Fqn fqn)
      {
   	  if (log.isTraceEnabled()) 
  +      {
   		 log.trace(getFqn() + " set FQN " + fqn);
  +      }
         this.fqn = fqn;
   
   	  if (children == null)
  +      {
   		 return;
  +      }
   
         // process children
         for (Map.Entry<Object, Node> me : children.entrySet())
  @@ -694,14 +741,18 @@
      public TreeNode getChild(Object child_name)
      {
         if (child_name == null)
  +      {
            return null;
  +      }
         return children == null ? null : (DataNode) children.get(child_name);
      }
   
      public boolean childExists(Object child_name)
      {
         if (child_name == null)
  +      {
            return false;
  +      }
         return children != null && children.containsKey(child_name);
      }
   
  @@ -733,14 +784,18 @@
      protected void printDetailsInMap(StringBuffer sb, int indent)
      {
         printIndent(sb, indent);
  -      indent += 2; // increse it
  +      indent += 2;// increse it
         if (!(getFqn()).isRoot())
  +      {
            sb.append(Fqn.SEPARATOR);
  +      }
         sb.append(getName());
         sb.append("  ");
         sb.append(data());
  -      if (children != null) {
  -         for (Node n : children.values()) {
  +      if (children != null)
  +      {
  +         for (Node n : children.values())
  +         {
               sb.append("\n");
               ((DataNode) n).printDetails(sb, indent);
            }
  @@ -768,7 +823,9 @@
         public Iterator iterator()
         {
            if (children == null)
  +         {
               return Collections.emptySet().iterator();
  +         }
            return children.keySet().iterator();
         }
   
  @@ -776,7 +833,9 @@
         public boolean contains(Object o)
         {
            if (children == null)
  +         {
               return false;
  +         }
            return children.containsKey(o);
         }
   
  @@ -784,14 +843,18 @@
         public int size()
         {
            if (children == null)
  +         {
               return 0;
  +         }
            return children.size();
         }
   
         private Object writeReplace() throws ObjectStreamException
         {
            if (children == null)
  +         {
               return Collections.emptySet();
  +         }
            return Collections.unmodifiableSet(new HashSet(children.keySet()));
         }
   
  @@ -804,7 +867,9 @@
         public Iterator iterator()
         {
            if (children == null)
  +         {
               return Collections.emptySet().iterator();
  +         }
            return children.values().iterator();
         }
         
  @@ -818,7 +883,9 @@
         public int size()
         {
            if (children == null)
  +         {
               return 0;
  +         }
            return children.size();
         }
   
  
  
  



More information about the jboss-cvs-commits mailing list