[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at belmont.prod.atl2.jboss.com
Wed Aug 30 16:01:58 EDT 2006
User: msurtani
Date: 06/08/30 16:01:58
Modified: src/org/jboss/cache/interceptors
OptimisticCreateIfNotExistsInterceptor.java
Log:
Fixed concurrency issues with notifications
Revision Changes Path
1.28 +192 -181 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.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- OptimisticCreateIfNotExistsInterceptor.java 25 Aug 2006 14:10:07 -0000 1.27
+++ OptimisticCreateIfNotExistsInterceptor.java 30 Aug 2006 20:01:58 -0000 1.28
@@ -6,24 +6,32 @@
*/
package org.jboss.cache.interceptors;
-import org.jboss.cache.*;
+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.OptimisticTransactionEntry;
+import org.jboss.cache.TransactionEntry;
+import org.jboss.cache.TransactionTable;
+import org.jboss.cache.TreeCacheProxyImpl;
+import org.jboss.cache.TreeNode;
import org.jboss.cache.factories.NodeFactory;
+import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.optimistic.WorkspaceNode;
-import org.jboss.cache.marshall.MethodCall;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
/**
-* Used to make copies of nodes from the main tree into the {@see TransactionWorkspace} as and when needed.
-*
-* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
-* @author <a href="mailto:stevew at jofti.com">Steve Woodcock (stevew at jofti.com)</a>
-*/
+ * Used to make copies of nodes from the main tree into the {@see TransactionWorkspace} as and when needed.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ * @author <a href="mailto:stevew at jofti.com">Steve Woodcock (stevew at jofti.com)</a>
+ */
public class OptimisticCreateIfNotExistsInterceptor extends OptimisticInterceptor
{
public Object invoke(MethodCall m) throws Throwable
@@ -85,7 +93,7 @@
WorkspaceNode workspaceNode, childWorkspaceNode;
Object childName;
- List nodesCreated = new ArrayList();
+ List<Fqn> nodesCreated = new ArrayList<Fqn>();
// how many levels do we have?
int treeNodeSize = fqn.size();
@@ -94,13 +102,13 @@
// try and get the root from the transaction
TransactionWorkspace workspace = transactionEntry.getTransactionWorkSpace();
- synchronized( workspace )
+ synchronized (workspace)
{
DataVersion version = null;
if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
{
version = ctx.getOptionOverrides().getDataVersion();
- workspace.setVersioningImplicit( false );
+ workspace.setVersioningImplicit(false);
}
if (log.isDebugEnabled()) log.debug(" Getting root fqn from workspace for gtx " + gtx);
@@ -111,7 +119,7 @@
if (workspaceNode == null)
{
// Root TreeNode class:
- TreeNode rootTreeNode = ((TreeCacheProxyImpl)cache).currentNode; // very dirty hack
+ 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);
@@ -143,18 +151,20 @@
// no child exists with this name
if (tempchildNode == null)
{
- if (log.isDebugEnabled()) log.debug("Child node "+childName+" doesn't exist. Creating new node.");
+ if (log.isDebugEnabled()) log.debug("Child node " + childName + " doesn't exist. Creating new node.");
// 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()) log.debug("Parent node doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
+ if (log.isDebugEnabled())
+ log.debug("Parent node doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
workspace.addNode(workspaceNode);
}
else
{
- if (log.isDebugEnabled()) log.debug(" Parent node " + workspaceNode.getFqn() + " exists in workspace " + gtx);
+ if (log.isDebugEnabled())
+ log.debug(" Parent node " + workspaceNode.getFqn() + " exists in workspace " + gtx);
}
copy = tmpFqn.clone();
// this does not add it into the real child nodes - but in its
@@ -186,13 +196,15 @@
// wrap it up so we can put it in later if we need to
if (childWorkspaceNode == null || childWorkspaceNode.isDeleted())
{
- if (log.isDebugEnabled()) log.debug("Child node doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
+ if (log.isDebugEnabled())
+ log.debug("Child node doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempchildNode, workspace);
if (!workspace.isVersioningImplicit()) childWorkspaceNode.setVersion(version);
}
else
{
- if (log.isDebugEnabled()) log.debug(" Already found " + tempchildNode.getFqn() + " node in workspace " + gtx);
+ if (log.isDebugEnabled())
+ log.debug(" Already found " + tempchildNode.getFqn() + " node in workspace " + gtx);
}
}
@@ -205,11 +217,10 @@
// code might do
if (nodesCreated.size() > 0)
{
- for (Iterator it = nodesCreated.iterator(); it.hasNext();)
+ for (Fqn temp : nodesCreated)
{
- Object temp = it.next();
- cache.getNotifier().notifyNodeCreated((Fqn) temp, true);
- cache.getNotifier().notifyNodeCreated((Fqn) temp, false);
+ cache.getNotifier().notifyNodeCreated(temp, true);
+ cache.getNotifier().notifyNodeCreated(temp, false);
if (log.isDebugEnabled()) log.debug("Notifying cache of node created in workspace " + temp);
}
}
More information about the jboss-cvs-commits
mailing list