[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Fri Sep 15 14:01:02 EDT 2006
User: msurtani
Date: 06/09/15 14:01:02
Modified: src/org/jboss/cache AbstractNode.java NodeImpl.java
TreeCache.java TreeCacheProxyImpl.java
Log:
- Added move() API
- Added more tests
Revision Changes Path
1.21 +5 -0 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.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- AbstractNode.java 25 Aug 2006 16:30:46 -0000 1.20
+++ AbstractNode.java 15 Sep 2006 18:01:01 -0000 1.21
@@ -58,6 +58,11 @@
return fqn;
}
+ public void setFqn(Fqn f)
+ {
+ fqn = f;
+ }
+
public TreeNode getChild(Object child_name)
{
if (child_name == null) return null;
1.14 +0 -0 JBossCache/src/org/jboss/cache/NodeImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
1.246 +64 -1 JBossCache/src/org/jboss/cache/TreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
retrieving revision 1.245
retrieving revision 1.246
diff -u -b -r1.245 -r1.246
--- TreeCache.java 13 Sep 2006 15:53:04 -0000 1.245
+++ TreeCache.java 15 Sep 2006 18:01:01 -0000 1.246
@@ -93,7 +93,7 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: TreeCache.java,v 1.245 2006/09/13 15:53:04 msurtani Exp $
+ * @version $Id: TreeCache.java,v 1.246 2006/09/15 18:01:01 msurtani Exp $
* <p/>
* @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
*/
@@ -3604,6 +3604,69 @@
return new org.jboss.cache.jmx.Cache(getCacheSPI());
}
+ /**
+ * New API to efficiently relocate a node
+ *
+ * @since 2.0.0
+ */
+ public void move(Fqn newParent, Fqn nodeToMove)
+ {
+ // this needs to be passed up the interceptor chain
+ MethodCall m = MethodCallFactory.create(MethodDeclarations.moveMethodLocal, newParent, nodeToMove);
+ invokeMethod(m);
+ }
+
+ /**
+ * Called by reflection
+ *
+ * @param newParentFqn
+ * @param nodeToMoveFqn
+ */
+ public void _move(Fqn newParentFqn, Fqn nodeToMoveFqn)
+ {
+ // the actual move algorithm.
+ NodeImpl newParent = (NodeImpl) findNode(newParentFqn);
+
+ if (newParent == null)
+ {
+ throw new NodeNotExistsException("New parent node " + newParentFqn + " does not exist when attempting to move node!!");
+ }
+
+ NodeImpl node = (NodeImpl) findNode(nodeToMoveFqn);
+
+ if (node == null)
+ {
+ throw new NodeNotExistsException("Node " + nodeToMoveFqn + " does not exist when attempting to move node!!");
+ }
+
+ NodeImpl oldParent = (NodeImpl) node.getParent();
+ Object nodeName = nodeToMoveFqn.getLast();
+
+ // now that we have the parent and target nodes:
+ // first correct the pointers at the pruning point
+ oldParent.removeChild(nodeName);
+ newParent.addChild(nodeName, node);
+
+ // parent pointer is calculated on the fly using Fqns.
+
+ // now adjust Fqns of node and all children.
+ moveFqns(node, oldParent.getFqn(), newParent.getFqn());
+ }
+
+ private void moveFqns(NodeImpl node, Fqn oldBase, Fqn newBase)
+ {
+ Fqn oldFqn = node.getFqn();
+ Fqn newFqn = new Fqn(newBase, oldFqn.getLast());
+ node.setFqn(newFqn);
+
+ // process children
+ for (Object n : node.getChildren().values())
+ {
+ NodeImpl child = (NodeImpl) n;
+ moveFqns(child, oldFqn, newFqn);
+ }
+ }
+
class MessageListenerAdaptor implements ExtendedMessageListener
{
final Log my_log; // Need this to run under jdk1.3
1.34 +4 -19 JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheProxyImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- TreeCacheProxyImpl.java 13 Sep 2006 17:10:42 -0000 1.33
+++ TreeCacheProxyImpl.java 15 Sep 2006 18:01:02 -0000 1.34
@@ -294,7 +294,7 @@
children.add(new TreeCacheProxyImpl(treeCache, (NodeImpl) i.next()));
}
- return children;
+ return Collections.unmodifiableSet(children);
}
public void setChildren(Map<Object, Node> children)
@@ -304,12 +304,12 @@
public Map getData()
{
- return currentNode.getData();
+ return Collections.unmodifiableMap(currentNode.getData());
}
public Set getKeys()
{
- return currentNode.getDataKeys();
+ return Collections.unmodifiableSet(currentNode.getDataKeys());
}
public Fqn getFqn()
@@ -449,7 +449,7 @@
public void move(Node newParent)
{
- move(currentNode, currentNode.getParent().getFqn(), newParent.getFqn());
+ treeCache.move(newParent.getFqn(), currentNode.getFqn());
}
public boolean hasChild(Fqn f)
@@ -457,21 +457,6 @@
return treeCache.exists(new Fqn(currentNode.getFqn(), f));
}
- private void move(TreeNode node, Fqn oldRoot, Fqn newRoot)
- {
- // recursive
- Iterator i = node.getChildren().values().iterator();
- Fqn oldBase = new Fqn(oldRoot, node.getName());
- Fqn newBase = new Fqn(newRoot, node.getName());
- while (i.hasNext())
- {
- NodeImpl child = (NodeImpl) i.next();
- move(child, node.getFqn(), new Fqn(oldBase, newBase));
- }
- treeCache.put(newRoot, node.getData());
- treeCache.remove(oldRoot);
- }
-
public boolean isLocked()
{
return currentNode.isLocked();
More information about the jboss-cvs-commits
mailing list