org.jboss.cache.interceptors.base
Class CommandInterceptor

java.lang.Object
  extended by org.jboss.cache.commands.AbstractVisitor
      extended by org.jboss.cache.interceptors.base.CommandInterceptor
All Implemented Interfaces:
Visitor
Direct Known Subclasses:
BaseRpcInterceptor, BaseTransactionalContextInterceptor, BatchingInterceptor, CallInterceptor, EvictionInterceptor, Interceptor, JmxStatsCommandInterceptor, MarshalledValueInterceptor, OptimisticInterceptor, PrePostProcessingCommandInterceptor, SkipCheckChainedInterceptor

public class CommandInterceptor
extends AbstractVisitor

This is the base class for all interceptors to extend, and implements the Visitor interface allowing it to intercept invocations on VisitableCommands.

Commands are created either by the CacheInvocationDelegate (for invocations on the Cache public interface), the NodeInvocationDelegate for invocations on the Node public interface, or by the CommandAwareRpcDispatcher for remotely originating invocations, and are passed up the interceptor chain by using the InterceptorChain helper class.

When writing interceptors, authors can either override a specific visitXXX() method (such as AbstractVisitor.visitGetKeyValueCommand(org.jboss.cache.InvocationContext , org.jboss.cache.commands.read.GetKeyValueCommand)) or the more generic handleDefault(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand) which is the default behaviour of any visit method, as defined in AbstractVisitor.handleDefault(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand).

The preferred approach is to override the specific visitXXX() methods that are of interest rather than to override 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.

Since:
2.2
Author:
Mircea.Markus@jboss.com
See Also:
VisitableCommand, Visitor, InterceptorChain

Field Summary
protected  Configuration configuration
           
protected  org.apache.commons.logging.Log log
           
protected  boolean trace
           
 
Constructor Summary
CommandInterceptor()
           
 
Method Summary
 CommandInterceptor getNext()
          Retrieves the next interceptor in the chain.
protected  Object handleDefault(InvocationContext ctx, VisitableCommand command)
          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.
 boolean hasNext()
           
 Object invokeNextInterceptor(InvocationContext ctx, VisitableCommand command)
          Invokes the next interceptor in the chain.
 void setNext(CommandInterceptor next)
          Sets the next interceptor in the chain to the interceptor passed in.
 
Methods inherited from class org.jboss.cache.commands.AbstractVisitor
visitClearDataCommand, visitCollection, visitCommitCommand, visitCreateNodeCommand, visitEvictFqnCommand, visitExistsNodeCommand, visitGetChildrenNamesCommand, visitGetDataMapCommand, visitGetKeysCommand, visitGetKeyValueCommand, visitGetNodeCommand, visitGravitateDataCommand, visitInvalidateCommand, visitMoveCommand, visitOptimisticPrepareCommand, visitPrepareCommand, visitPutDataMapCommand, visitPutForExternalReadCommand, visitPutKeyValueCommand, visitRemoveKeyCommand, visitRemoveNodeCommand, visitRollbackCommand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected org.apache.commons.logging.Log log

trace

protected boolean trace

configuration

protected Configuration configuration
Constructor Detail

CommandInterceptor

public CommandInterceptor()
Method Detail

getNext

public CommandInterceptor getNext()
Retrieves the next interceptor in the chain.

Returns:
the next interceptor in the chain.

hasNext

public boolean hasNext()
Returns:
true if there is another interceptor in the chain after this; false otherwise.

setNext

public void setNext(CommandInterceptor next)
Sets the next interceptor in the chain to the interceptor passed in.

Parameters:
next - next interceptor in the chain.

invokeNextInterceptor

public Object invokeNextInterceptor(InvocationContext ctx,
                                    VisitableCommand command)
                             throws Throwable
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
super.invoke()
.

Parameters:
ctx - invocation context
command - command to pass up the chain.
Returns:
return value of the invocation
Throws:
Throwable - in the event of problems

handleDefault

protected Object handleDefault(InvocationContext ctx,
                               VisitableCommand command)
                        throws Throwable
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.

Overrides:
handleDefault in class AbstractVisitor
Parameters:
ctx - invocation context
command - command to invoke
Returns:
return value
Throws:
Throwable - in the event of problems


Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.