Author: manik.surtani(a)jboss.com
Date: 2008-04-28 13:27:58 -0400 (Mon, 28 Apr 2008)
New Revision: 5734
Added:
core/trunk/src/main/java/org/jboss/cache/interceptors/base/PostProcessingCommandInterceptor.java
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/base/CommandInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java
Log:
Javadoc and method naming
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-04-28
16:56:40 UTC (rev 5733)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-04-28
17:27:58 UTC (rev 5734)
@@ -8,6 +8,7 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.AbstractVisitor;
import org.jboss.cache.commands.ReversibleCommand;
+import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.tx.CommitCommand;
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
@@ -88,7 +89,7 @@
* if this is a shared cache loader and the call is of remote origin, pass up the
chain
*/
@Override
- public boolean skipInterception(InvocationContext ctx)
+ public boolean skipInterception(InvocationContext ctx, VisitableCommand command)
{
if (!ctx.isOriginLocal() && loaderConfig.isShared())
{
@@ -102,7 +103,7 @@
}
@Override
- public Object executeCommitCommand(InvocationContext ctx, CommitCommand command)
throws Throwable
+ public Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws
Throwable
{
if (inTransaction())
{
@@ -151,7 +152,7 @@
}
@Override
- public Object executeRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
+ public Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
{
if (inTransaction())
{
@@ -179,7 +180,7 @@
}
@Override
- public Object executeOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
+ public Object handleOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
{
if (inTransaction())
{
@@ -190,7 +191,7 @@
}
@Override
- public Object executePrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
+ public Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
{
if (inTransaction())
{
@@ -205,7 +206,7 @@
* access an element just removed, causing the CacheLoader to *load* the element
before *removing* it.
*/
@Override
- public Object executeRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
+ public Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
{
if (!inTransaction())
{
@@ -215,7 +216,7 @@
}
@Override
- public Object executeRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command)
throws Throwable
+ public Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command)
throws Throwable
{
if (!inTransaction())
{
@@ -227,7 +228,7 @@
}
@Override
- public Object executeRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
+ public Object handleRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
{
if (!inTransaction())
{
@@ -243,7 +244,7 @@
}
@Override
- public Object executeMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
+ public Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
{
Object returnValue = invokeNextInterceptor(ctx, command);
if (inTransaction())
@@ -257,7 +258,7 @@
}
@Override
- public Object executePutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
+ public Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
{
Object returnValue = invokeNextInterceptor(ctx, command);
if (inTransaction())
@@ -284,7 +285,7 @@
}
@Override
- public Object executePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
+ public Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
{
Object result;
Object returnValue = invokeNextInterceptor(ctx, command);
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-04-28
16:56:40 UTC (rev 5733)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-04-28
17:27:58 UTC (rev 5734)
@@ -11,6 +11,7 @@
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.DataCommand;
+import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
import org.jboss.cache.commands.read.GetKeysCommand;
@@ -27,7 +28,7 @@
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.interceptors.base.PostProcessingChainedInterceptor;
+import org.jboss.cache.interceptors.base.PostProcessingCommandInterceptor;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockManager;
import org.jboss.cache.lock.NodeLock;
@@ -55,7 +56,7 @@
* @author Bela Ban
* @version $Id$
*/
-public class PessimisticLockInterceptor extends PostProcessingChainedInterceptor
+public class PessimisticLockInterceptor extends PostProcessingCommandInterceptor
{
private TransactionTable txTable;
private DataContainer dataContainer;
@@ -74,13 +75,13 @@
}
@Override
- public Object executePutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
+ public Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
{
return handlePutCommand(ctx, command, false);
}
@Override
- public Object executePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
+ public Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
{
return handlePutCommand(ctx, command, command.isPutForExternalRead());
}
@@ -112,7 +113,7 @@
}
@Override
- public Object executePrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
+ public Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
{
// 2-phase commit prepares are no-ops here.
if (!command.isOnePhaseCommit()) return invokeNextInterceptor(ctx, command);
@@ -125,7 +126,7 @@
}
@Override
- public Object executeCommitCommand(InvocationContext ctx, CommitCommand command)
throws Throwable
+ public Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws
Throwable
{
commit(command.getGlobalTransaction());
if (trace) log.trace("bypassed locking as method commit() doesn't require
locking");
@@ -135,7 +136,7 @@
}
@Override
- public Object executeRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
+ public Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
{
TransactionEntry entry = txTable.get(command.getGlobalTransaction());
if (trace)
@@ -165,7 +166,7 @@
}
@Override
- public Object executeMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
+ public Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
{
if (ctx.isLockingSuppressed()) return invokeNextInterceptor(ctx, command);
long timeout = ctx.getContextLockAcquisitionTimeout(lockAcquisitionTimeout);
@@ -198,7 +199,7 @@
}
@Override
- public Object executeRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
+ public Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
{
if (ctx.isLockingSuppressed()) return invokeNextInterceptor(ctx, command);
// need to make a note of ALL nodes created here!!
@@ -247,56 +248,56 @@
}
@Override
- public Object executeRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command)
throws Throwable
+ public Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command)
throws Throwable
{
lockManager.acquireLocksWithTimeout(ctx, command.getFqn(), NodeLock.LockType.WRITE,
false, false, false, false, null, false);
return invokeNextInterceptor(ctx, command);
}
@Override
- public Object executeRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
+ public Object handleRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
{
lockManager.acquireLocksWithTimeout(ctx, command.getFqn(), NodeLock.LockType.WRITE,
false, false, false, false, null, false);
return invokeNextInterceptor(ctx, command);
}
@Override
- public Object executeEvictFqnCommand(InvocationContext ctx, EvictCommand command)
throws Throwable
+ public Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command)
throws Throwable
{
lockManager.acquireLocksWithTimeout(ctx, command.getFqn(), NodeLock.LockType.WRITE,
false, true, false, false, null, false);
return invokeNextInterceptor(ctx, command);
}
@Override
- public Object executeGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
+ public Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
{
lockManager.acquireLocksWithTimeout(ctx, command.getFqn(), NodeLock.LockType.READ,
false, false, false, false, null, false);
return invokeNextInterceptor(ctx, command);
}
@Override
- public Object executeGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
+ public Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
{
lockManager.acquireLocksWithTimeout(ctx, command.getFqn(), NodeLock.LockType.READ,
false, false, false, false, null, false);
return invokeNextInterceptor(ctx, command);
}
@Override
- public Object executeGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
+ public Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
{
lockManager.acquireLocksWithTimeout(ctx, command.getFqn(), NodeLock.LockType.READ,
false, false, false, false, null, false);
return invokeNextInterceptor(ctx, command);
}
@Override
- public Object executeGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
+ public Object handleGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
{
lockManager.acquireLocksWithTimeout(ctx, command.getFqn(), NodeLock.LockType.READ,
false, false, false, false, null, false);
return invokeNextInterceptor(ctx, command);
}
@Override
- public void doAfterCall(InvocationContext ctx)
+ public void doAfterCall(InvocationContext ctx, VisitableCommand command)
{
ctx.clearInvocationLocksAcquired();
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/base/CommandInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/base/CommandInterceptor.java 2008-04-28
16:56:40 UTC (rev 5733)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/base/CommandInterceptor.java 2008-04-28
17:27:58 UTC (rev 5734)
@@ -11,7 +11,26 @@
import java.util.Map;
/**
+ * This is the base class for all interceptors to extend, and implements the {@link
org.jboss.cache.commands.Visitor} interface
+ * allowing it to intercept invocations on {@link
org.jboss.cache.commands.VisitableCommand}s.
+ * <p/>
+ * Commands are created either by the {@link
org.jboss.cache.invocation.CacheInvocationDelegate} (for invocations on the {@link
org.jboss.cache.Cache}
+ * public interface), the {@link org.jboss.cache.invocation.NodeInvocationDelegate} for
invocations on the {@link org.jboss.cache.Node}
+ * public interface, or by the {@link org.jboss.cache.marshall.CommandAwareRpcDispatcher}
for remotely originating invocations, and
+ * are passed up the interceptor chain by using the {@link
org.jboss.cache.interceptors.InterceptorChain} helper class.
+ * <p/>
+ * When writing interceptors, authors can either override a specific visitXXX() method
(such as {@link #visitGetKeyValueCommand(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.read.GetKeyValueCommand)})
+ * or the more generic {@link #handleDefault(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.VisitableCommand)} which is the default behaviour of
+ * any visit method, as defined in {@link
org.jboss.cache.commands.AbstractVisitor#handleDefault(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.VisitableCommand)}.
+ * <p/>
+ * The preferred approach is to override the specific visitXXX() methods that are of
interest rather than to override {@link #handleDefault(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.VisitableCommand)}
+ * and then write a series of if statements or a switch block, if command-specific
behaviour is needed.
+ * <p/>
+ *
* @author Mircea.Markus(a)jboss.com
+ * @see VisitableCommand
+ * @see org.jboss.cache.commands.Visitor
+ * @see org.jboss.cache.interceptors.InterceptorChain
* @since 2.2
*/
public class CommandInterceptor extends AbstractVisitor implements InterceptorMBean
@@ -29,47 +48,94 @@
trace = log.isTraceEnabled();
}
+ /**
+ * @return true if gathering statistics for JMX is enabled on this interceptor.
+ */
public boolean getStatisticsEnabled()
{
return statsEnabled;
}
+ /**
+ * @param enabled whether gathering statistics for JMX are enabled.
+ */
public void setStatisticsEnabled(boolean enabled)
{
statsEnabled = enabled;
}
+ /**
+ * Returns a map of statistics. This is a default implementation which returns an
empty map and should be overridden
+ * if it is to be meaningful.
+ *
+ * @return an empty map
+ */
public Map<String, Object> dumpStatistics()
{
return Collections.emptyMap();
}
+ /**
+ * Resets statistics gathered. Is a no-op, and should be overridden if it is to be
meaningful.
+ */
public void resetStatistics()
{
}
+ /**
+ * Retrieves the next interceptor in the chain.
+ *
+ * @return the next interceptor in the chain.
+ */
public CommandInterceptor getNext()
{
return next;
}
+ /**
+ * @return true if there is another interceptor in the chain after this; false
otherwise.
+ */
public boolean hasNext()
{
return getNext() != null;
}
+ /**
+ * Sets the next interceptor in the chain to the interceptor passed in.
+ *
+ * @param next next interceptor in the chain.
+ */
public void setNext(CommandInterceptor next)
{
this.next = next;
}
+ /**
+ * Invokes the next interceptor in the chain. This is how interceptor implementations
should pass a call up the chain
+ * to the next interceptor. In previous (pre-2.2.0) implementations of JBoss Cache,
this was done by calling
+ * <pre>super.invoke()</pre>.
+ *
+ * @param ctx invocation context
+ * @param command command to pass up the chain.
+ * @return return value of the invocation
+ * @throws Throwable in the event of problems
+ */
public Object invokeNextInterceptor(InvocationContext ctx, VisitableCommand command)
throws Throwable
{
- return command.acceptVisitor(ctx, getNext());
+ return command.acceptVisitor(ctx, next);
}
+ /**
+ * The default behaviour of the visitXXX methods, which is to ignore the call and pass
the call up to the next
+ * interceptor in the chain.
+ *
+ * @param ctx invocation context
+ * @param command command to invoke
+ * @return return value
+ * @throws Throwable in the event of problems
+ */
@Override
- public Object handleDefault(InvocationContext ctx, VisitableCommand command) throws
Throwable
+ protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws
Throwable
{
return invokeNextInterceptor(ctx, command);
}
Copied:
core/trunk/src/main/java/org/jboss/cache/interceptors/base/PostProcessingCommandInterceptor.java
(from rev 5728,
core/trunk/src/main/java/org/jboss/cache/interceptors/base/PostProcessingChainedInterceptor.java)
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/base/PostProcessingCommandInterceptor.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/base/PostProcessingCommandInterceptor.java 2008-04-28
17:27:58 UTC (rev 5734)
@@ -0,0 +1,389 @@
+package org.jboss.cache.interceptors.base;
+
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.commands.VisitableCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.read.GetDataMapCommand;
+import org.jboss.cache.commands.read.GetKeyValueCommand;
+import org.jboss.cache.commands.read.GetKeysCommand;
+import org.jboss.cache.commands.read.GetNodeCommand;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.cache.commands.read.RemoteExistsCommand;
+import org.jboss.cache.commands.tx.CommitCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+import org.jboss.cache.commands.write.InvalidateCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveDataCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
+
+/**
+ * This interceptor will call {@link
#doAfterCall(org.jboss.cache.InvocationContext,org.jboss.cache.commands.VisitableCommand)}
after invoking each visit method
+ * (and the {@link #handleDefault(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.VisitableCommand)} method) in
+ * a <tt>finally</tt> block.
+ * <p/>
+ * It is useful if common cleanup code is required at the end of each call.
+ * <p/>
+ * Instead of overriding visitXXX() methods, implementations should override their
handleXXX() counterparts defined in this class
+ * instead, as well as the {@link
#doAfterCall(org.jboss.cache.InvocationContext,org.jboss.cache.commands.VisitableCommand)}
method.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public abstract class PostProcessingCommandInterceptor extends CommandInterceptor
+{
+ @Override
+ public final Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
+ {
+ try
+ {
+ return handlePutDataMapCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
+ {
+ try
+ {
+ return handlePutKeyValueCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleRemoveNodeCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleRemoveDataCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command)
throws Throwable
+ {
+ try
+ {
+ return handleEvictFqnCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command)
throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleInvalidateCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleRemoveKeyCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleGetDataMapCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitExistsNodeCommand(InvocationContext ctx, RemoteExistsCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleExistsNodeCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleExistsNodeCommand(InvocationContext ctx, RemoteExistsCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleGetKeyValueCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
+ {
+ try
+ {
+ return handleGetNodeCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
+ {
+ try
+ {
+ return handleGetKeysCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
+ {
+ try
+ {
+ return handleGetChildrenNamesCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitMoveCommand(InvocationContext ctx, MoveCommand command)
throws Throwable
+ {
+ try
+ {
+ return handleMoveCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGravitateDataCommand(InvocationContext ctx,
GravitateDataCommand command) throws Throwable
+ {
+ try
+ {
+ return handleGravitateDataCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGravitateDataCommand(InvocationContext ctx,
GravitateDataCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
+ {
+ try
+ {
+ return handlePrepareCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitRollbackCommand(InvocationContext ctx, RollbackCommand
command) throws Throwable
+ {
+ try
+ {
+ return handleRollbackCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitCommitCommand(InvocationContext ctx, CommitCommand command)
throws Throwable
+ {
+ try
+ {
+ return handleCommitCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleCommitCommand(InvocationContext ctx, CommitCommand command)
throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
+ {
+ try
+ {
+ return handleOptimisticPrepareCommand(ctx, command);
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ /**
+ * Callback that is invoked after every handleXXX() method defined above.
+ *
+ * @param ctx invocation context
+ * @param command command which was invoked
+ */
+ protected abstract void doAfterCall(InvocationContext ctx, VisitableCommand command);
+}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java 2008-04-28
16:56:40 UTC (rev 5733)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java 2008-04-28
17:27:58 UTC (rev 5734)
@@ -23,9 +23,15 @@
import org.jboss.cache.commands.write.RemoveNodeCommand;
/**
- * Chained command interceptor that performs a skip check before calling each handler
method.
- * This is usefull in scenarios where all handlers methods should be skiped if the same
condition is true.
- * E.g. CacheStoreInteceptor would skip all method calls if we have a shared storage and
this is not the designated node.
+ * This interceptor will call {@link
#skipInterception(org.jboss.cache.InvocationContext,org.jboss.cache.commands.VisitableCommand)}
before invoking each visit method
+ * (and the {@link #handleDefault(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.VisitableCommand)} method). If
+ * {@link
#skipInterception(org.jboss.cache.InvocationContext,org.jboss.cache.commands.VisitableCommand)}
returns <tt>false</tt>, the invocation will be skipped
+ * and passed up the interceptor chain instead.
+ * <p/>
+ * Instead of overriding visitXXX() methods, implementations should override their
handleXXX() counterparts defined in this class
+ * instead, as well as the {@link
#skipInterception(org.jboss.cache.InvocationContext,org.jboss.cache.commands.VisitableCommand)}
method.
+ * Also, instead of overriding {@link #handleDefault(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.VisitableCommand)}, implementors
+ * should override {@link #handleAll(org.jboss.cache.InvocationContext,
org.jboss.cache.commands.VisitableCommand)}.
*
* @author Mircea.Markus(a)jboss.com
* @since 2.2
@@ -35,302 +41,317 @@
@Override
public final Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executePutDataMapCommand(ctx, command);
+ return handlePutDataMapCommand(ctx, command);
}
- public Object executePutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
+ protected Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executePutKeyValueCommand(ctx, command);
+ return handlePutKeyValueCommand(ctx, command);
}
- public Object executePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
+ protected Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeRemoveNodeCommand(ctx, command);
+ return handleRemoveNodeCommand(ctx, command);
}
- public Object executeRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
+ protected Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeRemoveDataCommand(ctx, command);
+ return handleRemoveDataCommand(ctx, command);
}
- public Object executeRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
+ protected Object handleRemoveDataCommand(InvocationContext ctx, RemoveDataCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command)
throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeEvictFqnCommand(ctx, command);
+ return handleEvictFqnCommand(ctx, command);
}
- public Object executeEvictFqnCommand(InvocationContext ctx, EvictCommand command)
throws Throwable
+ protected Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command)
throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeInvalidateCommand(ctx, command);
+ return handleInvalidateCommand(ctx, command);
}
- public Object executeInvalidateCommand(InvocationContext ctx, InvalidateCommand
command) throws Throwable
+ protected Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeRemoveKeyCommand(ctx, command);
+ return handleRemoveKeyCommand(ctx, command);
}
- public Object executeRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command)
throws Throwable
+ protected Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeGetDataMapCommand(ctx, command);
+ return handleGetDataMapCommand(ctx, command);
}
- public Object executeGetDataMapCommand(InvocationContext ctx, GetDataMapCommand
command) throws Throwable
+ protected Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitExistsNodeCommand(InvocationContext ctx, RemoteExistsCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeExistsNodeCommand(ctx, command);
+ return handleExistsNodeCommand(ctx, command);
}
- public Object executeExistsNodeCommand(InvocationContext ctx, RemoteExistsCommand
command) throws Throwable
+ protected Object handleExistsNodeCommand(InvocationContext ctx, RemoteExistsCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeGetKeyValueCommand(ctx, command);
+ return handleGetKeyValueCommand(ctx, command);
}
- public Object executeGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
+ protected Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeGetNodeCommand(ctx, command);
+ return handleGetNodeCommand(ctx, command);
}
- public Object executeGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
+ protected Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeGetKeysCommand(ctx, command);
+ return handleGetKeysCommand(ctx, command);
}
- public Object executeGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
+ protected Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeGetChildrenNamesCommand(ctx, command);
+ return handleGetChildrenNamesCommand(ctx, command);
}
- public Object executeGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
+ protected Object handleGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitMoveCommand(InvocationContext ctx, MoveCommand command)
throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeMoveCommand(ctx, command);
+ return handleMoveCommand(ctx, command);
}
- public Object executeMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
+ protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitGravitateDataCommand(InvocationContext ctx,
GravitateDataCommand command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeGravitateDataCommand(ctx, command);
+ return handleGravitateDataCommand(ctx, command);
}
- public Object executeGravitateDataCommand(InvocationContext ctx, GravitateDataCommand
command) throws Throwable
+ protected Object handleGravitateDataCommand(InvocationContext ctx,
GravitateDataCommand command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executePrepareCommand(ctx, command);
+ return handlePrepareCommand(ctx, command);
}
- public Object executePrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
+ protected Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command)
throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitRollbackCommand(InvocationContext ctx, RollbackCommand
command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeRollbackCommand(ctx, command);
+ return handleRollbackCommand(ctx, command);
}
- public Object executeRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
+ protected Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitCommitCommand(InvocationContext ctx, CommitCommand command)
throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeCommitCommand(ctx, command);
+ return handleCommitCommand(ctx, command);
}
- public Object executeCommitCommand(InvocationContext ctx, CommitCommand command)
throws Throwable
+ protected Object handleCommitCommand(InvocationContext ctx, CommitCommand command)
throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object visitOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeOptimisticPrepareCommand(ctx, command);
+ return handleOptimisticPrepareCommand(ctx, command);
}
- public Object executeOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
+ protected Object handleOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
{
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
@Override
public final Object handleDefault(InvocationContext ctx, VisitableCommand command)
throws Throwable
{
- if (skipInterception(ctx))
+ if (skipInterception(ctx, command))
{
return invokeNextInterceptor(ctx, command);
}
- return executeAll(ctx, command);
+ return handleAll(ctx, command);
}
- public Object executeAll(InvocationContext ctx, VisitableCommand command) throws
Throwable
+ /**
+ * Default implementation, which just passes the call up the interceptor chain
+ *
+ * @param ctx invocation context
+ * @param command command
+ * @return return value
+ * @throws Throwable in the event of problems
+ */
+ protected Object handleAll(InvocationContext ctx, VisitableCommand command) throws
Throwable
{
return invokeNextInterceptor(ctx, command);
}
- public abstract boolean skipInterception(InvocationContext ctx);
+ /**
+ * Tests whether the command should be intercepted or not. This is invoked before any
of the handleXXX() methods.
+ *
+ * @param ctx invocation context
+ * @param command command
+ * @return true if the invocation should skip the current interceptor and move on to
the next in the chain, false otherwise.
+ */
+ protected abstract boolean skipInterception(InvocationContext ctx, VisitableCommand
command);
}