Author: manik.surtani(a)jboss.com
Date: 2008-01-04 11:55:01 -0500 (Fri, 04 Jan 2008)
New Revision: 4986
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
JBCACHE-811 - more efficiencies with peek()
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -177,7 +177,7 @@
private void removeNodeFromCacheLoader(InvocationContext ctx, Fqn fqn) throws
Throwable
{
NodeSPI n;
- if (((n = peekNode(ctx, fqn, false, true)) != null) && n.isDataLoaded()
&& loader.exists(fqn))
+ if (((n = peekNode(ctx, fqn, false, true, false)) != null) &&
n.isDataLoaded() && loader.exists(fqn))
{
// node not null and attributes have been loaded?
if (!n.getChildrenDirect().isEmpty())
@@ -339,9 +339,9 @@
// AND it was found in the cache loader (nodeLoaded = true).
// Then notify the listeners that the node has been activated.
Fqn fqn = (Fqn) args[1];
- if (fqn != null && peekNode(ctx, fqn, false, false) != null
&& loader.exists(fqn))
+ if (fqn != null && peekNode(ctx, fqn, false, false, false) != null
&& loader.exists(fqn))
{
- NodeSPI n = peekNode(ctx, fqn, false, true);// don't load
+ NodeSPI n = peekNode(ctx, fqn, false, true, false);// don't load
// node not null and attributes have been loaded?
if (n != null && n.isDataLoaded())
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -265,7 +265,7 @@
private void loadIfNeeded(InvocationContext ctx, Fqn fqn, Object key, boolean allKeys,
boolean initNode, boolean acquireLock, MethodCall m, TransactionEntry entry, boolean
recursive, boolean isMove, boolean bypassLoadingData) throws Throwable
{
- NodeSPI n = cache.peek(fqn, true, true);
+ NodeSPI n = peekNode(ctx, fqn, false, true, true);
boolean mustLoad = mustLoad(n, key, allKeys);
if (trace)
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -112,7 +112,7 @@
Set<Fqn> affectedFqns = preparingTxs.remove(gtx);
if (affectedFqns != null)
{
- storeInternalState(affectedFqns);
+ storeInternalState(ctx, affectedFqns);
}
return returnValue;
}
@@ -212,7 +212,7 @@
{
loader.removeData(fqn);
// we need to mark this node as data loaded
- NodeSPI n = peekNode(ctx, fqn, false, false);//cache.peek(fqn, false);
+ NodeSPI n = peekNode(ctx, fqn, false, false, false);//cache.peek(fqn, false);
if (n != null)
{
n.setDataLoaded(true);
@@ -245,7 +245,7 @@
}
loader.removeData(fqn);
// if we are erasing all the data then consider this node loaded
- NodeSPI n = peekNode(ctx, fqn, false, false);//cache.peek(fqn, false);
+ NodeSPI n = peekNode(ctx, fqn, false, false, false);//cache.peek(fqn, false);
n.setDataLoaded(true);
return returnValue;
}
@@ -299,14 +299,14 @@
return tx_mgr != null && tx_mgr.getTransaction() != null;
}
- private void storeInternalState(Set<Fqn> affectedFqns) throws Exception
+ private void storeInternalState(InvocationContext ctx, Set<Fqn> affectedFqns)
throws Exception
{
if (cache.getConfiguration().isNodeLockingOptimistic())
{
for (Fqn f : affectedFqns)
{
// NOT going to store tombstones!!
- NodeSPI n = cache.peek(f, false, false);
+ NodeSPI n = peekNode(ctx, f, false, false, false);
if (n != null)
{
Map internalState = n.getInternalState(true);
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -172,7 +172,7 @@
}
else
{
- if (peekNode(ctx, fqn, false, false) == null)
+ if (peekNode(ctx, fqn, false, false, false) == null)
{
if (trace) log.trace("Gravitating from local backup tree");
BackupData data = localBackupGet(fqn, ctx);
@@ -386,7 +386,7 @@
if (localOnly)
{
// if (cache.peek(data.getFqn(), false) == null)
- if (peekNode(ctx, data.getFqn(), false, false) == null)
+ if (peekNode(ctx, data.getFqn(), false, false, false) == null)
{
createNodesLocally(data.getFqn(), data.getAttributes());
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -238,7 +238,7 @@
return;
}
- NodeSPI<?, ?> nodeSPI = peekNode(ctx, event.getFqn(), false,
false);//cache.peek(event.getFqn(), false);
+ NodeSPI<?, ?> nodeSPI = peekNode(ctx, event.getFqn(), false, false,
false);//cache.peek(event.getFqn(), false);
//we do not trigger eviction events for resident nodes
if (nodeSPI != null && nodeSPI.isResident())
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -231,20 +231,25 @@
* @param f fqn to find
* @param forceRefresh forces calling cache.peek() even if we hold a reference
to the relevant node.
* @param includeDeletedNodes includes nodes marked for deletion if this is true
+ * @param includeInvalidNodes includes nodes marked as invalid if this is true
* @return a node, or null if one cannot be found.
* @since 2.1.0
*/
- public NodeSPI peekNode(InvocationContext ctx, Fqn f, boolean forceRefresh, boolean
includeDeletedNodes)
+ public NodeSPI peekNode(InvocationContext ctx, Fqn f, boolean forceRefresh, boolean
includeDeletedNodes, boolean includeInvalidNodes)
{
NodeSPI n;
if (forceRefresh || (n = ctx.getPeekedNode(f)) == null)
{
- n = cache.peek(f, true);
+ n = cache.peek(f, true, true);
// put this in the invocation cache
ctx.savePeekedNode(n, f);
}
- if (n != null && !includeDeletedNodes && n.isDeleted()) return
null;
+ if (n != null)
+ {
+ if (!includeDeletedNodes && n.isDeleted()) return null;
+ if (!includeInvalidNodes && !n.isValid()) return null;
+ }
return n;
}
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -114,7 +114,7 @@
fqns.add((Fqn) to);
// peek into Node and get a hold of all child fqns as these need to be in the
workspace.
- NodeSPI node = cache.peek((Fqn) from, true, true);
+ NodeSPI node = peekNode(ctx, (Fqn) from, false, true, true);
greedyGetFqns(fqns, node, (Fqn) to);
@@ -137,7 +137,7 @@
private void createNode(InvocationContext ctx, Fqn targetFqn, boolean
suppressNotification) throws CacheException
{
// if (cache.peek(targetFqn, false) != null) return;
- if (peekNode(ctx, targetFqn, false, false) != null) return;
+ if (peekNode(ctx, targetFqn, false, false, false) != null) return;
// we do nothing if targetFqn is null
if (targetFqn == null) return;
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -69,12 +69,12 @@
GlobalTransaction gtx = getGlobalTransaction(ctx);
TransactionWorkspace workspace = getTransactionWorkspace(gtx);
Fqn fqn = getFqn(args, m.getMethodId());
- WorkspaceNode workspaceNode = fetchWorkspaceNode(fqn, workspace, true, true);
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, true,
true);
// in the case of a data gravitation cleanup, if the primary Fqn does not exist
the backup one may.
if (workspaceNode == null && m.getMethodId() ==
MethodDeclarations.dataGravitationCleanupMethod_id)
{
- workspaceNode = fetchWorkspaceNode(getBackupFqn(args), workspace, true,
true);
+ workspaceNode = fetchWorkspaceNode(ctx, getBackupFqn(args), workspace, true,
true);
}
if (workspaceNode != null)
@@ -238,7 +238,7 @@
return;
}
- WorkspaceNode oldParent = fetchWorkspaceNode(nodeFqn.getParent(), ws, false,
true);
+ WorkspaceNode oldParent = fetchWorkspaceNode(ctx, nodeFqn.getParent(), ws, false,
true);
if (oldParent == null) throw new NodeNotExistsException("Node " +
nodeFqn.getParent() + " does not exist!");
if (parentFqn.equals(oldParent.getFqn()))
@@ -247,7 +247,7 @@
return;
}
// retrieve parent
- WorkspaceNode parent = fetchWorkspaceNode(parentFqn, ws, false, true);
+ WorkspaceNode parent = fetchWorkspaceNode(ctx, parentFqn, ws, false, true);
if (parent == null) throw new NodeNotExistsException("Node " + parentFqn
+ " does not exist!");
Object nodeName = nodeFqn.getLastElement();
@@ -262,7 +262,7 @@
// pre-notify
notifier.notifyNodeMoved(nodeFqn, nodeNewFqn, true, ctx);
- recursiveMoveNode(node, parent.getFqn(), ws);
+ recursiveMoveNode(ctx, node, parent.getFqn(), ws);
// remove old nodes. this may mark some nodes which have already been moved as
deleted
removeNode(ws, node, false, ctx);
@@ -278,17 +278,17 @@
* @param newBase new base Fqn under which the given node will now exist
* @param ws transaction workspace
*/
- private void recursiveMoveNode(WorkspaceNode node, Fqn newBase, TransactionWorkspace
ws)
+ private void recursiveMoveNode(InvocationContext ctx, WorkspaceNode node, Fqn newBase,
TransactionWorkspace ws)
{
Fqn newFqn = new Fqn(newBase, node.getFqn().getLastElement());
- WorkspaceNode movedNode = fetchWorkspaceNode(newFqn, ws, true, true);
+ WorkspaceNode movedNode = fetchWorkspaceNode(ctx, newFqn, ws, true, true);
movedNode.putAll(node.getData());
// process children
for (Object n : node.getChildrenNames())
{
- WorkspaceNode child = fetchWorkspaceNode(new Fqn(node.getFqn(), n), ws, false,
true);
- if (child != null) recursiveMoveNode(child, newFqn, ws);
+ WorkspaceNode child = fetchWorkspaceNode(ctx, new Fqn(node.getFqn(), n), ws,
false, true);
+ if (child != null) recursiveMoveNode(ctx, child, newFqn, ws);
}
}
@@ -329,7 +329,7 @@
if (workspaceNode == null) return false;
Fqn parentFqn = workspaceNode.getFqn().getParent();
- WorkspaceNode parentNode = fetchWorkspaceNode(parentFqn, workspace, true, true);
+ WorkspaceNode parentNode = fetchWorkspaceNode(ctx, parentFqn, workspace, true,
true);
if (parentNode == null) throw new NodeNotExistsException("Unable to find
parent node with fqn " + parentFqn);
// pre-notify
@@ -396,7 +396,7 @@
{
Fqn fqn = (Fqn) args[0];
Object key = args[1];
- WorkspaceNode workspaceNode = fetchWorkspaceNode(fqn, workspace, false, false);
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false,
false);
if (workspaceNode == null)
{
@@ -418,7 +418,7 @@
{
Fqn fqn = (Fqn) args[0];
- WorkspaceNode workspaceNode = fetchWorkspaceNode(fqn, workspace, false, false);
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false,
false);
if (workspaceNode == null)
{
@@ -443,7 +443,7 @@
{
Fqn fqn = (Fqn) args[0];
- WorkspaceNode workspaceNode = fetchWorkspaceNode(fqn, workspace, false, false);
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false,
false);
if (workspaceNode == null)
{
@@ -464,7 +464,7 @@
{
Fqn fqn = (Fqn) args[0];
- WorkspaceNode workspaceNode = fetchWorkspaceNode(fqn, workspace, false, false);
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false,
false);
if (workspaceNode == null)
{
@@ -485,7 +485,7 @@
{
Fqn fqn = (Fqn) args[0];
- WorkspaceNode workspaceNode = fetchWorkspaceNode(fqn, workspace, false, false);
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false,
false);
if (workspaceNode == null)
{
@@ -522,13 +522,13 @@
* @param includeInvalidNodes
* @return a node, if found, or null if not.
*/
- private WorkspaceNode fetchWorkspaceNode(Fqn fqn, TransactionWorkspace workspace,
boolean undeleteIfNecessary, boolean includeInvalidNodes)
+ private WorkspaceNode fetchWorkspaceNode(InvocationContext ctx, Fqn fqn,
TransactionWorkspace workspace, boolean undeleteIfNecessary, boolean includeInvalidNodes)
{
WorkspaceNode workspaceNode = workspace.getNode(fqn);
// if we do not have the node then we need to add it to the workspace
if (workspaceNode == null)
{
- NodeSPI node = cache.peek(fqn, true, includeInvalidNodes);
+ NodeSPI node = peekNode(ctx, fqn, false, true, includeInvalidNodes);
if (node == null) return null;
// create new workspace node based on the node from the underlying data
structure
@@ -546,7 +546,7 @@
{
workspaceNode.markAsDeleted(false);
// re-add to parent
- WorkspaceNode parent = fetchWorkspaceNode(fqn.getParent(), workspace, true,
includeInvalidNodes);
+ WorkspaceNode parent = fetchWorkspaceNode(ctx, fqn.getParent(), workspace,
true, includeInvalidNodes);
parent.addChild(workspaceNode);
}
else
@@ -564,7 +564,7 @@
// now make sure all parents are in the wsp as well
if (workspaceNode != null && !fqn.isRoot())
- fetchWorkspaceNode(fqn.getParent(), workspace, false, includeInvalidNodes);
+ fetchWorkspaceNode(ctx, fqn.getParent(), workspace, false,
includeInvalidNodes);
return workspaceNode;
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -78,7 +78,7 @@
if (trace) log.trace("Validating version for node [" + fqn +
"]");
NodeSPI underlyingNode;
- underlyingNode = cache.peek(fqn, true, true);
+ underlyingNode = peekNode(ctx, fqn, false, true, true);
// if this is a newly created node then we expect the underlying node to be
null.
// also, if the node has been deleted in the WS and the underlying node is
null, this *may* be ok ... will test again later when comparing versions
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -94,7 +94,7 @@
{
throw new NodeNotLoadedException();
}
- NodeSPI n = peekNode(ctx, fqn, false, true);
+ NodeSPI n = peekNode(ctx, fqn, false, true, false);
if (n != null)
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-04
16:20:23 UTC (rev 4985)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-04
16:55:01 UTC (rev 4986)
@@ -134,7 +134,7 @@
if (recursive)
{
//acquireLocksOnChildren(cache.peek(fqn, false), lockType, ctx);
- acquireLocksOnChildren(peekNode(ctx, fqn, false, false), lockType, ctx);
+ acquireLocksOnChildren(peekNode(ctx, fqn, false, false, false), lockType, ctx);
}
return null;
}
@@ -209,18 +209,18 @@
{
cache.getTransactionTable().get(ctx.getGlobalTransaction()).addRemovedNode(from);
}
- acquireLocksOnChildren(peekNode(ctx, from, false, true),
NodeLock.LockType.WRITE, ctx);
+ acquireLocksOnChildren(peekNode(ctx, from, false, true, false),
NodeLock.LockType.WRITE, ctx);
}
if (to != null && !(configuration.getIsolationLevel() ==
IsolationLevel.NONE))
{
//now for an RL for the new parent.
if (trace) log.trace("Attempting to get RL on new parent [" + to +
"]");
lock(ctx, to, NodeLock.LockType.READ, false, timeout, false, false);
- acquireLocksOnChildren(peekNode(ctx, to, false, true), NodeLock.LockType.READ,
ctx);
+ acquireLocksOnChildren(peekNode(ctx, to, false, true, false),
NodeLock.LockType.READ, ctx);
}
Object retValue = nextInterceptor(ctx);
// do a REAL remove here.
- NodeSPI n = peekNode(ctx, from, false, true);
+ NodeSPI n = peekNode(ctx, from, false, true, false);
if (n != null)
{
n.getLock().releaseAll(Thread.currentThread());
@@ -240,7 +240,7 @@
if (ctx.getGlobalTransaction() == null)
{
cacheImpl.realRemove(fqn, true);
- NodeSPI n = peekNode(ctx, fqn, false, true);
+ NodeSPI n = peekNode(ctx, fqn, false, true, false);
if (n != null)
{
n.getLock().releaseAll(Thread.currentThread());
@@ -337,7 +337,7 @@
created = lock(ctx, fqn, lockType, createIfNotExists, timeout,
acquireLockOnParent, reverseRemoveCheck);
firstTry = false;
}
- while (createIfNotExists && peekNode(ctx, fqn, false, true) == null);//
keep trying until we have the lock (fixes concurrent remove())
+ while (createIfNotExists && peekNode(ctx, fqn, false, true, false) ==
null);// keep trying until we have the lock (fixes concurrent remove())
return created;
}
@@ -401,7 +401,7 @@
// make sure the lock we acquired isn't on a deleted node/is an orphan!!
// look into invalidated nodes as well
- NodeSPI repeek = cache.peek(currentNode.getFqn(), true, true);
+ NodeSPI repeek = peekNode(ctx, currentNode.getFqn(), true, true, true);
if (currentNode != repeek)
{
if (trace)
@@ -410,7 +410,7 @@
// check if the parent exists!!
// look into invalidated nodes as well
currentNode.getLock().releaseAll(owner);
- if (cache.peek(parent.getFqn(), true, true) == null)
+ if (peekNode(ctx, parent.getFqn(), true, true, true) == null)
{
// crap!
if (trace)
@@ -490,7 +490,7 @@
{
return true;// we're doing a remove and we've reached the PARENT node
of the target to be removed.
}
- if (!isTargetNode && peekNode(ctx,
targetFqn.getAncestor(currentNodeIndex + 2), false, false) == null)
+ if (!isTargetNode && peekNode(ctx,
targetFqn.getAncestor(currentNodeIndex + 2), false, false, false) == null)
//if (!isTargetNode && cache.peek(targetFqn.getAncestor(currentNodeIndex
+ 2), false) == null)
//if (!isTargetNode && cache.peek(new Fqn(currentNode.getFqn(),
targetFqn.get(currentNodeIndex + 1)), false) == null)
{