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, InterceptorMBean
Direct Known Subclasses:
BaseRpcInterceptor, BaseTransactionalContextInterceptor, CacheLoaderInterceptor, CacheMgmtInterceptor, CallInterceptor, EvictionInterceptor, Interceptor, MarshalledValueInterceptor, OptimisticInterceptor, PassivationInterceptor, PostProcessingCommandInterceptor, SkipCheckChainedInterceptor

public class CommandInterceptor
extends AbstractVisitor
implements InterceptorMBean

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
 Map<String,Object> dumpStatistics()
          Returns a map of statistics.
 CommandInterceptor getNext()
          Retrieves the next interceptor in the chain.
 boolean getStatisticsEnabled()
          Returns whether an interceptor's statistics are being captured.
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 resetStatistics()
          Resets statistics gathered.
 void setNext(CommandInterceptor next)
          Sets the next interceptor in the chain to the interceptor passed in.
 void setStatisticsEnabled(boolean enabled)
          Enables an interceptor's cache statistics If true, the interceptor will capture statistics and make them available through the mbean.
 
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

getStatisticsEnabled

public boolean getStatisticsEnabled()
Description copied from interface: InterceptorMBean
Returns whether an interceptor's statistics are being captured.

Specified by:
getStatisticsEnabled in interface InterceptorMBean
Returns:
true if gathering statistics for JMX is enabled on this interceptor.

setStatisticsEnabled

public void setStatisticsEnabled(boolean enabled)
Description copied from interface: InterceptorMBean
Enables an interceptor's cache statistics If true, the interceptor will capture statistics and make them available through the mbean.

Specified by:
setStatisticsEnabled in interface InterceptorMBean
Parameters:
enabled - whether gathering statistics for JMX are enabled.

dumpStatistics

public Map<String,Object> dumpStatistics()
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.

Specified by:
dumpStatistics in interface InterceptorMBean
Returns:
an empty map

resetStatistics

public void resetStatistics()
Resets statistics gathered. Is a no-op, and should be overridden if it is to be meaningful.

Specified by:
resetStatistics in interface InterceptorMBean

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.