[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Thu Aug 24 10:57:52 EDT 2006
User: msurtani
Date: 06/08/24 10:57:52
Modified: src/org/jboss/cache/interceptors
OptimisticCreateIfNotExistsInterceptor.java
OptimisticValidatorInterceptor.java
Log:
opt locking and state transfer/region mgmt fixes
Revision Changes Path
1.25 +5 -3 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.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- OptimisticCreateIfNotExistsInterceptor.java 18 Aug 2006 15:40:39 -0000 1.24
+++ OptimisticCreateIfNotExistsInterceptor.java 24 Aug 2006 14:57:52 -0000 1.25
@@ -113,13 +113,15 @@
}
if (log.isDebugEnabled()) log.debug(" Getting root fqn from workspace for gtx " + gtx);
- workspaceNode = workspace.getNode(cache.getRoot().getFqn());
+ workspaceNode = workspace.getNode(Fqn.ROOT);
// we do not have the root so lets wrap it in case we need to add it
// to the transaction
if (workspaceNode == null)
{
- workspaceNode = NodeFactory.getInstance().createWorkspaceNode((TreeNode) cache.get(Fqn.ROOT), workspace);
+ // Root TreeNode class:
+ TreeNode rootTreeNode = ((TreeCacheProxyImpl)cache).currentNode; // very dirty hack
+ workspaceNode = NodeFactory.getInstance().createWorkspaceNode(rootTreeNode, workspace);
workspace.addNode(workspaceNode);
if (log.isDebugEnabled()) log.debug(" created root node " + workspaceNode + " in workspace " + gtx);
}
@@ -163,7 +165,7 @@
{
if (log.isDebugEnabled()) log.debug(" Parent node " + workspaceNode.getFqn() + " exists in workspace " + gtx);
}
- copy = (Fqn) tmpFqn.clone();
+ copy = tmpFqn.clone();
// this does not add it into the real child nodes - but in its
// local child map for the transaction
1.30 +43 -22 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.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- OptimisticValidatorInterceptor.java 18 Aug 2006 15:40:39 -0000 1.29
+++ OptimisticValidatorInterceptor.java 24 Aug 2006 14:57:52 -0000 1.30
@@ -6,18 +6,24 @@
*/
package org.jboss.cache.interceptors;
-import org.jboss.cache.*;
-import org.jboss.cache.config.Option;
-import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.DataNode;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.GlobalTransaction;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.OptimisticTreeNode;
+import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.marshall.JBCMethodCall;
+import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.optimistic.WorkspaceNode;
-import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jgroups.blocks.MethodCall;
import javax.transaction.Transaction;
import java.lang.reflect.Method;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
@@ -108,14 +114,17 @@
workspaceNode = (WorkspaceNode) it.next();
Fqn fqn = workspaceNode.getFqn();
if (trace) log.trace("validating version for node " + fqn);
- Option o = cache.getInvocationContext().getOptionOverrides();
- o.setBypassInterceptorChain(true);
- cache.getInvocationContext().setOptionOverrides(o);
- OptimisticTreeNode realNode = (OptimisticTreeNode) cache.get(fqn);
- o = cache.getInvocationContext().getOptionOverrides();
- o.setBypassInterceptorChain(false);
- cache.getInvocationContext().setOptionOverrides(o);
+ // TODO: MANIK an UGLY UGLY hack. Fix this
+ OptimisticTreeNode realNode = null;
+ if (fqn.isRoot())
+ {
+ realNode = (OptimisticTreeNode) ((TreeCacheProxyImpl) cache).currentNode;
+ }
+ 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...
@@ -157,11 +166,9 @@
// short circuit if this node is deleted?
if (wrappedNode.isDeleted())
{
- // handle notifications
-
if (trace) log.trace("Workspace node " + wrappedNode.getFqn() + " deleted; removing");
DataNode dNode = wrappedNode.getNode();
- // TODO : MANIK: cache.notifyNodeRemoved(dNode.getFqn(), true);
+
if (dNode.getFqn().isRoot())
{
@@ -169,11 +176,11 @@
}
else
{
+ cache.getNotifier().notifyNodeRemoved(dNode.getFqn(), true, dNode.getData() == null ? null : Collections.unmodifiableMap(dNode.getData()));
DataNode parent = (DataNode) dNode.getParent();
parent.removeChild( dNode.getName() );
+ cache.getNotifier().notifyNodeRemoved(dNode.getFqn(), false, null);
}
- // TODO : MANIK: cache.notifyNodeRemoved(dNode.getFqn());
- // TODO : MANIK: cache.notifyNodeRemove(dNode.getFqn(), false);
}
else
{
@@ -181,7 +188,6 @@
// if (wrappedNode.hasCreatedOrRemovedChildren() handleChildNodes(wrappedNode);
if (wrappedNode.isDirty())
{
- // TODO : MANIK: cache.notifyNodeModify(wrappedNode.getFqn(), true);
OptimisticTreeNode current = (OptimisticTreeNode) wrappedNode.getNode();
Map mergedChildren = wrappedNode.getMergedChildren();
@@ -189,7 +195,14 @@
current.setChildren(mergedChildren);
if (log.isTraceEnabled()) log.trace("inserting merged data " + wrappedNode.getMergedData());
+
+ // do we need to notify listeners of a modification?? If all we've done is added children then don't
+ // notify.
Map mergedData = wrappedNode.getMergedData();
+ boolean needsNotify = !dataEquals(mergedData, current.getData());
+
+ if (needsNotify) cache.getNotifier().notifyNodeModified(wrappedNode.getFqn(), true, wrappedNode.getData() == null ? null : Collections.unmodifiableMap(wrappedNode.getData()));
+
current.put(mergedData, true);
if (workspace.isVersioningImplicit())
{
@@ -201,17 +214,25 @@
current.setVersion(wrappedNode.getVersion());
}
if (trace) log.trace("Setting version of node " + current.getName() + " from " + wrappedNode.getVersion() + " to " + current.getVersion());
- // TODO : MANIK: cache.notifyNodeModified(wrappedNode.getFqn());
- // TODO : MANIK: cache.notifyNodeModify(wrappedNode.getFqn(), false);
+
+ if (needsNotify) cache.getNotifier().notifyNodeModified(wrappedNode.getFqn(), false, mergedData == null ? null : Collections.unmodifiableMap(mergedData));
}
else
{
if (trace) log.trace("Merging node " + wrappedNode.getFqn() + " not necessary since the node is not dirty");
- // TODO : MANIK: cache.notifyNodeVisited(wrappedNode.getFqn());
+ cache.getNotifier().notifyNodeVisited(wrappedNode.getFqn(), true);
+ cache.getNotifier().notifyNodeVisited(wrappedNode.getFqn(), false);
+ }
}
}
+
}
+ private boolean dataEquals(Map map1, Map map2)
+ {
+ if (map1 == null && (map2 == null || map2.isEmpty())) return true;
+ if (map2 == null && map1.isEmpty()) return true;
+ return map1.equals(map2);
}
private void rollBack(GlobalTransaction gtx)
More information about the jboss-cvs-commits
mailing list