org.jboss.cache.interceptors
Class MethodDispacherInterceptor

java.lang.Object
  extended by org.jboss.cache.interceptors.Interceptor
      extended by org.jboss.cache.interceptors.MethodDispacherInterceptor
All Implemented Interfaces:
InterceptorMBean
Direct Known Subclasses:
BaseRpcInterceptor, BaseTransactionalContextInterceptor, CacheLoaderInterceptor, CacheMgmtInterceptor, CacheStoreInterceptor, EvictionInterceptor, OptimisticInterceptor, PassivationInterceptor, PessimisticLockInterceptor

public abstract class MethodDispacherInterceptor
extends Interceptor

The purpose of this interceptor is to supply a nicer way of handling the interception of desired methods:

    - one can regiter to be notified on an particular method call by extending handleCalledMethod method.
       This would result in removal of switch statemenets in invoke
    - the parameters of the hendler methods are passes in strongly typed, rather than as an array of Objects
 
This interceptor acts as a switch that delegates method calls to handlers/methods.

Implementation notes: Current implementation checks to see the methods that are overwritten and does only perform calls to those methods. This is for avoiding the casts needed to build parameter list. If a non-overridden method is invoked, then next interceptor will be called.

Version:
2.1.0 todo - Refactor stuff in txint
Author:
Mircea.Markus@jboss.com

Field Summary
 
Fields inherited from class org.jboss.cache.interceptors.Interceptor
cache, configuration, last, log, next, trace
 
Constructor Summary
protected MethodDispacherInterceptor()
           
 
Method Summary
protected  Object handleAddChildMethod(InvocationContext ctx, GlobalTransaction tx, Fqn parentFqn, Object childName, Node cn, boolean createUndoOps)
          Handles CacheImpl._addChild(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, org.jboss.cache.Node, boolean)
protected  Object handleBlockChannelMethod(InvocationContext ctx)
          Handles CacheImpl._block()
protected  Object handleCommitMethod(InvocationContext ctx, GlobalTransaction globalTransaction)
          Handles CacheImpl.commit(org.jboss.cache.transaction.GlobalTransaction)
protected  Object handleDataGravitationCleanupMethod(InvocationContext ctx, Fqn primary, Fqn backup)
          Handles RemoteCacheInvocationDelegate.dataGravitationCleanup(org.jboss.cache.Fqn, org.jboss.cache.Fqn)
protected  Object handleEvictMethod(InvocationContext ctx, Fqn fqn)
          Handles evict()
protected  Object handleEvictVersionedNodeMethod(InvocationContext ctx, Fqn fqn, DataVersion dataVersion)
          Handles CacheImpl._evict(org.jboss.cache.Fqn, org.jboss.cache.optimistic.DataVersion)
protected  Object handleExistsMethod(InvocationContext ctx, Fqn fqn)
          Handles CacheImpl.exists(String)
protected  Object handleGetDataMapMethod(InvocationContext ctx, Fqn fqn)
          Handles CacheImpl._getData(org.jboss.cache.Fqn)
protected  Object handleGetChildrenNamesMethod(InvocationContext ctx, Fqn fqn)
          Handles CacheImpl._getChildrenNames(org.jboss.cache.Fqn)
protected  Object handleGetKeysMethod(InvocationContext ctx, Fqn fqn)
          Handles Cache.getKeys(Fqn)
protected  Object handleGetKeyValueMethod(InvocationContext ctx, Fqn fqn, Object key, boolean sendNodeEvent)
          Handles CacheImpl._get(org.jboss.cache.Fqn, Object, boolean)
protected  Object handleGetNodeMethod(InvocationContext ctx, Fqn fqn)
          Handles CacheImpl._get(org.jboss.cache.Fqn)
protected  Object handleLockMethod(InvocationContext ctx, Fqn fqn, NodeLock.LockType lockType, boolean recursive)
          Handles CacheImpl._lock(org.jboss.cache.Fqn, org.jboss.cache.lock.NodeLock.LockType, boolean)
