[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Fri Sep 15 20:23:35 EDT 2006
User: msurtani
Date: 06/09/15 20:23:35
Modified: src/org/jboss/cache/interceptors
CacheStoreInterceptor.java
PessimisticLockInterceptor.java
Log:
Updates to the move() API plus more UTs
Revision Changes Path
1.31 +43 -3 JBossCache/src/org/jboss/cache/interceptors/CacheStoreInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheStoreInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CacheStoreInterceptor.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- CacheStoreInterceptor.java 5 Sep 2006 18:09:56 -0000 1.30
+++ CacheStoreInterceptor.java 16 Sep 2006 00:23:34 -0000 1.31
@@ -25,7 +25,7 @@
* through the CacheLoader, either after each method call (no TXs), or at TX commit.
*
* @author Bela Ban
- * @version $Id: CacheStoreInterceptor.java,v 1.30 2006/09/05 18:09:56 msurtani Exp $
+ * @version $Id: CacheStoreInterceptor.java,v 1.31 2006/09/16 00:23:34 msurtani Exp $
*/
public class CacheStoreInterceptor extends BaseCacheLoaderInterceptor implements CacheStoreInterceptorMBean
{
@@ -105,7 +105,9 @@
{
Integer puts = (Integer) m_txStores.get(gtx);
if (puts != null)
+ {
m_cacheStores = m_cacheStores + puts.intValue();
+ }
m_txStores.remove(gtx);
}
}
@@ -124,8 +126,10 @@
loader.rollback(gtx);
}
if (configuration.isUseInterceptorMbeans() && getStatisticsEnabled())
+ {
m_txStores.remove(gtx);
}
+ }
else
{
log.trace("Rollback called with no modifications; ignoring.");
@@ -186,6 +190,9 @@
releaseLoaderLock(fqn);
}
break;
+ case MethodDeclarations.moveMethodLocal_id:
+ recursiveRemoveForMove((Fqn) args[0], (Fqn) args[1]);
+ break;
}
// }
@@ -195,6 +202,9 @@
// synchronized(this) {
switch (m.getMethodId())
{
+ case MethodDeclarations.moveMethodLocal_id:
+ recursivePutForMove((Fqn) args[0], (Fqn) args[1]);
+ break;
case MethodDeclarations.putDataMethodLocal_id:
case MethodDeclarations.putDataEraseMethodLocal_id:
Modification mod = convertMethodCallToModification(m);
@@ -210,7 +220,9 @@
releaseLoaderLock(fqn);
}
if (configuration.isUseInterceptorMbeans() && getStatisticsEnabled())
+ {
m_cacheStores++;
+ }
break;
case MethodDeclarations.putKeyValMethodLocal_id:
fqn = (Fqn) args[1];
@@ -227,16 +239,32 @@
releaseLoaderLock(fqn);
}
if (configuration.isUseInterceptorMbeans() && getStatisticsEnabled())
+ {
m_cacheStores++;
+ }
break;
}
// }
if (use_tmp_retval)
+ {
return tmp_retval;
+ }
else
+ {
return retval;
}
+ }
+
+ private void recursivePutForMove(Fqn parent, Fqn node)
+ {
+ throw new RuntimeException("Implement me!");
+ }
+
+ private void recursiveRemoveForMove(Fqn parent, Fqn node)
+ {
+ throw new RuntimeException("Implement me!");
+ }
private List getFqnsFromModificationList(List<MethodCall> modifications)
{
@@ -284,10 +312,14 @@
entry = tx_table.get(gtx);
if (entry == null)
+ {
throw new Exception("entry for transaction " + gtx + " not found in transaction table");
+ }
modifications = entry.getCacheLoaderModifications();
if (modifications.size() == 0)
+ {
return;
+ }
List cache_loader_modifications = new ArrayList();
for (Iterator it = modifications.iterator(); it.hasNext();)
{
@@ -299,26 +331,34 @@
if ((mod.getType() == Modification.PUT_DATA) ||
(mod.getType() == Modification.PUT_DATA_ERASE) ||
(mod.getType() == Modification.PUT_KEY_VALUE))
+ {
txPuts++;
}
}
+ }
if (log.isTraceEnabled())
+ {
log.trace("Converted method calls to cache loader modifications. List size: " + cache_loader_modifications.size());
+ }
if (cache_loader_modifications.size() > 0)
{
loader.prepare(gtx, cache_loader_modifications, onePhase);
preparingTxs.put(gtx, gtx);
if (configuration.isUseInterceptorMbeans() && getStatisticsEnabled() && txPuts > 0)
+ {
m_txStores.put(gtx, new Integer(txPuts));
}
}
+ }
protected Modification convertMethodCallToModification(MethodCall methodCall) throws Exception
{
Method method = methodCall.getMethod();
Object[] args;
if (method == null)
+ {
throw new Exception("method call has no method: " + methodCall);
+ }
args = methodCall.getArgs();
switch (methodCall.getMethodId())
1.32 +23 -14 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.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- PessimisticLockInterceptor.java 5 Sep 2006 11:03:26 -0000 1.31
+++ PessimisticLockInterceptor.java 16 Sep 2006 00:23:34 -0000 1.32
@@ -36,7 +36,7 @@
* current method and unlock when the method returns.
*
* @author Bela Ban
- * @version $Id: PessimisticLockInterceptor.java,v 1.31 2006/09/05 11:03:26 msurtani Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.32 2006/09/16 00:23:34 msurtani Exp $
*/
public class PessimisticLockInterceptor extends Interceptor
{
@@ -65,6 +65,7 @@
DataNode.LockType lock_type = DataNode.LockType.NONE;
Object[] args = m.getArgs();
InvocationContext ctx = cache.getInvocationContext();
+ boolean lockNecessary = false;
if (log.isTraceEnabled()) log.trace("PessimisticLockInterceptor invoked for method " + m);
if (cache.getInvocationContext().getOptionOverrides() != null && cache.getInvocationContext().getOptionOverrides().isSuppressLocking())
@@ -96,6 +97,10 @@
// Set the Fqn
switch (m.getMethodId())
{
+ case MethodDeclarations.moveMethodLocal_id:
+ obtainLocksForMove((Fqn) args[0], (Fqn) args[1]);
+ lockNecessary = true;
+ break;
case MethodDeclarations.putDataMethodLocal_id:
case MethodDeclarations.putDataEraseMethodLocal_id:
case MethodDeclarations.putKeyValMethodLocal_id:
@@ -155,23 +160,13 @@
// release the locks for the given TX
if (fqn != null)
{
- if (createIfNotExists)
- {
do
{
- // TODO: WHat do we do about createIfNotExists flag?
- lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, createIfNotExists);
- }
- while (!cache.hasChild(fqn)); // keep trying until we have the lock (fixes concurrent remove())
- // terminates successfully, or with (Timeout)Exception
- }
- else
- // TODO: WHat do we do about createIfNotExists flag?
- {
lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, createIfNotExists);
}
+ while (createIfNotExists && !cache.hasChild(fqn)); // keep trying until we have the lock (fixes concurrent remove())
}
- else
+ else if (!lockNecessary)
{
if (log.isTraceEnabled())
{
@@ -185,6 +180,20 @@
return super.invoke(m);
}
+ private void obtainLocksForMove(Fqn parent, Fqn node) throws InterruptedException
+ {
+ // parent node (new parent) and current node's existing parent should both get RLs.
+ // node should have a WL.
+
+ // 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);
+
+ //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);
+ }
+
/**
* Locks a given node.
More information about the jboss-cvs-commits
mailing list