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

Manik Surtani msurtani at jboss.com
Fri Aug 25 12:30:46 EDT 2006


  User: msurtani
  Date: 06/08/25 12:30:46

  Modified:    src/org/jboss/cache    AbstractNode.java DataNode.java
                        NodeImpl.java
  Log:
  JBCACHE-651
  
  Revision  Changes    Path
  1.20      +42 -53    JBossCache/src/org/jboss/cache/AbstractNode.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AbstractNode.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/AbstractNode.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -r1.19 -r1.20
  --- AbstractNode.java	17 Aug 2006 17:34:59 -0000	1.19
  +++ AbstractNode.java	25 Aug 2006 16:30:46 -0000	1.20
  @@ -7,13 +7,14 @@
   import org.apache.commons.logging.LogFactory;
   
   import java.util.Collection;
  +import java.util.Collections;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  -import java.util.Collections;
   
   /**
    * Base class for {@link NodeImpl}.
  + *
    * @author manik
    */
   public abstract class AbstractNode implements DataNode
  @@ -24,7 +25,7 @@
      /**
       * Default output indent for printing.
       */
  -   protected static final int INDENT=4;
  +   protected static final int INDENT = 4;
   
      /**
       * Name of the node.
  @@ -59,8 +60,8 @@
   
      public TreeNode getChild(Object child_name)
      {
  -      if(child_name == null) return null;
  -      return children == null ? null : (DataNode)children.get(child_name);
  +      if (child_name == null) return null;
  +      return children == null ? null : (DataNode) children.get(child_name);
      }
   
      /**
  @@ -73,7 +74,7 @@
   
      public boolean childExists(Object child_name)
      {
  -      if(child_name == null) return false;
  +      if (child_name == null) return false;
         return children != null && children.containsKey(child_name);
      }
   
  @@ -99,63 +100,73 @@
   
      public void removeChild(Object child_name)
      {
  -      if(children != null)
  +      if (children != null)
         {
            children.remove(child_name);
  -         if(log.isTraceEnabled())
  +         if (log.isTraceEnabled())
  +         {
               log.trace("removed child " + child_name);
         }
      }
  +   }
   
      public void removeAllChildren()
      {
  -      if(children != null) children.clear();
  +      if (children != null) children.clear();
      }
   
      public void print(StringBuffer sb, int indent)
      {
         printIndent(sb, indent);
         sb.append(Fqn.SEPARATOR).append(getName());
  -      if(children != null && children.size() > 0) {
  -         Collection values=children.values();
  -         for(Iterator it=values.iterator(); it.hasNext();) {
  +      if (children != null && children.size() > 0)
  +      {
  +         Collection values = children.values();
  +         for (Iterator it = values.iterator(); it.hasNext();)
  +         {
               sb.append("\n");
  -            ((DataNode)it.next()).print(sb, indent + INDENT);
  +            ((DataNode) it.next()).print(sb, indent + INDENT);
            }
         }
      }
   
  -   public void printIndent(StringBuffer sb, int indent) {
  -      if(sb != null) {
  -         for(int i=0; i < indent; i++)
  +   public void printIndent(StringBuffer sb, int indent)
  +   {
  +      if (sb != null)
  +      {
  +         for (int i = 0; i < indent; i++)
  +         {
               sb.append(" ");
         }
      }
  +   }
   
      public void addChild(Object child_name, TreeNode n)
      {
  -      if(child_name != null)
  +      if (child_name != null)
  +      {
            children().put(child_name, n);
      }
  +   }
   
      /**
  -    * Returns null or the Map in use with the data.
  -    * This needs to be called with a lock if concurrency is a concern.
  +    * Returns null or the Map in use with the data. This needs to be called with a lock if concurrency is a concern.
       */
      protected final Map data()
      {
  -      if(data == null)
  -         data=new HashMap();
  +      if (data == null)
  +      {
  +         data = new HashMap();
  +      }
         return data;
      }
   
      /**
  -    * Override this if concurrent thread access may occur, in which case return
  -    * a concurrently modifiable Map.
  +    * Override this if concurrent thread access may occur, in which case return a concurrently modifiable Map.
       */
      protected Map children()
      {
  -      if(children == null) children=new HashMap();
  +      if (children == null) children = new HashMap();
         return children;
      }
   
  @@ -169,47 +180,25 @@
         indent += 2;   // increse it
         sb.append(Fqn.SEPARATOR).append(getName());
         sb.append("\n");
  -      if(map != null)
  +      if (map != null)
         {
  -         for(Iterator it=map.entrySet().iterator(); it.hasNext();)
  +         for (Iterator it = map.entrySet().iterator(); it.hasNext();)
            {
  -            entry=(Map.Entry)it.next();
  +            entry = (Map.Entry) it.next();
               sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
            }
         }
  -      if(children != null && children.size() > 0)
  +      if (children != null && children.size() > 0)
         {
  -         Collection values=children.values();
  -         for(Iterator it=values.iterator(); it.hasNext();)
  +         Collection values = children.values();
  +         for (Iterator it = values.iterator(); it.hasNext();)
            {
               sb.append("\n");
  -            ((DataNode)it.next()).printDetails(sb, indent);
  +            ((DataNode) it.next()).printDetails(sb, indent);
            }
         }
      }
   
  -   public abstract Object clone() throws CloneNotSupportedException;
  -
  -   /** Comment out for now.
  -   public void relocate(DataNode newParentNode, Fqn newFqn)
  -   {
  -      Object child = fqn.get(fqn.size()-1);
  -      // get rid of parent's children map entry
  -      getParent().removeChild(child);
  -
  -      this.fqn = newFqn;
  -      // reset parent
  -      parent = newParentNode;
  -      parent.addChild(child, this);
  +   public abstract DataNode clone() throws CloneNotSupportedException;
   
  -      Iterator it = children().keySet().iterator();
  -      while(it.hasNext())
  -      {
  -         Object key = it.next();
  -         Fqn childFqn = new Fqn(fqn, key);
  -         DataNode node = (DataNode)children.get(key);
  -         node.relocate(this, childFqn);
  -      }
  -   }
  -   */
   }
  
  
  
  1.17      +13 -7     JBossCache/src/org/jboss/cache/DataNode.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DataNode.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/DataNode.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -b -r1.16 -r1.17
  --- DataNode.java	14 Aug 2006 17:52:35 -0000	1.16
  +++ DataNode.java	25 Aug 2006 16:30:46 -0000	1.17
  @@ -13,18 +13,24 @@
    * Represents a DataNode in the cache.
    * 
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  - *
    */
   public interface DataNode extends TreeNode
   {
   
  -   public enum LockType {NONE, READ, WRITE};
  +   public enum LockType
  +   {
  +      NONE, READ, WRITE}
  +
  +   ;
   
  -   /** Initialized property for debugging "print_lock_details" */
  +   /**
  +    * Initialized property for debugging "print_lock_details"
  +    */
      boolean PRINT_LOCK_DETAILS = Boolean.getBoolean("print_lock_details");
   
      /**
       * Returns true if a lock is acquired.
  +    *
       * @param lock_acquisition_timeout milliseconds to wait
       * @param lockTypeWrite lock type to use
       */
  @@ -35,6 +41,6 @@
      /**
       * Returns a copy of this node.
       */
  -   Object clone() throws CloneNotSupportedException;
  +   DataNode clone() throws CloneNotSupportedException;
   
   }
  
  
  
  1.7       +289 -207  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.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- NodeImpl.java	25 Aug 2006 14:10:09 -0000	1.6
  +++ NodeImpl.java	25 Aug 2006 16:30:46 -0000	1.7
  @@ -15,31 +15,24 @@
   import org.jboss.cache.lock.LockingException;
   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;
  -import org.jboss.cache.marshall.MethodCall;
   
  -import java.io.Externalizable;
  -import java.io.IOException;
  -import java.io.ObjectInput;
  -import java.io.ObjectOutput;
   import java.util.Collection;
  +import java.util.Collections;
   import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
  -import java.util.Collections;
   
   /**
    * Basic data node class.
    */
  -public class NodeImpl extends AbstractNode implements Externalizable
  +public class NodeImpl extends AbstractNode
   {
   
  -   /** The serialVersionUID */
  -   private static final long serialVersionUID = -5040432493172658796L;
  -
      private static Log log = LogFactory.getLog(NodeImpl.class);
   
      /**
  @@ -48,14 +41,13 @@
      private static boolean trace = log.isTraceEnabled();
   
      /**
  -    * True if all children have been loaded.
  -    * This is set when TreeCache.getChildrenNames() is called.
  +    * True if all children have been loaded. This is set when TreeCache.getChildrenNames() is called.
       */
  -   private boolean children_loaded=false;
  +   private boolean children_loaded = false;
   
      /**
  -    * Lock manager that manages locks to be acquired when accessing the node
  -    * inside a transaction. Lazy set just in case locking is not needed.
  +    * Lock manager that manages locks to be acquired when accessing the node inside a transaction. Lazy set just in case
  +    * locking is not needed.
       */
      private IdentityLock lock_ = null;
   
  @@ -67,41 +59,51 @@
      /**
       * Construct an empty node; used by serialization.
       */
  -   public NodeImpl() {
  +   public NodeImpl()
  +   {
      }
   
      /**
       * Constructs a new node with a name, etc.
       */
  -   public NodeImpl(Object child_name, Fqn fqn, NodeImpl parent, Map data, TreeCache cache) {
  +   public NodeImpl(Object child_name, Fqn fqn, NodeImpl parent, Map data, TreeCache cache)
  +   {
         init(child_name, fqn, cache);
  -      if (data != null) {
  +      if (data != null)
  +      {
            this.data().putAll(data);
         }
      }
   
      /**
       * Constructs a new node with a name, etc.
  -    * @param mapSafe <code>true</code> if param <code>data</code> can safely be 
  -    *                directly assigned to this object's {@link #data} field;
  -    *                <code>false</code> if param <code>data</code>'s contents
  -    *                should be copied into this object's {@link #data} field.
  +    *
  +    * @param mapSafe <code>true</code> if param <code>data</code> can safely be directly assigned to this object's
  +    *                {@link #data} field; <code>false</code> if param <code>data</code>'s contents should be copied into
  +    *                this object's {@link #data} field.
       */
      public NodeImpl(Object child_name, Fqn fqn, NodeImpl parent, Map data, boolean mapSafe,
  -                   TreeCache cache) {
  +                   TreeCache cache)
  +   {
         init(child_name, fqn, cache);
  -      if (data != null) {
  +      if (data != null)
  +      {
            if (mapSafe)
  +         {
               this.data = data;
  +         }
            else
  +         {
               this.data().putAll(data);
         }
      }
  +   }
   
      /**
       * Constructs a new node with a single key and value.
       */
  -   public NodeImpl(Object child_name, Fqn fqn, NodeImpl parent, Object key, Object value, TreeCache cache) {
  +   public NodeImpl(Object child_name, Fqn fqn, NodeImpl parent, Object key, Object value, TreeCache cache)
  +   {
         init(child_name, fqn, cache);
         data().put(key, value);
      }
  @@ -109,14 +111,19 @@
      /**
       * Initializes with a name and FQN and cache.
       */
  -   protected final void init(Object child_name, Fqn fqn, TreeCache cache) {
  +   protected final void init(Object child_name, Fqn fqn, TreeCache cache)
  +   {
         if (cache == null)
  +      {
            throw new IllegalArgumentException("no cache init for " + fqn);
  +      }
         this.cache = cache;
  -      this.fqn=fqn;
  +      this.fqn = fqn;
         if (!fqn.isRoot() && !child_name.equals(fqn.getLast()))
  +      {
            throw new IllegalArgumentException("Child " + child_name + " must be last part of " + fqn);
      }
  +   }
   
      /**
       * Returns a parent by checking the TreeMap by name.
  @@ -124,63 +131,83 @@
      public TreeNode getParent()
      {
         if (fqn.isRoot())
  +      {
            return null;
  +      }
         return cache.peek(fqn.getParent());
      }
   
  -   private synchronized void initLock() {
  +   private synchronized void initLock()
  +   {
         if (lock_ == null)
  +      {
            lock_ = new IdentityLock(cache, fqn);
      }
  +   }
   
  -   protected synchronized Map children() {
  -      if (children == null) {
  -          if (getFqn().isRoot()) {
  +   protected synchronized Map children()
  +   {
  +      if (children == null)
  +      {
  +         if (getFqn().isRoot())
  +         {
                 children = new ConcurrentReaderHashMap(64);
  -          } else {
  +         }
  +         else
  +         {
                 children = new ConcurrentReaderHashMap(4);
             }
         }
         return children;
      }
   
  -   private void setTreeCacheInstance(TreeCache cache) {
  +   private void setTreeCacheInstance(TreeCache cache)
  +   {
         this.cache = cache;
         this.lock_ = null;
      }
   
      /**
  -    * Set the tree cache instance recursively down to the children as well.
  -    * Note that this method is not currently thread safe.
  +    * Set the tree cache instance recursively down to the children as well. Note that this method is not currently
  +    * thread safe.
       */
  -   public void setRecursiveTreeCacheInstance(TreeCache cache) {
  +   public void setRecursiveTreeCacheInstance(TreeCache cache)
  +   {
   
         setTreeCacheInstance(cache);
   
  -      if(children != null) {
  -         for(Iterator it = children.keySet().iterator(); it.hasNext(); ) {
  -            DataNode nd = (DataNode)children.get(it.next());
  +      if (children != null)
  +      {
  +         for (Iterator it = children.keySet().iterator(); it.hasNext();)
  +         {
  +            DataNode nd = (DataNode) children.get(it.next());
               nd.setRecursiveTreeCacheInstance(cache);
            }
         }
      }
   
  -   public boolean getChildrenLoaded() {
  +   public boolean getChildrenLoaded()
  +   {
         return children_loaded;
      }
   
  -   public void setChildrenLoaded(boolean flag) {
  -      children_loaded=flag;
  +   public void setChildrenLoaded(boolean flag)
  +   {
  +      children_loaded = flag;
      }
   
  -   public Object get(Object key) {
  -      synchronized(this) {
  -         return data == null? null : data.get(key);
  +   public Object get(Object key)
  +   {
  +      synchronized (this)
  +      {
  +         return data == null ? null : data.get(key);
         }
      }
   
  -   public boolean containsKey(Object key) {
  -      synchronized(this) {
  +   public boolean containsKey(Object key)
  +   {
  +      synchronized (this)
  +      {
            return data != null && data.containsKey(key);
         }
      }
  @@ -188,92 +215,121 @@
       /**
        * Returns the data keys, or an empty set if there are no keys.
        */
  -   public Set getDataKeys() {
  -      synchronized(this) {
  +   public Set getDataKeys()
  +   {
  +      synchronized (this)
  +      {
            if (data == null) return Collections.emptySet();
            return data.keySet();
         }
      }
   
  -   boolean isReadLocked() {
  +   boolean isReadLocked()
  +   {
         return lock_ != null && lock_.isReadLocked();
      }
   
  -   boolean isWriteLocked() {
  +   boolean isWriteLocked()
  +   {
         return lock_ != null && lock_.isWriteLocked();
      }
   
  -   public boolean isLocked() {
  +   public boolean isLocked()
  +   {
         return isWriteLocked() || isReadLocked();
      }
   
      /**
       * @deprecated Use getLock() instead
       */
  -   public IdentityLock getImmutableLock() {
  +   public IdentityLock getImmutableLock()
  +   {
         initLock();
         return lock_;
      }
   
  -   public IdentityLock getLock() {
  +   public IdentityLock getLock()
  +   {
         initLock();
         return lock_;
      }
   
  -   public Map getData() {
  -      synchronized(this) {
  -         if(data == null)
  +   public Map getData()
  +   {
  +      synchronized (this)
  +      {
  +         if (data == null)
  +         {
               return null;
  +         }
            return new HashMap(data);
         }
      }
   
  -   public int numAttributes() {
  -      synchronized(this) {
  -         return data != null? data.size() : 0;
  +   public int numAttributes()
  +   {
  +      synchronized (this)
  +      {
  +         return data != null ? data.size() : 0;
         }
      }
   
  -   public void put(Map data, boolean erase) {
  -      synchronized(this) {
  -         if(erase) {
  -            if(this.data != null)
  +   public void put(Map data, boolean erase)
  +   {
  +      synchronized (this)
  +      {
  +         if (erase)
  +         {
  +            if (this.data != null)
  +            {
                  this.data.clear();
            }
  -         if(data == null) return;
  +         }
  +         if (data == null) return;
            this.data().putAll(data);
         }
      }
   
  -   public Object put(Object key, Object value) {
  -      synchronized(this) {
  +   public Object put(Object key, Object value)
  +   {
  +      synchronized (this)
  +      {
            return this.data().put(key, value);
         }
      }
   
  -   public TreeNode getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean createIfNotExists) {
  +   public TreeNode getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean createIfNotExists)
  +   {
         DataNode child;
         if (child_name == null)
  +      {
            throw new IllegalArgumentException("null child name");
  +      }
   
  -      child = (DataNode)children().get(child_name);
  -      if (createIfNotExists && child == null) {
  +      child = (DataNode) children().get(child_name);
  +      if (createIfNotExists && child == null)
  +      {
            // construct the new child outside the synchronized block to avoid
            // spending any more time than necessary in the synchronized section
            Fqn child_fqn = new Fqn(this.fqn, child_name);
  -         DataNode newChild = (DataNode)NodeFactory.getInstance().createNode(child_name, child_fqn, this, null, cache);
  +         DataNode newChild = (DataNode) NodeFactory.getInstance().createNode(child_name, child_fqn, this, null, cache);
            if (newChild == null)
  +         {
               throw new IllegalStateException();
  -         synchronized(this) {
  +         }
  +         synchronized (this)
  +         {
                // check again to see if the child exists
                // after acquiring exclusive lock
  -             child = (NodeImpl)children().get(child_name);
  -             if (child == null) {
  +            child = (NodeImpl) children().get(child_name);
  +            if (child == null)
  +            {
                    cache.getNotifier().notifyNodeCreated(child.getFqn(), true);
                    child = newChild;
                    children.put(child_name, child);
  -                 if(gtx != null) {
  -                     MethodCall undo_op=MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal,
  +               if (gtx != null)
  +               {
  +                  MethodCall undo_op = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal,
                                                          new Object[]{gtx, child_fqn, Boolean.FALSE});
                        cache.addUndoOperation(gtx, undo_op);
                        // add the node name to the list maintained for the current tx
  @@ -284,8 +340,10 @@
            }
   
            // notify if we actually created a new child
  -         if (newChild == child) {
  -             if (trace) {
  +         if (newChild == child)
  +         {
  +            if (trace)
  +            {
                    log.trace("created child: fqn=" + child_fqn);
                }
                cache.getNotifier().notifyNodeCreated(child.getFqn(), false);
  @@ -295,55 +353,68 @@
   
      }
   
  -   public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent) {
  +   public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent)
  +   {
         return getOrCreateChild(child_name, null, true);
      }
   
  -   public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent, Object key, Object value) {
  +   public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent, Object key, Object value)
  +   {
         TreeNode n = getOrCreateChild(child_name, null, true);
         n.put(key, value);
         return n;
      }
   
  -   public Object remove(Object key) {
  -      synchronized(this) {
  -         return data != null?  data.remove(key) : null;
  +   public Object remove(Object key)
  +   {
  +      synchronized (this)
  +      {
  +         return data != null ? data.remove(key) : null;
         }
      }
   
  -   public void clear() {
  -      synchronized(this) {
  -         if(data != null) {
  +   public void clear()
  +   {
  +      synchronized (this)
  +      {
  +         if (data != null)
  +         {
               data.clear();
  -            data=null;
  +            data = null;
            }
         }
      }
   
  -   public void printDetails(StringBuffer sb, int indent) {
  +   public void printDetails(StringBuffer sb, int indent)
  +   {
         Map tmp;
  -      synchronized(this) {
  -         tmp=data != null? new HashMap(data) : null;
  +      synchronized (this)
  +      {
  +         tmp = data != null ? new HashMap(data) : null;
         }
         printDetailsInMap(sb, indent, tmp);
      }
   
  -   public void printLockInfo(StringBuffer sb, int indent) {
  -      boolean locked=lock_ != null && lock_.isLocked();
  +   public void printLockInfo(StringBuffer sb, int indent)
  +   {
  +      boolean locked = lock_ != null && lock_.isLocked();
   
         printIndent(sb, indent);
         sb.append(Fqn.SEPARATOR).append(getName());
  -      if(locked) {
  +      if (locked)
  +      {
            sb.append("\t(");
            lock_.toString(sb);
            sb.append(")");
         }
   
  -      if(children != null && children.size() > 0) {
  -         Collection values=children.values();
  -         for(Iterator it=values.iterator(); it.hasNext();) {
  +      if (children != null && children.size() > 0)
  +      {
  +         Collection values = children.values();
  +         for (Iterator it = values.iterator(); it.hasNext();)
  +         {
               sb.append("\n");
  -            ((DataNode)it.next()).printLockInfo(sb, indent + INDENT);
  +            ((DataNode) it.next()).printLockInfo(sb, indent + INDENT);
            }
         }
      }
  @@ -351,175 +422,186 @@
      /**
       * Returns a debug string.
       */
  -   public String toString() {
  -      StringBuffer sb=new StringBuffer();
  +   public String toString()
  +   {
  +      StringBuffer sb = new StringBuffer();
         sb.append("\nfqn=" + fqn);
  -      synchronized (this) {
  -         if(data != null)
  +      synchronized (this)
  +      {
  +         if (data != null)
  +         {
               sb.append("\ndata=" + data);
         }
  -      if (lock_ != null) {
  +      }
  +      if (lock_ != null)
  +      {
            sb.append("\n read locked=").append(isReadLocked());
            sb.append("\n write locked=").append(isWriteLocked());
         }
         return sb.toString();
      }
   
  -   public Object clone() throws CloneNotSupportedException {
  -      DataNode parent = (DataNode)getParent();
  -      DataNode n = (DataNode)NodeFactory.getInstance().createNode(getName(), fqn, parent != null ? (DataNode) parent.clone() : null, data, cache);
  -      n.setChildren(children == null? null : (HashMap)((HashMap)children).clone());
  +   public DataNode clone() throws CloneNotSupportedException
  +   {
  +      DataNode parent = (DataNode) getParent();
  +      DataNode n = (DataNode) NodeFactory.getInstance().createNode(getName(), fqn, parent != null ? (DataNode) parent.clone() : null, data, cache);
  +      n.setChildren(children == null ? null : (HashMap) ((HashMap) children).clone());
         return n;
      }
   
  -   public boolean acquire(Object caller, long timeout, DataNode.LockType lock_type) throws LockingException, TimeoutException, InterruptedException {
  +   public boolean acquire(Object caller, long timeout, DataNode.LockType lock_type) throws LockingException, TimeoutException, InterruptedException
  +   {
         // Note that we rely on IdentityLock for synchronization
  -      try {
  -         if(lock_type == DataNode.LockType.NONE)
  +      try
  +      {
  +         if (lock_type == DataNode.LockType.NONE)
  +         {
               return true;
  -         else if(lock_type == DataNode.LockType.READ)
  +         }
  +         else if (lock_type == DataNode.LockType.READ)
  +         {
               return acquireReadLock(caller, timeout);
  +         }
            else
  +         {
               return acquireWriteLock(caller, timeout);
         }
  -      catch(UpgradeException e) {
  +      }
  +      catch (UpgradeException e)
  +      {
            StringBuffer buf = new StringBuffer("failure upgrading lock: fqn=").append(fqn).append(", caller=").append(caller).
                     append(", lock=").append(lock_.toString(true));
  -         if(trace)
  +         if (trace)
  +         {
               log.trace(buf.toString());
  +         }
            throw new UpgradeException(buf.toString(), e);
         }
  -      catch(LockingException e) {
  +      catch (LockingException e)
  +      {
            StringBuffer buf = new StringBuffer("failure acquiring lock: fqn=").append(fqn).append(", caller=").append(caller).
                     append(", lock=").append(lock_.toString(true));
  -         if(trace)
  +         if (trace)
  +         {
               log.trace(buf.toString());
  +         }
            throw new LockingException(buf.toString(), e);
         }
  -      catch(TimeoutException e) {
  +      catch (TimeoutException e)
  +      {
            StringBuffer buf = new StringBuffer("failure acquiring lock: fqn=").append(fqn).append(", caller=").append(caller).
                     append(", lock=").append(lock_.toString(true));
  -         if(trace)
  +         if (trace)
  +         {
               log.trace(buf.toString());
  +         }
            throw new TimeoutException(buf.toString(), e);
         }
      }
   
  -   protected boolean acquireReadLock(Object caller, long timeout) throws LockingException, TimeoutException, InterruptedException {
  +   protected boolean acquireReadLock(Object caller, long timeout) throws LockingException, TimeoutException, InterruptedException
  +   {
         initLock();
  -      if(trace) {
  +      if (trace)
  +      {
            log.trace(new StringBuffer("acquiring RL: fqn=").append(fqn).append(", caller=").append(caller).
                  append(", lock=").append(lock_.toString(DataNode.PRINT_LOCK_DETAILS)));
         }
  -      boolean flag=lock_.acquireReadLock(caller, timeout);
  -      if(trace) {
  +      boolean flag = lock_.acquireReadLock(caller, timeout);
  +      if (trace)
  +      {
            log.trace(new StringBuffer("acquired RL: fqn=").append(fqn).append(", caller=").append(caller).
                  append(", lock=").append(lock_.toString(DataNode.PRINT_LOCK_DETAILS)));
         }
         return flag;
      }
   
  -   protected boolean acquireWriteLock(Object caller, long timeout) throws LockingException, TimeoutException, InterruptedException {
  +   protected boolean acquireWriteLock(Object caller, long timeout) throws LockingException, TimeoutException, InterruptedException
  +   {
         initLock();
  -      if(trace) {
  +      if (trace)
  +      {
            log.trace(new StringBuffer("acquiring WL: fqn=").append(fqn).append(", caller=").append(caller).
                  append(", lock=").append(lock_.toString(DataNode.PRINT_LOCK_DETAILS)));
         }
  -      boolean flag=lock_.acquireWriteLock(caller, timeout);
  -      if(trace) {
  +      boolean flag = lock_.acquireWriteLock(caller, timeout);
  +      if (trace)
  +      {
            log.trace(new StringBuffer("acquired WL: fqn=").append(fqn).append(", caller=").append(caller).
                  append(", lock=").append(lock_.toString(DataNode.PRINT_LOCK_DETAILS)));
         }
         return flag;
      }
   
  -   public Set acquireAll(Object caller, long timeout, DataNode.LockType lock_type) throws LockingException, TimeoutException, InterruptedException {
  +   public Set acquireAll(Object caller, long timeout, DataNode.LockType lock_type) throws LockingException, TimeoutException, InterruptedException
  +   {
         DataNode tmp;
         boolean acquired;
  -      Set retval=new HashSet();
  +      Set retval = new HashSet();
   
  -      if(lock_type == DataNode.LockType.NONE)
  +      if (lock_type == DataNode.LockType.NONE)
  +      {
            return retval;
  -      acquired=acquire(caller, timeout, lock_type);
  -      if(acquired)
  +      }
  +      acquired = acquire(caller, timeout, lock_type);
  +      if (acquired)
  +      {
            retval.add(getLock());
  +      }
   
  -      if(children != null) {
  -         for(Iterator it=children.values().iterator(); it.hasNext();) {
  -            tmp=(DataNode)it.next();
  +      if (children != null)
  +      {
  +         for (Iterator it = children.values().iterator(); it.hasNext();)
  +         {
  +            tmp = (DataNode) it.next();
               retval.addAll(tmp.acquireAll(caller, timeout, lock_type));
            }
         }
         return retval;
      }
   
  -   public void release(Object caller) {
  +   public void release(Object caller)
  +   {
         if (lock_ != null)
  +      {
            lock_.release(caller);
      }
  +   }
   
  -   public void releaseForce() {
  +   public void releaseForce()
  +   {
         if (lock_ != null)
  +      {
            lock_.releaseForce();
      }
  +   }
   
  -   public void releaseAll(Object owner) {
  +   public void releaseAll(Object owner)
  +   {
         DataNode tmp;
  -      if(children != null) {
  -         for(Iterator it=children.values().iterator(); it.hasNext();) {
  -            tmp=(DataNode)it.next();
  +      if (children != null)
  +      {
  +         for (Iterator it = children.values().iterator(); it.hasNext();)
  +         {
  +            tmp = (DataNode) it.next();
               tmp.releaseAll(owner);
            }
         }
         release(owner);
      }
   
  -   public void releaseAllForce() {
  +   public void releaseAllForce()
  +   {
         DataNode tmp;
  -      if(children != null) {
  -         for(Iterator it=children.values().iterator(); it.hasNext();) {
  -            tmp=(DataNode)it.next();
  +      if (children != null)
  +      {
  +         for (Iterator it = children.values().iterator(); it.hasNext();)
  +         {
  +            tmp = (DataNode) it.next();
               tmp.releaseAllForce();
            }
         }
         releaseForce();
      }
  -
  -   /**
  -    * Serializes this object to ObjectOutput.
  -    * Writes the {@link Fqn} elements, children as a Map, and data as a Map.
  -    * (This is no longer used within JBoss Cache.)
  -    * @see org.jboss.cache.marshall.TreeCacheMarshaller
  -    */
  -   public void writeExternal(ObjectOutput out) throws IOException {
  -      // DO NOT CHANGE THE WIRE FORMAT OF THIS CLASS!!
  -      // The whole purpose of implementing writeExternal() is to
  -      // exchange data with 1.2.3 versions of JBC.  Either the wire
  -      // format stays the same, or we don't bother implementing Externalizable
  -      out.writeObject(getName());
  -      out.writeObject(fqn);
  -      out.writeObject(getParent());
  -      out.writeObject(children);
  -      synchronized(this) {
  -         out.writeObject(data);
  -      }
  -   }
  -
  -   /**
  -    * Deserializes this object from ObjectInput.
  -    * (This is no longer used within JBoss Cache.)
  -    */
  -   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  -      in.readObject(); // "name", which we discard
  -      fqn = (Fqn) in.readObject();
  -      in.readObject(); // "parent", which we discard
  -      children = (Map)in.readObject();
  -      data=(Map)in.readObject();
  -      // Note that we don't have a cache at this point, so our LockStrategy
  -      // is going to be configured based on whatever LockStrategyFactory's
  -      // static isolationLevel_ field is set to. This gets overridden
  -      // whenever a cache is assigned via setTreeCacheInstance
  -   }
  -
   }
   
  
  
  



More information about the jboss-cvs-commits mailing list