[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Elias Ross
genman at noderunner.net
Sun Nov 19 22:53:54 EST 2006
User: genman
Date: 06/11/19 22:53:54
Modified: src/org/jboss/cache/interceptors
ActivationInterceptor.java
CacheLoaderInterceptor.java
DataGravitatorInterceptor.java
InvocationContextInterceptor.java
OptimisticCreateIfNotExistsInterceptor.java
OptimisticLockingInterceptor.java
OptimisticNodeInterceptor.java
OptimisticValidatorInterceptor.java
PassivationInterceptor.java
PessimisticLockInterceptor.java TxInterceptor.java
Log:
JBCACHE-867, Move methods from the ProxyImpl to Node, refactor Node classes as well
Revision Changes Path
1.40 +3 -3 JBossCache/src/org/jboss/cache/interceptors/ActivationInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ActivationInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/ActivationInterceptor.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- ActivationInterceptor.java 10 Nov 2006 02:48:46 -0000 1.39
+++ ActivationInterceptor.java 20 Nov 2006 03:53:54 -0000 1.40
@@ -27,7 +27,7 @@
* their attributes have been initialized and their children have been loaded in memory.
*
* @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
- * @version $Id: ActivationInterceptor.java,v 1.39 2006/11/10 02:48:46 bstansberry Exp $
+ * @version $Id: ActivationInterceptor.java,v 1.40 2006/11/20 03:53:54 genman Exp $
*/
public class ActivationInterceptor extends CacheLoaderInterceptor implements ActivationInterceptorMBean
{
@@ -198,7 +198,7 @@
*/
private boolean allInitialized(Node n)
{
- if (!((TreeCacheProxyImpl) n).getChildrenLoaded()) return false;
+ if (n.getNodeSPI().getChildrenLoaded()) return false;
for (Node child : n.getChildren())
{
@@ -330,7 +330,7 @@
loader.prepare(gtx, cache_loader_modifications, false);
if (configuration.getExposeManagementStatistics() && getStatisticsEnabled() && txActs > 0)
{
- m_txActivations.put(gtx, new Integer(txActs));
+ m_txActivations.put(gtx, Integer.valueOf(txActs));
}
}
}
1.59 +19 -25 JBossCache/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- CacheLoaderInterceptor.java 10 Nov 2006 02:48:46 -0000 1.58
+++ CacheLoaderInterceptor.java 20 Nov 2006 03:53:54 -0000 1.59
@@ -2,7 +2,6 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DataNode;
import org.jboss.cache.Fqn;
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.InvocationContext;
@@ -15,6 +14,7 @@
import org.jboss.cache.loader.AsyncCacheLoader;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.ChainingCacheLoader;
+import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
@@ -32,7 +32,7 @@
* Loads nodes that don't exist at the time of the call into memory from the CacheLoader
*
* @author Bela Ban
- * @version $Id: CacheLoaderInterceptor.java,v 1.58 2006/11/10 02:48:46 bstansberry Exp $
+ * @version $Id: CacheLoaderInterceptor.java,v 1.59 2006/11/20 03:53:54 genman Exp $
*/
public class CacheLoaderInterceptor extends BaseCacheLoaderInterceptor implements CacheLoaderInterceptorMBean
{
@@ -197,9 +197,7 @@
try
{
- TreeCacheProxyImpl cacheImpl = (TreeCacheProxyImpl) cache;
-
- Node n = cacheImpl.peekNode(fqn);
+ Node n = cache.peek(fqn);
boolean mustLoad = mustLoad(n, key);
if (log.isTraceEnabled())
@@ -230,7 +228,7 @@
// - Manik Surtani (21 March 2006)
if (acquireLock)
{
- lock(fqn, DataNode.LockType.WRITE, false); // non-recursive for now
+ lock(fqn, NodeLock.LockType.WRITE, false); // non-recursive for now
}
}
@@ -256,8 +254,7 @@
private void loadChildren(Fqn fqn, Node node, boolean recursive) throws Throwable
{
- TreeCacheProxyImpl n = (TreeCacheProxyImpl) node;
- if (n != null && n.getChildrenLoaded())
+ if (node != null && node.getNodeSPI().getChildrenLoaded())
{
return;
}
@@ -271,19 +268,20 @@
// For getChildrenNames null means no children
if (children_names == null)
{
- if (n != null)
+ if (node != null)
{
if (useCacheStore)
{
- n.setChildren(null);
+ node.getNodeSPI().getChildrenMap().clear();
}
- n.setChildrenLoaded(true);
+ node.getNodeSPI().setChildrenLoaded(true);
}
return;
}
// Create if node had not been created already
- if (n == null) n = (TreeCacheProxyImpl) createNodes(fqn, null); // dont care about local transactions
+ if (node == null)
+ node = createNodes(fqn, null); // dont care about local transactions
// Create one DataNode per child, mark as UNINITIALIZED
for (Iterator i = children_names.iterator(); i.hasNext();)
@@ -292,8 +290,8 @@
Fqn child_fqn = new Fqn(child_name); // this is a RELATIVE Fqn!!
// create child if it didn't exist
cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
- n.addChild(child_fqn);
- Node child = findChild(n.getChildren(), child_name);
+ node.addChild(child_fqn);
+ Node child = findChild(node, child_name);
cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
if (isActivation && recursive)
{
@@ -309,8 +307,8 @@
loadChildren(child.getFqn(), child, true);
}
}
- lock(fqn, recursive ? DataNode.LockType.WRITE : DataNode.LockType.READ, true); // recursive=true: lock entire subtree
- n.setChildrenLoaded(true);
+ lock(fqn, recursive ? NodeLock.LockType.WRITE : NodeLock.LockType.READ, true); // recursive=true: lock entire subtree
+ node.getNodeSPI().setChildrenLoaded(true);
}
private boolean mustLoad(Node n, Object key)
@@ -357,7 +355,7 @@
return retval;
}
- protected void lock(Fqn fqn, DataNode.LockType lock_type, boolean recursive) throws Throwable
+ protected void lock(Fqn fqn, NodeLock.LockType lock_type, boolean recursive) throws Throwable
{
if (configuration.isNodeLockingOptimistic()) return;
@@ -471,7 +469,7 @@
tmp_fqn = new Fqn(tmp_fqn, child_name);
// Node child_node = n.getChild(new Fqn(child_name));
- Node child_node = findChild(n.getChildren(), child_name);
+ Node child_node = findChild(n, child_name);
boolean last = (i == size - 1);
if (child_node == null)
@@ -504,13 +502,9 @@
return n;
}
- private Node findChild(Collection<Node> children, Object child_name)
- {
- for (Node n : children)
+ private Node findChild(Node child, Object child_name)
{
- if (n.getFqn().getLast().equals(child_name)) return n;
- }
- return null;
+ return child.getNodeSPI().getChildrenMap().get(child_name);
}
private void cleanupNodesCreated(TransactionEntry entry)
1.29 +8 -7 JBossCache/src/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DataGravitatorInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/DataGravitatorInterceptor.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- DataGravitatorInterceptor.java 15 Nov 2006 22:59:45 -0000 1.28
+++ DataGravitatorInterceptor.java 20 Nov 2006 03:53:54 -0000 1.29
@@ -19,6 +19,7 @@
import org.jboss.cache.TransactionEntry;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.NodeData;
import org.jboss.cache.marshall.MethodCall;
@@ -435,14 +436,14 @@
private BackupData localBackupGet(Fqn fqn) throws CacheException
{
- List gravitatedData = ((TreeCacheProxyImpl) cache).gravitateData(fqn, true, false); // a "local" gravitation
- boolean found = (Boolean) gravitatedData.get(0);
+ GravitateResult result = cache.gravitateData(fqn, true, false); // a "local" gravitation
+ boolean found = result.getDataFound();
BackupData data = null;
if (found)
{
- Fqn backupFqn = (Fqn) gravitatedData.get(2);
- List nodeData = (List) gravitatedData.get(1);
+ Fqn backupFqn = result.getBuddyBackupRegion();
+ List nodeData = result.getSubtree();
data = new BackupData(fqn, backupFqn, nodeData);
// now the cleanup
if (buddyManager.isDataGravitationRemoveOnFind())
@@ -463,11 +464,11 @@
private Iterator getBackupRootIterator()
{
- DataNode backupRoot = ((TreeCacheProxyImpl) cache).peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
- return backupRoot == null ? Collections.EMPTY_SET.iterator() : backupRoot.getChildren().values().iterator();
+ Node backupRoot = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
+ return backupRoot == null ? Collections.EMPTY_SET.iterator() : backupRoot.getChildren().iterator();
}
- private class BackupData
+ private static class BackupData
{
Fqn primaryFqn;
Fqn backupFqn;
1.10 +1 -1 JBossCache/src/org/jboss/cache/interceptors/InvocationContextInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InvocationContextInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/InvocationContextInterceptor.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- InvocationContextInterceptor.java 6 Nov 2006 23:34:09 -0000 1.9
+++ InvocationContextInterceptor.java 20 Nov 2006 03:53:54 -0000 1.10
@@ -91,7 +91,7 @@
}
else
{
- gtx = ((TreeCacheProxyImpl) cache).treeCache.getCurrentTransaction(tx, false);
+ gtx = cache.getCurrentTransaction(tx, false);
}
return gtx;
1.31 +22 -19 JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: OptimisticCreateIfNotExistsInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- OptimisticCreateIfNotExistsInterceptor.java 20 Sep 2006 16:28:57 -0000 1.30
+++ OptimisticCreateIfNotExistsInterceptor.java 20 Nov 2006 03:53:54 -0000 1.31
@@ -13,6 +13,7 @@
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
import org.jboss.cache.OptimisticTransactionEntry;
+import org.jboss.cache.OptimisticTreeNode;
import org.jboss.cache.TransactionEntry;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.TreeNode;
@@ -109,6 +110,7 @@
// try and get the root from the transaction
TransactionWorkspace workspace = transactionEntry.getTransactionWorkSpace();
+ boolean debug = log.isDebugEnabled();
synchronized (workspace)
{
DataVersion version = null;
@@ -118,22 +120,21 @@
workspace.setVersioningImplicit(false);
}
- if (log.isDebugEnabled()) log.debug(" Getting root fqn from workspace for gtx " + gtx);
workspaceNode = workspace.getNode(Fqn.ROOT);
+ if (debug) log.debug("Global TX: " + gtx + " Root: " + workspaceNode);
// we do not have the root so lets wrap it in case we need to add it
// to the transaction
if (workspaceNode == null)
{
- // Root TreeNode class:
- TreeNode rootTreeNode = ((TreeCacheProxyImpl) cache).currentNode; // very dirty hack
- workspaceNode = NodeFactory.getInstance().createWorkspaceNode(rootTreeNode, workspace);
+ Node node = cache.getRoot();
+ workspaceNode = NodeFactory.getInstance().createWorkspaceNode(node, workspace);
workspace.addNode(workspaceNode);
- if (log.isDebugEnabled()) log.debug(" created root node " + workspaceNode + " in workspace " + gtx);
+ if (debug) log.debug("Created root node: " + workspaceNode);
}
else
{
- if (log.isDebugEnabled()) log.debug(" Already found root node " + workspaceNode + " in workspace " + gtx);
+ if (debug) log.debug("Found root node: " + workspaceNode);
}
// we will always have one root node here, by this stage
@@ -150,31 +151,32 @@
// current workspace node canot be null.
// try and get the child of current node
- log.debug(" Entering synchronized nodewrapper access for gtx " + gtx);
- TreeNode tempchildNode = workspaceNode.getChild(childName);
+ if (debug)
+ log.debug("workspaceNode.getChild(" + childName + ")");
+ Node tempchildNode = workspaceNode.getChild(childName);
// if (log.isDebugEnabled()) log.debug(" Entered synchronized workspaceNode " + workspaceNode + " access for gtx " + gtx);
// no child exists with this name
if (tempchildNode == null)
{
- if (log.isDebugEnabled()) log.debug("Child node " + childName + " doesn't exist. Creating new node.");
+ if (debug) log.debug("Creating new child, doesn't exist");
// we put the parent node into the workspace as we are changing it's children
WorkspaceNode tempCheckWrapper = workspace.getNode(workspaceNode.getFqn());
if (tempCheckWrapper == null || tempCheckWrapper.isDeleted())
{
//add a new one or overwrite an existing one that has been deleted
- if (log.isDebugEnabled())
+ if (debug)
{
- log.debug("Parent node doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
+ log.debug("Parent node doesn't exist in workspace or has been deleted. Adding to workspace.");
}
workspace.addNode(workspaceNode);
}
else
{
- if (log.isDebugEnabled())
+ if (debug)
{
- log.debug(" Parent node " + workspaceNode.getFqn() + " exists in workspace " + gtx);
+ log.debug("Parent node exists: " + workspaceNode);
}
}
copy = tmpFqn.clone();
@@ -188,7 +190,7 @@
versionToPassIn = version;
}
- DataNode tempNode = (DataNode) workspaceNode.createChild(childName, copy, workspaceNode.getNode(), ((TreeCacheProxyImpl) cache).treeCache, versionToPassIn);
+ Node tempNode = workspaceNode.createChild(childName, copy, workspaceNode.getNode(), cache, versionToPassIn);
childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempNode, workspace);
@@ -207,18 +209,18 @@
// wrap it up so we can put it in later if we need to
if (childWorkspaceNode == null || childWorkspaceNode.isDeleted())
{
- if (log.isDebugEnabled())
+ if (debug)
{
- log.debug("Child node doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
+ log.debug("Child node doesn't exist in workspace or has been deleted");
}
childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempchildNode, workspace);
if (!workspace.isVersioningImplicit()) childWorkspaceNode.setVersion(version);
}
else
{
- if (log.isDebugEnabled())
+ if (debug)
{
- log.debug(" Already found " + tempchildNode.getFqn() + " node in workspace " + gtx);
+ log.debug("Found child node: " + tempchildNode);
}
}
@@ -226,8 +228,9 @@
workspaceNode = childWorkspaceNode;
}
- if (log.isDebugEnabled()) log.debug("left synchronized nodewrapper access for gtx " + gtx);
} // end sync block
+ if (debug) log.debug("done synchronized access of GlobalTX");
+
// run the notify outside the synch block as we do not know what that
// code might do
if (nodesCreated.size() > 0)
1.23 +7 -6 JBossCache/src/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: OptimisticLockingInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- OptimisticLockingInterceptor.java 10 Nov 2006 20:32:51 -0000 1.22
+++ OptimisticLockingInterceptor.java 20 Nov 2006 03:53:54 -0000 1.23
@@ -8,10 +8,11 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DataNode;
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
import org.jboss.cache.TransactionEntry;
+import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.optimistic.TransactionWorkspace;
@@ -145,17 +146,17 @@
for (Iterator it = nodes.iterator(); it.hasNext();)
{
WorkspaceNode workspaceNode = (WorkspaceNode) it.next();
- DataNode node = workspaceNode.getNode();
+ Node node = workspaceNode.getNode();
- boolean acquired = node.acquire(gtx, lockAcquisitionTimeout, DataNode.LockType.WRITE);
+ boolean acquired = node.getNodeSPI().getLock().acquire(gtx, lockAcquisitionTimeout, NodeLock.LockType.WRITE);
if (acquired)
{
- if (log.isTraceEnabled()) log.trace("acquired lock on node " + node.getName());
- cache.getTransactionTable().addLock(gtx, node.getLock());
+ if (log.isTraceEnabled()) log.trace("acquired lock on node " + node.getFqn());
+ cache.getTransactionTable().addLock(gtx, node.getNodeSPI().getLock());
}
else
{
- throw new CacheException("unable to acquire lock on node " + node.getName());
+ throw new CacheException("unable to acquire lock on node " + node.getFqn());
}
}
1.33 +9 -5 JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: OptimisticNodeInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- OptimisticNodeInterceptor.java 13 Nov 2006 14:20:32 -0000 1.32
+++ OptimisticNodeInterceptor.java 20 Nov 2006 03:53:54 -0000 1.33
@@ -11,6 +11,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.TreeNode;
import org.jboss.cache.config.Option;
@@ -201,9 +202,12 @@
System.out.println("WS: " + ws);
}
+ /**
+ * Moves a node to a new base.
+ */
private void moveFqns(WorkspaceNode node, Fqn newBase, TransactionWorkspace ws)
{
- Fqn newFqn = new Fqn(newBase, node.getName());
+ Fqn newFqn = new Fqn(newBase, node.getFqn().getLast());
WorkspaceNode movedNode = getOrCreateWorkspaceNode(newFqn, ws);
movedNode.put(node.getData());
@@ -286,7 +290,7 @@
}
// get the parent
- TreeNode temp = workspaceNode.getParent();
+ Node temp = workspaceNode.getParent();
// can parent be null?
if (temp == null)
@@ -347,7 +351,7 @@
{
return;
}
- workspaceNode.clear();
+ workspaceNode.clearData();
workspace.addNode(workspaceNode);
}
@@ -433,12 +437,12 @@
// if we do not have the node then we need to add it to the workspace
if (workspaceNode == null)
{
- DataNode node = ((TreeCacheProxyImpl) cache).peek(fqn);
+ Node node = cache.peek(fqn);
if (node == null)
{
return null;// seems to happen quite a bit
}
- workspaceNode = NodeFactory.getInstance().createWorkspaceNode(node, workspace);
+ workspaceNode = NodeFactory.getInstance().createWorkspaceNode((TreeNode)node, workspace);
workspace.addNode(workspaceNode);
}
// the node has been deleted dude!
1.40 +31 -27 JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: OptimisticValidatorInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- OptimisticValidatorInterceptor.java 13 Nov 2006 14:20:32 -0000 1.39
+++ OptimisticValidatorInterceptor.java 20 Nov 2006 03:53:54 -0000 1.40
@@ -11,10 +11,12 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
import org.jboss.cache.OptimisticTreeNode;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.optimistic.DataVersioningException;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.optimistic.TransactionWorkspace;
@@ -116,33 +118,35 @@
Fqn fqn = workspaceNode.getFqn();
if (trace) log.trace("validating version for node " + fqn);
- // TODO: MANIK an UGLY UGLY hack. Fix this
OptimisticTreeNode realNode;
- if (fqn.isRoot())
+ realNode = (OptimisticTreeNode)cache.peek(fqn);
+
+ if (workspaceNode.isCreated())
+ {
+ if (realNode != null)
{
- realNode = (OptimisticTreeNode) ((TreeCacheProxyImpl) cache).currentNode;
+ throw new DataVersioningException("Tx attempted to create " + fqn + " anew. It has already been created since this tx started by another (possibly remote) tx.");
+ }
}
else
{
- realNode = (OptimisticTreeNode) ((TreeCacheProxyImpl) cache).peek(fqn);
- }
-
- // if this is a newly created node then we expect the underlying node to be null.
- // if not, we have a problem...
- if (realNode == null && !workspaceNode.isCreated())
+ if (realNode == null)
{
throw new DataVersioningException("Real node for " + fqn + " is null, and this wasn't newly created in this tx!");
}
- if (realNode != null && workspaceNode.isCreated())
+ if (workspaceNode == null)
{
- throw new DataVersioningException("Tx attempted to create " + fqn + " anew. It has already been created since this tx started by another (possibly remote) tx.");
+ throw new DataVersioningException("Workspace node for " + fqn + " is null, and this wasn't newly created in this tx!");
}
- if (!workspaceNode.isCreated())
- {
+ if (workspaceNode.getVersion() == null)
+ throw new DataVersioningException("No version for workspace node");
+
+ DataVersion rnv = realNode.getVersion();
+ DataVersion wnv = workspaceNode.getVersion();
// test that the 2 DataVersion types match up
- if (!realNode.getVersion().getClass().equals(workspaceNode.getVersion().getClass()))
+ if (!rnv.getClass().equals(wnv.getClass()))
{
throw new DataVersioningException("Attempting to apply data version of type " + workspaceNode.getVersion().getClass() + " to a node that already contains version of type " + realNode.getVersion().getClass());
}
@@ -182,7 +186,7 @@
if (wrappedNode.isDeleted())
{
if (trace) log.trace("Workspace node " + wrappedNode.getFqn() + " deleted; removing");
- DataNode dNode = wrappedNode.getNode();
+ Node dNode = wrappedNode.getNode();
if (dNode.getFqn().isRoot())
@@ -193,7 +197,7 @@
{
cache.getNotifier().notifyNodeRemoved(dNode.getFqn(), true, dNode.getData() == null ? Collections.emptyMap() : Collections.unmodifiableMap(dNode.getData()));
DataNode parent = (DataNode) dNode.getParent();
- parent.removeChild(dNode.getName());
+ parent.removeChild(dNode.getFqn().getLast());
cache.getNotifier().notifyNodeRemoved(dNode.getFqn(), false, null);
}
}
@@ -207,9 +211,7 @@
Map mergedChildren = wrappedNode.getMergedChildren();
// this could be done better to account for more subtle merges
- current.setChildren(mergedChildren);
-
- if (log.isTraceEnabled()) log.trace("inserting merged data " + wrappedNode.getMergedData());
+ current.getNodeSPI().setChildrenMap(mergedChildren);
// do we need to notify listeners of a modification?? If all we've done is added children then don't
// notify.
@@ -218,6 +220,8 @@
if (needsNotify)
{
+ if (log.isTraceEnabled())
+ log.trace("inserting merged data " + mergedData + " for " + current);
cache.getNotifier().notifyNodeModified(wrappedNode.getFqn(), true, current.getData() == null ? Collections.emptyMap() : Collections.unmodifiableMap(current.getData()));
}
1.32 +3 -3 JBossCache/src/org/jboss/cache/interceptors/PassivationInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PassivationInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/PassivationInterceptor.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- PassivationInterceptor.java 10 Nov 2006 02:48:46 -0000 1.31
+++ PassivationInterceptor.java 20 Nov 2006 03:53:54 -0000 1.32
@@ -18,7 +18,7 @@
* CacheLoader, either before each method call (no TXs), or at TX commit.
*
* @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
- * @version $Id: PassivationInterceptor.java,v 1.31 2006/11/10 02:48:46 bstansberry Exp $
+ * @version $Id: PassivationInterceptor.java,v 1.32 2006/11/20 03:53:54 genman Exp $
*/
public class PassivationInterceptor extends Interceptor implements PassivationInterceptorMBean
{
@@ -26,7 +26,7 @@
protected CacheLoader loader = null;
private SynchronizedLong m_passivations = new SynchronizedLong(0);
- public void setCache(CacheSPI cache)
+ public synchronized void setCache(CacheSPI cache)
{
super.setCache(cache);
this.loader = cache.getCacheLoader();
@@ -126,7 +126,7 @@
}
if (n != null)
{
- return ((TreeCacheProxyImpl) n).currentNode.getData();
+ return n.getNodeSPI().getRawData();
}
else
{
1.34 +32 -29 JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PessimisticLockInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- PessimisticLockInterceptor.java 31 Oct 2006 17:11:42 -0000 1.33
+++ PessimisticLockInterceptor.java 20 Nov 2006 03:53:54 -0000 1.34
@@ -7,16 +7,17 @@
package org.jboss.cache.interceptors;
import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DataNode;
import org.jboss.cache.Fqn;
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
+import org.jboss.cache.NodeImpl;
import org.jboss.cache.TransactionEntry;
import org.jboss.cache.TransactionTable;
import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.lock.LockingException;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.marshall.MethodCall;
@@ -36,7 +37,7 @@
* current method and unlock when the method returns.
*
* @author Bela Ban
- * @version $Id: PessimisticLockInterceptor.java,v 1.33 2006/10/31 17:11:42 msurtani Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.34 2006/11/20 03:53:54 genman Exp $
*/
public class PessimisticLockInterceptor extends Interceptor
{
@@ -62,7 +63,7 @@
public Object invoke(MethodCall m) throws Throwable
{
Fqn fqn = null;
- DataNode.LockType lock_type = DataNode.LockType.NONE;
+ NodeLock.LockType lock_type = NodeLock.LockType.NONE;
Object[] args = m.getArgs();
InvocationContext ctx = cache.getInvocationContext();
boolean lockNecessary = false;
@@ -107,23 +108,23 @@
case MethodDeclarations.putKeyValMethodLocal_id:
createIfNotExists = true;
fqn = (Fqn) args[1];
- lock_type = DataNode.LockType.WRITE;
+ lock_type = NodeLock.LockType.WRITE;
break;
case MethodDeclarations.removeNodeMethodLocal_id:
fqn = (Fqn) args[1];
- lock_type = DataNode.LockType.WRITE;
+ lock_type = NodeLock.LockType.WRITE;
recursive = true; // remove node and *all* child nodes
break;
case MethodDeclarations.removeKeyMethodLocal_id:
case MethodDeclarations.removeDataMethodLocal_id:
case MethodDeclarations.addChildMethodLocal_id:
fqn = (Fqn) args[1];
- lock_type = DataNode.LockType.WRITE;
+ lock_type = NodeLock.LockType.WRITE;
break;
case MethodDeclarations.evictNodeMethodLocal_id:
zeroLockTimeout = true;
fqn = (Fqn) args[0];
- lock_type = DataNode.LockType.WRITE;
+ lock_type = NodeLock.LockType.WRITE;
break;
case MethodDeclarations.getKeyValueMethodLocal_id:
case MethodDeclarations.getNodeMethodLocal_id:
@@ -132,11 +133,11 @@
case MethodDeclarations.releaseAllLocksMethodLocal_id:
case MethodDeclarations.printMethodLocal_id:
fqn = (Fqn) args[0];
- lock_type = DataNode.LockType.READ;
+ lock_type = NodeLock.LockType.READ;
break;
case MethodDeclarations.lockMethodLocal_id:
fqn = (Fqn) args[0];
- lock_type = (DataNode.LockType) args[1];
+ lock_type = (NodeLock.LockType) args[1];
recursive = (Boolean) args[2];
break;
case MethodDeclarations.commitMethod_id:
@@ -189,11 +190,11 @@
// this call will ensure the node gets a WL and it's current parent gets RL.
if (log.isTraceEnabled()) log.trace("Attempting to get WL on node to be moved [" + node + "]");
- lock(node, cache.getInvocationContext().getGlobalTransaction(), DataNode.LockType.WRITE, true, false, lock_acquisition_timeout);
+ lock(node, cache.getInvocationContext().getGlobalTransaction(), NodeLock.LockType.WRITE, true, false, lock_acquisition_timeout);
//now for an RL for the new parent.
if (log.isTraceEnabled()) log.trace("Attempting to get RL on new parent [" + parent + "]");
- lock(parent, cache.getInvocationContext().getGlobalTransaction(), DataNode.LockType.READ, true, false, lock_acquisition_timeout);
+ lock(parent, cache.getInvocationContext().getGlobalTransaction(), NodeLock.LockType.READ, true, false, lock_acquisition_timeout);
}
@@ -205,7 +206,7 @@
* @param lock_type DataNode.LOCK_TYPE_READ, DataNode.LOCK_TYPE_WRITE or DataNode.LOCK_TYPE_NONE
* @param recursive Lock children recursively
*/
- private void lock(Fqn fqn, GlobalTransaction gtx, DataNode.LockType lock_type, boolean recursive, boolean createIfNotExists, long timeout)
+ private void lock(Fqn fqn, GlobalTransaction gtx, NodeLock.LockType lock_type, boolean recursive, boolean createIfNotExists, long timeout)
throws TimeoutException, LockingException, InterruptedException
{
Node n;
@@ -225,23 +226,28 @@
return;
}
- if ((treeNodeSize = fqn.size()) == 0)
+ if (fqn.isRoot())
{
return;
}
if (configuration.getIsolationLevel() == IsolationLevel.NONE)
{
- lock_type = DataNode.LockType.NONE;
+ lock_type = NodeLock.LockType.NONE;
}
n = cache;
+ treeNodeSize = fqn.size();
for (int i = 0; i < treeNodeSize; i++)
{
child_name = fqn.get(i);
+ child_node = n.getNodeSPI().getChildrenMap().get(child_name);
+ /*
cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
+ Fqn childFqn = new Fqn(child_name);
child_node = n.getChild(new Fqn(child_name));
+ */
if (child_node == null && createIfNotExists)
{
cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
@@ -257,7 +263,7 @@
return;
}
- if (lock_type == DataNode.LockType.NONE)
+ if (lock_type == NodeLock.LockType.NONE)
{
// acquired=false;
n = child_node;
@@ -265,15 +271,15 @@
}
else
{
- if (lock_type == DataNode.LockType.WRITE && i == (treeNodeSize - 1))
+ if (lock_type == NodeLock.LockType.WRITE && i == (treeNodeSize - 1))
{
//acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_WRITE);
- acquired = lockManager.acquire(child_node, owner, DataNode.LockType.WRITE, timeout);
+ acquired = lockManager.acquire(child_node, owner, NodeLock.LockType.WRITE, timeout);
}
else
{
//acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_READ);
- acquired = lockManager.acquire(child_node, owner, DataNode.LockType.READ, timeout);
+ acquired = lockManager.acquire(child_node, owner, NodeLock.LockType.READ, timeout);
}
}
@@ -288,7 +294,7 @@
}
else
{
- IdentityLock l = lockManager.getLock(child_node);
+ NodeLock l = lockManager.getLock(child_node);
List locks = getLocks(currentThread);
if (!locks.contains(l))
{
@@ -406,9 +412,7 @@
*/
private void rollback(GlobalTransaction tx)
{
- List undo_ops;
TransactionEntry entry = tx_table.get(tx);
- MethodCall undo_op;
if (log.isTraceEnabled())
{
@@ -453,22 +457,21 @@
tx_table.remove(tx);
}
- private class LockManager
+ private static class LockManager
{
- boolean acquire(Node node, Object owner, DataNode.LockType lockType, long timeout) throws InterruptedException
+ boolean acquire(Node node, Object owner, NodeLock.LockType lockType, long timeout) throws InterruptedException
{
- // TODO: MANIK: The lock map should not be accessed by methods on the Node. This is temporary until it can properly be refactored out.
- return ((TreeCacheProxyImpl) node).acquire(owner, timeout, lockType);
+ return node.getNodeSPI().getLock().acquire(owner, timeout, lockType);
}
- IdentityLock getLock(Node node)
+ NodeLock getLock(Node node)
{
- return ((TreeCacheProxyImpl) node).getLock();
+ return node.getNodeSPI().getLock();
}
- public Set acquireAll(Node node, Object owner, DataNode.LockType lockType, long timeout) throws InterruptedException
+ public Set acquireAll(Node node, Object owner, NodeLock.LockType lockType, long timeout) throws InterruptedException
{
- return ((TreeCacheProxyImpl) node).acquireAll(owner, timeout, lockType);
+ return node.getNodeSPI().getLock().acquireAll(owner, timeout, lockType);
}
}
1.66 +1 -1 JBossCache/src/org/jboss/cache/interceptors/TxInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TxInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/TxInterceptor.java,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- TxInterceptor.java 13 Nov 2006 14:20:32 -0000 1.65
+++ TxInterceptor.java 20 Nov 2006 03:53:54 -0000 1.66
@@ -827,7 +827,7 @@
GlobalTransaction gtx;
if (isValid(tx) && transactions.put(tx, NULL) == null)
{
- gtx = ((TreeCacheProxyImpl) cache).getCurrentTransaction(tx);
+ gtx = cache.getCurrentTransaction(tx, true);
if (gtx.isRemote())
{
// should be no need to register a handler since this a remotely initiated gtx
More information about the jboss-cvs-commits
mailing list