[jboss-cvs] JBossCache/src/org/jboss/cache/optimistic ...
Manik Surtani
manik at jboss.org
Wed Mar 7 13:00:57 EST 2007
User: msurtani
Date: 07/03/07 13:00:57
Modified: src/org/jboss/cache/optimistic WorkspaceNode.java
WorkspaceNodeImpl.java
Log:
JBCACHE-961 - more sophisticated merging of child maps in workspace nodes.
Revision Changes Path
1.24 +12 -3 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.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- WorkspaceNode.java 19 Jan 2007 14:47:40 -0000 1.23
+++ WorkspaceNode.java 7 Mar 2007 18:00:57 -0000 1.24
@@ -11,7 +11,9 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Represents a type of {@link org.jboss.cache.Node} that is to be copied into a {@link TransactionWorkspace} for optimistically locked
@@ -26,11 +28,11 @@
public interface WorkspaceNode extends Node
{
/**
- * Attempts to merge children created during the transaction with underlying children in the tree.
+ * Returns 2 Sets - a set of children added (first set) and a set of children removed.
*
* @return a merged map of child names and Nodes
*/
- Map<Object, NodeSPI> getMergedChildren();
+ List<Set<NodeSPI>> getMergedChildren();
/**
* Retrieves the data version of the in-memory node.
@@ -47,7 +49,9 @@
void setVersion(DataVersion version);
/**
- * Returns true if this node needs to be merged when the transaction commits.
+ * 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.
*/
@@ -154,4 +158,9 @@
* @param workspaceNode
*/
void addChild(WorkspaceNode workspaceNode);
+
+ /**
+ * @return true if children have been added to or removed from this node. Not the same as 'dirty'.
+ */
+ boolean isChildrenModified();
}
1.51 +26 -6 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.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- WorkspaceNodeImpl.java 22 Feb 2007 08:21:03 -0000 1.50
+++ WorkspaceNodeImpl.java 7 Mar 2007 18:00:57 -0000 1.51
@@ -16,9 +16,11 @@
import org.jboss.cache.VersionedNode;
import org.jboss.cache.transaction.GlobalTransaction;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -39,7 +41,10 @@
private DataVersion version = DefaultDataVersion.ZERO;
private boolean dirty;
private boolean created;
+ private boolean childrenModified;
private Map<Object, NodeSPI> optimisticChildNodeMap;
+ private Set<NodeSPI> childrenAdded = new HashSet<NodeSPI>();
+ private Set<NodeSPI> childrenRemoved = new HashSet<NodeSPI>();
private Map<Object, Object> optimisticDataMap;
private boolean versioningImplicit = true; // default
@@ -65,6 +70,11 @@
}
}
+ public boolean isChildrenModified()
+ {
+ return childrenModified;
+ }
+
/**
* Returns true if this node is dirty.
*/
@@ -149,8 +159,10 @@
{
child = (NodeSPI) cache.getConfiguration().getRuntimeConfig().getNodeFactory().createNodeOfType(parent, child_name, parent, null);
optimisticChildNodeMap.put(child_name, child);
+ childrenAdded.add(child);
+ childrenRemoved.remove(child);
}
- dirty = true;
+ childrenModified = true;
return child;
}
@@ -185,9 +197,13 @@
this.version = version;
}
- public Map<Object, NodeSPI> getMergedChildren()
+ public List<Set<NodeSPI>> getMergedChildren()
{
- return optimisticChildNodeMap;
+ //return optimisticChildNodeMap;
+ List<Set<NodeSPI>> l = new ArrayList<Set<NodeSPI>>(2);
+ l.add(childrenAdded);
+ l.add(childrenRemoved);
+ return l;
}
public Map<Object, Object> getMergedData()
@@ -265,6 +281,8 @@
public void addChild(WorkspaceNode child)
{
optimisticChildNodeMap.put(child.getFqn().getLastElement(), child.getNode());
+ childrenAdded.add(child.getNode());
+ childrenRemoved.remove(child.getNode());
}
public void clearData()
@@ -326,10 +344,12 @@
public boolean removeChild(Object childName)
{
- Node n = optimisticChildNodeMap.remove(childName);
+ NodeSPI n = optimisticChildNodeMap.remove(childName);
+ childrenRemoved.add(n);
+ childrenAdded.remove(n);
if (n != null)
{
- dirty = true;
+ childrenModified = true;
return true;
}
else
More information about the jboss-cvs-commits
mailing list