protected  Object handleMoveMethod(InvocationContext ctx, Fqn from, Fqn to)
          Handles CacheImpl._move(org.jboss.cache.Fqn, org.jboss.cache.Fqn)
protected  Object handleOptimisticPrepareMethod(InvocationContext ctx, GlobalTransaction gtx, List modifications, Map data, org.jgroups.Address address, boolean onePhaseCommit)
          Handles CacheImpl.optimisticPrepare(org.jboss.cache.transaction.GlobalTransaction, java.util.List, java.util.Map, org.jgroups.Address, boolean)
protected  Object handlePrepareMethod(InvocationContext ctx, GlobalTransaction gtx, List modification, org.jgroups.Address coordinator, boolean onePhaseCommit)
          Handles CacheImpl.prepare(org.jboss.cache.transaction.GlobalTransaction, java.util.List, org.jgroups.Address, boolean)
protected  Object handlePrintMethod(InvocationContext ctx, Fqn fqn)
          Handles CacheImpl._print(org.jboss.cache.Fqn)
protected  Object handlePutDataEraseMethod(InvocationContext ctx, GlobalTransaction gt, Fqn fqn, Map newData, boolean createUndoOps, boolean eraseContents)
          Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, boolean)
protected  Object handlePutDataEraseVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Map data, boolean createUndoOps, boolean eraseContent, DataVersion dv)
          Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, boolean, org.jboss.cache.optimistic.DataVersion)
protected  Object handlePutDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Map data, boolean createUndoOps)
          Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, String, java.util.Map, boolean)
protected  Object handlePutDataVersionedMethod(InvocationContext ctx, GlobalTransaction globalTransaction, Fqn fqn, Map map, Boolean createUndoOps, DataVersion dataVersion)
          Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, org.jboss.cache.optimistic.DataVersion)
protected  Object handlePutForExternalReadMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Object key, Object value)
          Handles CacheImpl._putForExternalRead(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object)
protected  Object handlePutForExternalReadVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, Object value, DataVersion dv)
          Handles CacheImpl._putForExternalRead(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object, org.jboss.cache.optimistic.DataVersion)
protected  Object handlePutKeyValueMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, Object value, boolean createUndoOps)
          Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, String, Object, Object, boolean)
protected  Object handlePutKeyValueVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, Object value, boolean createUndoOps, DataVersion dv)
          Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object, boolean, org.jboss.cache.optimistic.DataVersion)
protected  Object handleReleaseAllLocksMethod(InvocationContext ctx, Fqn fqn)
          Handles CacheImpl._releaseAllLocks(org.jboss.cache.Fqn)
protected  Object handleRemoveDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps)
          Handles CacheImpl._removeData(org.jboss.cache.transaction.GlobalTransaction, Fqn, boolean)
protected  Object handleRemoveDataVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, boolean createUndoOps, DataVersion dv)
          Handles CacheImpl._removeData(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, boolean, org.jboss.cache.optimistic.DataVersion)
protected  Object handleRemoveKeyMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Object key, boolean createUndoOps)
          Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, String, Object, boolean)
protected  Object handleRemoveKeyVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, boolean createUndoOps, DataVersion dv)
          Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, boolean, org.jboss.cache.optimistic.DataVersion)
protected  Object handleRemoveNodeMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps)
          Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, String, boolean)
protected  Object handleRemoveNodeVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, boolean createUndoOps, DataVersion dv)
          Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, boolean, org.jboss.cache.optimistic.DataVersion)
protected  Object handleRollbackMethod(InvocationContext ctx, GlobalTransaction globalTransaction)
          Handles CacheImpl.rollback(org.jboss.cache.transaction.GlobalTransaction)
protected  Object handleUnblockChannelMethod(InvocationContext ctx)
          Handles CacheImpl._unblock()
 Object invoke(InvocationContext ctx)
          Acts like a 'switch case' that delegates the call to the appropriate method.
