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

Elias Ross genman at noderunner.net
Sun Nov 19 22:53:55 EST 2006


  User: genman  
  Date: 06/11/19 22:53:55

  Modified:    src/org/jboss/cache/optimistic   WorkspaceNode.java
                        WorkspaceNodeImpl.java
  Log:
  JBCACHE-867, Move methods from the ProxyImpl to Node, refactor Node classes as well
  
  Revision  Changes    Path
  1.15      +5 -4      JBossCache/src/org/jboss/cache/optimistic/WorkspaceNode.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WorkspaceNode.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/optimistic/WorkspaceNode.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- WorkspaceNode.java	18 Aug 2006 15:40:40 -0000	1.14
  +++ WorkspaceNode.java	20 Nov 2006 03:53:55 -0000	1.15
  @@ -6,10 +6,11 @@
    */
   package org.jboss.cache.optimistic;
   
  -import org.jboss.cache.DataNode;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.TreeNode;
  +import org.jboss.cache.Node;
   import org.jboss.cache.Fqn;
  -import org.jboss.cache.TreeCache;
  +import org.jboss.cache.Cache;
   
   import java.util.Map;
   import java.util.Set;
  @@ -35,7 +36,7 @@
   
       public Map getMergedData();
   
  -    public DataNode getNode();
  +    public Node getNode();
   
       public Set getChildrenNames();
   
  @@ -49,5 +50,5 @@
   
       public void markAsCreated();
   
  -    public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent, TreeCache cache, DataVersion version);
  +    public Node createChild(Object child_name, Fqn fqn, Node parent, CacheSPI cache, DataVersion version);
   }
  
  
  
  1.27      +154 -52   JBossCache/src/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WorkspaceNodeImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/optimistic/WorkspaceNodeImpl.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -b -r1.26 -r1.27
  --- WorkspaceNodeImpl.java	20 Sep 2006 16:28:58 -0000	1.26
  +++ WorkspaceNodeImpl.java	20 Nov 2006 03:53:55 -0000	1.27
  @@ -6,17 +6,22 @@
    */
   package org.jboss.cache.optimistic;
   
  -import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.Cache;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.DataNode;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.GlobalTransaction;
  +import org.jboss.cache.Node;
  +import org.jboss.cache.NodeNotExistsException;
  +import org.jboss.cache.NodeSPI;
   import org.jboss.cache.OptimisticTreeNode;
   import org.jboss.cache.TreeCache;
   import org.jboss.cache.TreeNode;
   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.TimeoutException;
   
  @@ -25,6 +30,7 @@
   import java.util.HashSet;
   import java.util.Map;
   import java.util.Set;
  +import java.util.concurrent.ConcurrentHashMap;
   
   /**
    * Wraps a DataNode and adds versioning and other meta data to it.
  @@ -32,39 +38,24 @@
    * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
    * @author Steve Woodcock (<a href="mailto:stevew at jofti.com">stevew at jofti.com</a>)
    */
  -public class WorkspaceNodeImpl implements WorkspaceNode
  +public class WorkspaceNodeImpl implements WorkspaceNode, NodeSPI
   {
   
      private static Log log = LogFactory.getLog(WorkspaceNodeImpl.class);
   
  -   private DataNode node;
  +   private Node node;
      private TransactionWorkspace workspace;
      private DataVersion version = DefaultDataVersion.ZERO;
      private boolean deleted;
      private boolean dirty;
      private boolean created;
  -   private Map optimisticChildNodeMap;
  +   private Map<Object, Node> optimisticChildNodeMap;
      private Map optimisticDataMap;
   
  -   public WorkspaceNodeImpl()
  -   {
  -      this(new OptimisticTreeNode(), null);
  -   }
  -
      /**
       * Constructs with a node and workspace.
  -    *
  -    * @deprecated
       */
  -   public WorkspaceNodeImpl(TreeNode node, TransactionWorkspace workspace)
  -   {
  -      this((DataNode) node, workspace);
  -   }
  -
  -   /**
  -    * Constructs with a node and workspace.
  -    */
  -   public WorkspaceNodeImpl(DataNode node, TransactionWorkspace workspace)
  +   public WorkspaceNodeImpl(Node node, TransactionWorkspace workspace)
      {
         if (!(node instanceof OptimisticTreeNode))
         {
  @@ -72,20 +63,11 @@
         }
         this.node = node;
         this.workspace = workspace;
  -      optimisticDataMap = node.getData();
  -      if (optimisticDataMap == null)
  -      {
  -         optimisticDataMap = new HashMap();
  -      }
  -      if (node.getChildren() == null)
  -      {
  -         optimisticChildNodeMap = new ConcurrentReaderHashMap(0);
  -      }
  -      else
  -      {
  -         optimisticChildNodeMap = new ConcurrentReaderHashMap(node.getChildren());
  -      }
  +      optimisticDataMap = new HashMap(node.getNodeSPI().getRawData());
  +      optimisticChildNodeMap = new ConcurrentHashMap(node.getNodeSPI().getChildrenMap());
         this.version = ((OptimisticTreeNode) node).getVersion();
  +      if (version == null)
  +         throw new IllegalStateException("OptimisticTreeNode version null");
      }
   
      /**
  @@ -172,13 +154,13 @@
      }
   
      //this needs to be changed to return wrapped node
  -   public TreeNode getParent()
  +   public Node getParent()
      {
         return node.getParent();
      }
   
      //this what the above method should look like
  -   public TreeNode getWrappedParent()
  +   public Node getWrappedParent()
      {
   
         //see if in the the transaction map
  @@ -192,12 +174,12 @@
         return workspaceNode;
      }
   
  -   public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent)
  +   public Node createChild(Object child_name, Fqn fqn, Node parent)
      {
         throw new UnsupportedOperationException("Unsupported for optimistic nodes");
      }
   
  -   public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent, TreeCache cache, DataVersion version)
  +   public Node createChild(Object child_name, Fqn fqn, Node parent, CacheSPI cache, DataVersion version)
      {
         if (child_name == null)
         {
  @@ -205,16 +187,12 @@
         }
   
         //see if we already have it
  -      TreeNode child = (TreeNode) optimisticChildNodeMap.get(child_name);
  +      Node child = optimisticChildNodeMap.get(child_name);
   
         // if not we need to create it
         if (child == null)
         {
  -         child = NodeFactory.getInstance().createNodeOfType(parent, child_name, fqn, parent, null, cache, version);
  -         if (optimisticChildNodeMap == Collections.EMPTY_MAP)
  -         {
  -            optimisticChildNodeMap = new ConcurrentReaderHashMap();
  -         }
  +         child = NodeFactory.getInstance().createNodeOfType(parent, child_name, fqn, parent, (Map)null, cache, version);
            optimisticChildNodeMap.put(child_name, child);
         }
         if (log.isTraceEnabled())
  @@ -228,14 +206,14 @@
      }
   
      //this needs to be changed to return wrapped node
  -   public TreeNode getChild(Object childName)
  +   public Node getChild(Object childName)
      {
         //see if in the the transaction map
  -      return (TreeNode) optimisticChildNodeMap.get(childName);
  +      return optimisticChildNodeMap.get(childName);
      }
   
      //this what the above method should be like
  -   public TreeNode getWrappedChild(Object fqn)
  +   public Node getWrappedChild(Object fqn)
      {
   
         //see if in the the transaction map
  @@ -254,7 +232,7 @@
         return wrapper;
      }
   
  -   public DataNode getNode()
  +   public Node getNode()
      {
         return node;
      }
  @@ -312,7 +290,7 @@
   
      public Object getName()
      {
  -      return node.getName();
  +      return node.getFqn().getLast();
      }
   
      public TransactionWorkspace getTransactionWorkspace()
  @@ -336,7 +314,7 @@
         return Collections.unmodifiableMap(optimisticDataMap);
      }
   
  -   public Map getChildren()
  +   public Map getChildrenMap()
      {
         return Collections.unmodifiableMap(optimisticChildNodeMap);
      }
  @@ -356,7 +334,7 @@
         throw new UnsupportedOperationException("Unsupported for optimistic nodes");
      }
   
  -   public IdentityLock getImmutableLock()
  +   public NodeLock getImmutableLock()
      {
         throw new UnsupportedOperationException("Unsupported for optimistic nodes");
      }
  @@ -406,7 +384,7 @@
         throw new UnsupportedOperationException("Unsupported for optimistic nodes");
      }
   
  -   public void addChild(Object child_name, TreeNode n)
  +   public void addChild(Object child_name, Node n)
      {
         throw new UnsupportedOperationException("Unsupported for optimistic nodes");
      }
  @@ -431,7 +409,7 @@
         throw new UnsupportedOperationException("Unsupported for optimistic nodes");
      }
   
  -   public Set acquireAll(Object caller, long timeout, DataNode.LockType lock_type) throws LockingException, TimeoutException, InterruptedException
  +   public Set acquireAll(Object caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException, InterruptedException
      {
         throw new UnsupportedOperationException("Unsupported for optimistic nodes");
      }
  @@ -475,4 +453,128 @@
         return
                 "WorkNode fqn=" + getFqn() + " " + sb + "ver=" + version;
      }
  +
  +   public Node addChild(Fqn f)
  +   {
  +      if (log.isTraceEnabled())
  +         log.trace("Adding child " + f + " to " + getFqn());
  +      CacheSPI cache = getCache();
  +      if (cache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
  +      {
  +         Node newNode = this;
  +         GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction();
  +
  +         if (f.size() == 1)
  +         {
  +            Fqn ffqn = new Fqn(getFqn(), f);
  +            newNode = createChild(f.get(0), ffqn, this.node, getCache(), version); 
  +         }
  +         else
  +         {
  +            // recursively create children
  +            Node currentParent = this;
  +            for (Object o : f.peekElements())
  +            {
  +               newNode = currentParent.getNodeSPI().getOrCreateChild(o, gtx);
  +               currentParent = newNode;
  +            }
  +         }
  +
  +         cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
  +         return newNode;
  +      }
  +      else
  +      {
  +         Fqn nf = new Fqn(getFqn(), f);
  +         cache.put(nf, Collections.emptyMap());
  +         return getChild(f);
  +      }
  +   }
  +
  +   public void clearData()
  +   {
  +      optimisticDataMap.clear();
  +   }
  +
  +   public Node getChild(Fqn f)
  +   {
  +      // ???
  +      return node.getChild(f);
  +   }
  +
  +   public Set<Node> getChildren()
  +   {
  +      throw new UnsupportedOperationException();      
  +      //return node.getChildren();
  +   }
  +
  +   public boolean hasChild(Fqn f)
  +   {
  +      throw new UnsupportedOperationException();      
  +      // TODO Auto-generated method stub
  +      // return false;
  +   }
  +
  +   public void move(Node newParent) throws NodeNotExistsException
  +   {
  +      throw new UnsupportedOperationException();      
  +      // TODO Auto-generated method stub
  +      
  +   }
  +
  +   public void putIfNull(Object k, Object v)
  +   {
  +      throw new UnsupportedOperationException();
  +      // TODO Auto-generated method stub
  +      
  +   }
  +
  +   public void putIfNull(Map m)
  +   {
  +      throw new UnsupportedOperationException();
  +      // TODO Auto-generated method stub
  +      
  +   }
  +
  +   public void removeChild(Fqn f)
  +   {
  +      throw new UnsupportedOperationException();
  +      // TODO Auto-generated method stub
  +   }
  +
  +   public void removeChildren()
  +   {
  +      throw new UnsupportedOperationException();
  +   }
  +
  +   public NodeSPI getNodeSPI()
  +   {
  +      return this; // node.getNodeSPI();
  +   }
  +
  +   public Node getOrCreateChild(Object name, GlobalTransaction tx)
  +   {
  +      throw new UnsupportedOperationException();      
  +   }
  +
  +   public void setCache(CacheSPI cache)
  +   {
  +      throw new UnsupportedOperationException();
  +   }
  +
  +   public CacheSPI getCache()
  +   {
  +      return node.getNodeSPI().getCache();
  +   }
  +
  +   public Map<Object, Object> getRawData()
  +   {
  +      throw new UnsupportedOperationException();
  +   }
  +
  +   public void setChildrenMap(Map<Object, Node> children)
  +   {
  +      throw new UnsupportedOperationException();      
  +   }
  +   
   }
  
  
  



More information about the jboss-cvs-commits mailing list