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

Manik Surtani manik at jboss.org
Wed Mar 7 17:46:29 EST 2007


  User: msurtani
  Date: 07/03/07 17:46:29

  Modified:    src/org/jboss/cache/optimistic   Tag:
                        Branch_JBossCache_1_4_0 WorkspaceNodeImpl.java
                        WorkspaceNode.java
  Log:
  JBCACHE-961 - more sophisticated merging of child maps in workspace nodes backported to 1.4.x
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.21.2.6  +39 -11    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.21.2.5
  retrieving revision 1.21.2.6
  diff -u -b -r1.21.2.5 -r1.21.2.6
  --- WorkspaceNodeImpl.java	28 Feb 2007 10:58:41 -0000	1.21.2.5
  +++ WorkspaceNodeImpl.java	7 Mar 2007 22:46:29 -0000	1.21.2.6
  @@ -28,6 +28,8 @@
   import java.util.Set;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.List;
  +import java.util.ArrayList;
   
   /**
    * Wraps a DataNode and adds versioning and other meta data to it.
  @@ -49,7 +51,12 @@
       private boolean created;
       private Map optimisticChildNodeMap;
       private Map optimisticDataMap;
  -   private boolean versioningImplicit;
  +   private boolean versioningImplicit = true;
  +   private boolean childrenModified;
  +   private Set childrenAdded = new HashSet();
  +   private Set childrenRemoved = new HashSet();
  +   private static boolean trace = log.isTraceEnabled();
  +
   
       public WorkspaceNodeImpl() {
           this(new OptimisticTreeNode(), null);
  @@ -87,6 +94,12 @@
           this.version = ((OptimisticTreeNode) node).getVersion();
       }
   
  +
  +   public boolean isChildrenModified()
  +   {
  +      return childrenModified;
  +   }
  +
       /**
        * Returns true if this node is dirty.
        */
  @@ -165,9 +178,15 @@
   
       public void removeChild(Object childName)
       {
  -        // TODO: MANIK: Remove dirty=true, implement merging on child mods instead.
  -        dirty = true;
  -        optimisticChildNodeMap.remove(childName);
  +
  +        childrenModified = true;
  +        Object child = optimisticChildNodeMap.remove(childName);
  +       if (trace) log.trace("Removing child " + childName);
  +       if (child != null)
  +       {
  +         childrenRemoved.add(child);
  +         childrenAdded.remove(child);
  +       }
       }
   
       //this needs to be changed to return wrapped node
  @@ -214,11 +233,14 @@
               if (optimisticChildNodeMap == Collections.EMPTY_MAP)
                   optimisticChildNodeMap = new ConcurrentReaderHashMap();
               optimisticChildNodeMap.put(child_name, child);
  +           if (trace) log.trace("Adding child " + child_name);
  +           childrenAdded.add(child);
  +           childrenRemoved.remove(child);
           }
  -       // TODO: MANIK: Remove dirty=true, implement merging on child mods instead.
  -       dirty = true;
   
  -        if (log.isTraceEnabled()) log.trace("createChild: fqn=" + fqn + " for node " + this);
  +       childrenModified = true;
  +
  +        if (trace) log.trace("createChild: fqn=" + fqn + " for node " + this);
           return child;
   
       }
  @@ -275,10 +297,12 @@
           this.version = version;
       }
   
  -    public Map getMergedChildren()
  +    public List getMergedChildren()
       {
  -        //return mergeMaps((OptimisticMap) optimisticChildNodeMap);
  -        return optimisticChildNodeMap;
  + 	    List l = new ArrayList(2);
  + 	    l.add(childrenAdded);
  + 	    l.add(childrenRemoved);
  + 	    return l;
       }
   
   //    private Map mergeMaps(OptimisticMap opMap)
  @@ -604,6 +628,10 @@
   
       public void addChild(WorkspaceNode child)
       {
  +       if (trace) log.trace("Adding child " + child.getName());
          optimisticChildNodeMap.put(child.getName(), child.getNode());
  +       childrenAdded.add(child.getNode());
  +       childrenRemoved.remove(child.getNode());
  +       childrenModified = true;
       }
   }
  
  
  
  1.12.2.3  +33 -17    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.12.2.2
  retrieving revision 1.12.2.3
  diff -u -b -r1.12.2.2 -r1.12.2.3
  --- WorkspaceNode.java	28 Feb 2007 10:58:41 -0000	1.12.2.2
  +++ WorkspaceNode.java	7 Mar 2007 22:46:29 -0000	1.12.2.3
  @@ -13,6 +13,7 @@
   
   import java.util.Map;
   import java.util.Set;
  +import java.util.List;
   
   /**
    * Represents a type of {@link org.jboss.cache.Node} that is to be copied into a {@link TransactionWorkspace} for optimistically locked
  @@ -24,37 +25,52 @@
    */
   public interface WorkspaceNode extends TreeNode
   {
  -    public Map getMergedChildren();
  +   /**
  +    * @return Returns 2 Sets - a set of children added (first set) and a set of children removed.
  +    */
  +    List getMergedChildren();
   
  -    public DataVersion getVersion();
  +    DataVersion getVersion();
   
  -    public void setVersion(DataVersion version);
  +    void setVersion(DataVersion version);
   
  -    public Set getKeys();
  +    Set getKeys();
   
  -    public boolean isDirty();
  +   /**
  + 	 * Returns true if this node needs to be merged when the transaction commits.  A node is considered dirty if it
  + 	 * has just been created, deleted or it's data map has changed.  If children are added or removed, the node is not
  + 	 * considered dirty - instead, see {@link #isChildrenModified()}.
  +    *
  +    * @return true if needs merging, false otherwise.
  +    */
  +    boolean isDirty();
   
  -    public Map getMergedData();
  +    Map getMergedData();
   
  -    public DataNode getNode();
  +    DataNode getNode();
   
  -    public Set getChildrenNames();
  +    Set getChildrenNames();
   
  -    public boolean isDeleted();
  +    boolean isDeleted();
   
  -    public void markAsDeleted(boolean marker);
  +    void markAsDeleted(boolean marker);
   
  -    public TransactionWorkspace getTransactionWorkspace();
  +    TransactionWorkspace getTransactionWorkspace();
   
  -    public boolean isCreated();
  +    boolean isCreated();
   
  -    public void markAsCreated();
  +    void markAsCreated();
   
  -    public TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent, TreeCache cache, DataVersion version);
  +    TreeNode createChild(Object child_name, Fqn fqn, TreeNode parent, TreeCache cache, DataVersion version);
   
      boolean isVersioningImplicit();
   
      void setVersioningImplicit(boolean b);
   
      void addChild(WorkspaceNode workspaceNode);
  +
  +   /**
  + 	 * @return true if children have been added to or removed from this node.  Not the same as 'dirty'.
  + 	 */
  + 	boolean isChildrenModified();
   }
  
  
  



More information about the jboss-cvs-commits mailing list