protected  boolean skipMethodCall(InvocationContext ctx)
          Each interceptor should extend this if it does not need any processing for current call.
 
Methods inherited from class org.jboss.cache.interceptors.Interceptor
assertTransactionValid, dumpStatistics, getLast, getNext, getStatisticsEnabled, initLogger, isActive, isPreparing, isValid, nextInterceptor, peekNode, resetStatistics, setCache, setLast, setNext, setStatisticsEnabled, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodDispacherInterceptor

protected MethodDispacherInterceptor()
Method Detail

invoke

public Object invoke(InvocationContext ctx)
              throws Throwable
Acts like a 'switch case' that delegates the call to the appropriate method.

Overrides:
invoke in class Interceptor
Throws:
Throwable

handleLockMethod

protected Object handleLockMethod(InvocationContext ctx,
                                  Fqn fqn,
                                  NodeLock.LockType lockType,
                                  boolean recursive)
                           throws Throwable
Handles CacheImpl._lock(org.jboss.cache.Fqn, org.jboss.cache.lock.NodeLock.LockType, boolean)

Throws:
Throwable

handleUnblockChannelMethod

protected Object handleUnblockChannelMethod(InvocationContext ctx)
                                     throws Throwable
Handles CacheImpl._unblock()

Throws:
Throwable

handleBlockChannelMethod

protected Object handleBlockChannelMethod(InvocationContext ctx)
                                   throws Throwable
Handles CacheImpl._block()

Throws:
Throwable

handleRemoveDataVersionedMethod

protected Object handleRemoveDataVersionedMethod(InvocationContext ctx,
                                                 GlobalTransaction gtx,
                                                 Fqn fqn,
                                                 boolean createUndoOps,
                                                 DataVersion dv)
                                          throws Throwable
