public class CommandInterceptor extends AbstractVisitor
Visitor
interface
allowing it to intercept invocations on VisitableCommand
s.
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.
VisitableCommand
,
Visitor
,
InterceptorChain
Modifier and Type | Field and Description |
---|---|
protected Configuration |
configuration |
protected org.apache.commons.logging.Log |
log |
protected boolean |
trace |
Constructor and Description |
---|
CommandInterceptor() |
Modifier and Type | Method and Description |
---|---|
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.
|
visitClearDataCommand, visitCollection, visitCommitCommand, visitCreateNodeCommand, visitEvictFqnCommand, visitExistsNodeCommand, visitGetChildrenNamesCommand, visitGetDataMapCommand, visitGetKeysCommand, visitGetKeyValueCommand, visitGetNodeCommand, visitGravitateDataCommand, visitInvalidateCommand, visitMoveCommand, visitOptimisticPrepareCommand, visitPrepareCommand, visitPutDataMapCommand, visitPutForExternalReadCommand, visitPutKeyValueCommand, visitRemoveKeyCommand, visitRemoveNodeCommand, visitRollbackCommand
protected org.apache.commons.logging.Log log
protected boolean trace
protected Configuration configuration
public CommandInterceptor getNext()
public boolean hasNext()
public void setNext(CommandInterceptor next)
next
- next interceptor in the chain.public Object invokeNextInterceptor(InvocationContext ctx, VisitableCommand command) throws Throwable
super.invoke().
ctx
- invocation contextcommand
- command to pass up the chain.Throwable
- in the event of problemsprotected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable
handleDefault
in class AbstractVisitor
ctx
- invocation contextcommand
- command to invokeThrowable
- in the event of problemsCopyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.