Handles CacheImpl._removeData(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, boolean, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handleRemoveKeyVersionedMethod

protected Object handleRemoveKeyVersionedMethod(InvocationContext ctx,
                                                GlobalTransaction gtx,
                                                Fqn fqn,
                                                Object key,
                                                boolean createUndoOps,
                                                DataVersion dv)
                                         throws Throwable
Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, boolean, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handleRemoveNodeVersionedMethod

protected Object handleRemoveNodeVersionedMethod(InvocationContext ctx,
                                                 GlobalTransaction gtx,
                                                 Fqn fqn,
                                                 boolean createUndoOps,
                                                 DataVersion dv)
                                          throws Throwable
Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, boolean, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handleDataGravitationCleanupMethod

protected Object handleDataGravitationCleanupMethod(InvocationContext ctx,
                                                    Fqn primary,
                                                    Fqn backup)
                                             throws Throwable
Handles RemoteCacheInvocationDelegate.dataGravitationCleanup(org.jboss.cache.Fqn, org.jboss.cache.Fqn)

Throws:
Throwable

handlePutForExternalReadVersionedMethod

protected Object handlePutForExternalReadVersionedMethod(InvocationContext ctx,
                                                         GlobalTransaction gtx,
                                                         Fqn fqn,
                                                         Object key,
                                                         Object value,
                                                         DataVersion dv)
                                                  throws Throwable
Handles CacheImpl._putForExternalRead(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handlePutKeyValueVersionedMethod

protected Object handlePutKeyValueVersionedMethod(InvocationContext ctx,
                                                  GlobalTransaction gtx,
                                                  Fqn fqn,
                                                  Object key,
                                                  Object value,
                                                  boolean createUndoOps,
                                                  DataVersion dv)
                                           throws Throwable
Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object, boolean, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handlePutDataVersionedMethod

protected Object handlePutDataVersionedMethod(InvocationContext ctx,
                                              GlobalTransaction globalTransaction,
                                              Fqn fqn,
                                              Map map,
                                              Boolean createUndoOps,
                                              DataVersion dataVersion)
                                       throws Throwable
Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handlePutDataEraseVersionedMethod

protected Object handlePutDataEraseVersionedMethod(InvocationContext ctx,
                                                   GlobalTransaction gtx,
                                                   Fqn fqn,
                                                   Map data,
                                                   boolean createUndoOps,
                                                   boolean eraseContent,
                                                   DataVersion dv)
                                            throws Throwable
Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, boolean, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handleExistsMethod

protected Object handleExistsMethod(InvocationContext ctx,
                                    Fqn fqn)
                             throws Throwable
Handles CacheImpl.exists(String)

Throws:
Throwable

skipMethodCall

protected boolean skipMethodCall(InvocationContext ctx)
Each interceptor should extend this if it does not need any processing for current call. An sample usage would be: this interceptor is only interested if thre is one transaction going on. If so all handleXYZ would know that we have a transaction going and would not check its state.


handleEvictVersionedNodeMethod

protected Object handleEvictVersionedNodeMethod(InvocationContext ctx,
                                                Fqn fqn,
                                                DataVersion dataVersion)
                                         throws Throwable
Handles CacheImpl._evict(org.jboss.cache.Fqn, org.jboss.cache.optimistic.DataVersion)

Throws:
Throwable

handleEvictMethod

protected Object handleEvictMethod(InvocationContext ctx,
                                   Fqn fqn)
                            throws Throwable
Handles evict()

Throws:
Throwable

handlePrepareMethod

protected Object handlePrepareMethod(InvocationContext ctx,
                                     GlobalTransaction gtx,
                                     List modification,
                                     org.jgroups.Address coordinator,
                                     boolean onePhaseCommit)
                              throws Throwable
Handles CacheImpl.prepare(org.jboss.cache.transaction.GlobalTransaction, java.util.List, org.jgroups.Address, boolean)

Throws:
Throwable

handleOptimisticPrepareMethod

protected Object handleOptimisticPrepareMethod(InvocationContext ctx,
                                               GlobalTransaction gtx,
                                               List modifications,
                                               Map data,
                                               org.jgroups.Address address,
                                               boolean onePhaseCommit)
                                        throws Throwable
Handles CacheImpl.optimisticPrepare(org.jboss.cache.transaction.GlobalTransaction, java.util.List, java.util.Map, org.jgroups.Address, boolean)

Throws:
Throwable

handleCommitMethod

protected Object handleCommitMethod(InvocationContext ctx,
                                    GlobalTransaction globalTransaction)
                             throws Throwable
Handles CacheImpl.commit(org.jboss.cache.transaction.GlobalTransaction)

Throws:
Throwable

handleRemoveDataMethod

protected Object handleRemoveDataMethod(InvocationContext ctx,
                                        GlobalTransaction tx,
                                        Fqn fqn,
                                        boolean createUndoOps)
                                 throws Throwable
Handles CacheImpl._removeData(org.jboss.cache.transaction.GlobalTransaction, Fqn, boolean)

Throws:
Throwable

handleRemoveKeyMethod

protected Object handleRemoveKeyMethod(InvocationContext ctx,
                                       GlobalTransaction tx,
                                       Fqn fqn,
                                       Object key,
                                       boolean createUndoOps)
                                throws Throwable
Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, String, Object, boolean)

Throws:
Throwable

handleRemoveNodeMethod

protected Object handleRemoveNodeMethod(InvocationContext ctx,
                                        GlobalTransaction tx,
                                        Fqn fqn,
                                        boolean createUndoOps)
                                 throws Throwable
Handles CacheImpl._remove(org.jboss.cache.transaction.GlobalTransaction, String, boolean)

Throws:
Throwable

handleRollbackMethod

protected Object handleRollbackMethod(InvocationContext ctx,
                                      GlobalTransaction globalTransaction)
                               throws Throwable
Handles CacheImpl.rollback(org.jboss.cache.transaction.GlobalTransaction)

Throws:
Throwable

handleGetDataMapMethod

protected Object handleGetDataMapMethod(InvocationContext ctx,
                                        Fqn fqn)
                                 throws Throwable
Handles CacheImpl._getData(org.jboss.cache.Fqn)

Throws:
Throwable

handleGetKeysMethod

protected Object handleGetKeysMethod(InvocationContext ctx,
                                     Fqn fqn)
                              throws Throwable
Handles Cache.getKeys(Fqn)

Throws:
Throwable

handlePrintMethod

protected Object handlePrintMethod(InvocationContext ctx,
                                   Fqn fqn)
                            throws Throwable
Handles CacheImpl._print(org.jboss.cache.Fqn)

Throws:
Throwable

handleReleaseAllLocksMethod

protected Object handleReleaseAllLocksMethod(InvocationContext ctx,
                                             Fqn fqn)
                                      throws Throwable
Handles CacheImpl._releaseAllLocks(org.jboss.cache.Fqn)

Throws:
Throwable

handleGetChildrenNamesMethod

protected Object handleGetChildrenNamesMethod(InvocationContext ctx,
                                              Fqn fqn)
                                       throws Throwable
Handles CacheImpl._getChildrenNames(org.jboss.cache.Fqn)

Throws:
Throwable

handleGetNodeMethod

protected Object handleGetNodeMethod(InvocationContext ctx,
                                     Fqn fqn)
                              throws Throwable
Handles CacheImpl._get(org.jboss.cache.Fqn)

Throws:
Throwable

handleGetKeyValueMethod

protected Object handleGetKeyValueMethod(InvocationContext ctx,
                                         Fqn fqn,
                                         Object key,
                                         boolean sendNodeEvent)
                                  throws Throwable
Handles CacheImpl._get(org.jboss.cache.Fqn, Object, boolean)

Throws:
Throwable

handleAddChildMethod

protected Object handleAddChildMethod(InvocationContext ctx,
                                      GlobalTransaction tx,
                                      Fqn parentFqn,
                                      Object childName,
                                      Node cn,
                                      boolean createUndoOps)
                               throws Throwable
Handles CacheImpl._addChild(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, org.jboss.cache.Node, boolean)

Throws:
Throwable

handleMoveMethod

protected Object handleMoveMethod(InvocationContext ctx,
                                  Fqn from,
                                  Fqn to)
                           throws Throwable
Handles CacheImpl._move(org.jboss.cache.Fqn, org.jboss.cache.Fqn)

Throws:
Throwable

handlePutKeyValueMethod

protected Object handlePutKeyValueMethod(InvocationContext ctx,
                                         GlobalTransaction gtx,
                                         Fqn fqn,
                                         Object key,
                                         Object value,
                                         boolean createUndoOps)
                                  throws Throwable
Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, String, Object, Object, boolean)

Throws:
Throwable

handlePutForExternalReadMethod

protected Object handlePutForExternalReadMethod(InvocationContext ctx,
                                                GlobalTransaction tx,
                                                Fqn fqn,
                                                Object key,
                                                Object value)
                                         throws Throwable
Handles CacheImpl._putForExternalRead(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object)

Throws:
Throwable

handlePutDataMethod

protected Object handlePutDataMethod(InvocationContext ctx,
                                     GlobalTransaction tx,
                                     Fqn fqn,
                                     Map data,
                                     boolean createUndoOps)
                              throws Throwable
Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, String, java.util.Map, boolean)

Throws:
Throwable

handlePutDataEraseMethod

protected Object handlePutDataEraseMethod(InvocationContext ctx,
                                          GlobalTransaction gt,
                                          Fqn fqn,
                                          Map newData,
                                          boolean createUndoOps,
                                          boolean eraseContents)
                                   throws Throwable
Handles CacheImpl._put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, boolean)

Throws:
Throwable


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