org.jboss.cache.interceptors
Class TxInterceptor

java.lang.Object
  extended by org.jboss.cache.commands.AbstractVisitor
      extended by org.jboss.cache.interceptors.base.CommandInterceptor
          extended by org.jboss.cache.interceptors.BaseTransactionalContextInterceptor
              extended by org.jboss.cache.interceptors.TxInterceptor
All Implemented Interfaces:
Visitor, InterceptorMBean, TxInterceptorMBean

public class TxInterceptor
extends BaseTransactionalContextInterceptor
implements TxInterceptorMBean

This interceptor is the new default at the head of all interceptor chains, and makes transactional attributes available to all interceptors in the chain. This interceptor is also responsible for registering for synchronisation on transaction completion.

Author:
Manik Surtani (manik@jboss.org), Steve Woodcock (stevew@jofti.com)

Nested Class Summary
 class TxInterceptor.ModificationsReplayVisitor
           
 
Field Summary
 
Fields inherited from class org.jboss.cache.interceptors.BaseTransactionalContextInterceptor
txManager, txTable
 
Fields inherited from class org.jboss.cache.interceptors.base.CommandInterceptor
configuration, log, trace
 
Constructor Summary
TxInterceptor()
           
 
Method Summary
 Map<String,Object> dumpStatistics()
          Returns a map of statistics.
 long getCommits()
          Returns the number of transaction commits
 long getPrepares()
          Returns the number of transaction prepares
 long getRollbacks()
          Returns the number of transaction rollbacks
 Object handleDefault(InvocationContext ctx, VisitableCommand command)
          Tests if we already have a tx running.
 void intialize(RPCManager rpcManager, Notifier notifier, InvocationContextContainer icc, LifecycleManager lifecycleManager, CommandsFactory factory)
           
 void resetStatistics()
          Resets statistics gathered.
protected  void runCommitPhase(InvocationContext ctx, GlobalTransaction gtx, Transaction tx, List modifications, List clModifications, boolean onePhaseCommit)
          creates a commit() MethodCall and feeds it to handleCommitRollback();
 Object runPreparePhase(InvocationContext ctx, GlobalTransaction gtx, List<ReversibleCommand> modifications)
          Handles a local prepare - invoked by the sync handler.
protected  void runRollbackPhase(InvocationContext ctx, GlobalTransaction gtx, Transaction tx, List<ReversibleCommand> modifications)
          creates a rollback() MethodCall and feeds it to handleCommitRollback();
 Object visitCommitCommand(InvocationContext ctx, CommitCommand command)
          Visits a CommitCommand.
 Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command)
          Visits a InvalidateCommand.
 Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command)
          Visits a OptimisticPrepareCommand.
 Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command)
          Visits a PrepareCommand.
 Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command)
          Visits a RollbackCommand.
 
Methods inherited from class org.jboss.cache.interceptors.BaseTransactionalContextInterceptor
copyInvocationScopeOptionsToTxScope, isRollingBack, setTransactionalContext
 
Methods inherited from class org.jboss.cache.interceptors.base.CommandInterceptor
getNext, getStatisticsEnabled, hasNext, invokeNextInterceptor, setNext, setStatisticsEnabled
 
Methods inherited from class org.jboss.cache.commands.AbstractVisitor
visitCollection, visitCreateNodeCommand, visitEvictFqnCommand, visitExistsNodeCommand, visitGetChildrenNamesCommand, visitGetDataMapCommand, visitGetKeysCommand, visitGetKeyValueCommand, visitGetNodeCommand, visitGravitateDataCommand, visitMoveCommand, visitPutDataMapCommand, visitPutKeyValueCommand, visitRemoveDataCommand, visitRemoveKeyCommand, visitRemoveNodeCommand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.cache.interceptors.InterceptorMBean
getStatisticsEnabled, setStatisticsEnabled
 

Constructor Detail

TxInterceptor

public TxInterceptor()
Method Detail

intialize

public void intialize(RPCManager rpcManager,
                      Notifier notifier,
                      InvocationContextContainer icc,
                      LifecycleManager lifecycleManager,
                      CommandsFactory factory)

visitOptimisticPrepareCommand

public Object visitOptimisticPrepareCommand(InvocationContext ctx,
                                            OptimisticPrepareCommand command)
                                     throws Throwable
Description copied from interface: Visitor
Visits a OptimisticPrepareCommand.

Specified by:
visitOptimisticPrepareCommand in interface Visitor
Overrides:
visitOptimisticPrepareCommand in class AbstractVisitor
Parameters:
ctx - invocation context
command - command to visit
Returns:
response from the visit
Throws:
Throwable - in the event of problems.

visitPrepareCommand

public Object visitPrepareCommand(InvocationContext ctx,
                                  PrepareCommand command)
                           throws Throwable
Description copied from interface: Visitor
Visits a PrepareCommand.

Specified by:
visitPrepareCommand in interface Visitor
Overrides:
visitPrepareCommand in class AbstractVisitor
Parameters:
ctx - invocation context
command - command to visit
Returns:
response from the visit
Throws:
Throwable - in the event of problems.

visitCommitCommand

public Object visitCommitCommand(InvocationContext ctx,
                                 CommitCommand command)
                          throws Throwable
Description copied from interface: Visitor
Visits a CommitCommand.

Specified by:
visitCommitCommand in interface Visitor
Overrides:
visitCommitCommand in class AbstractVisitor
Parameters:
ctx - invocation context
command - command to visit
Returns:
response from the visit
Throws:
Throwable - in the event of problems.

visitRollbackCommand

public Object visitRollbackCommand(InvocationContext ctx,
                                   RollbackCommand command)
                            throws Throwable
Description copied from interface: Visitor
Visits a RollbackCommand.

Specified by:
visitRollbackCommand in interface Visitor
Overrides:
visitRollbackCommand in class AbstractVisitor
Parameters:
ctx - invocation context
command - command to visit
Returns:
response from the visit
Throws:
Throwable - in the event of problems.

getPrepares

public long getPrepares()
Description copied from interface: TxInterceptorMBean
Returns the number of transaction prepares

Specified by:
getPrepares in interface TxInterceptorMBean
Returns:
the number of prepares

getCommits

public long getCommits()
Description copied from interface: TxInterceptorMBean
Returns the number of transaction commits

Specified by:
getCommits in interface TxInterceptorMBean
Returns:
the number of commits

getRollbacks

public long getRollbacks()
Description copied from interface: TxInterceptorMBean
Returns the number of transaction rollbacks

Specified by:
getRollbacks in interface TxInterceptorMBean
Returns:
the number of rollbacks

resetStatistics

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

Specified by:
resetStatistics in interface InterceptorMBean
Overrides:
resetStatistics in class CommandInterceptor

dumpStatistics

public Map<String,Object> dumpStatistics()
Description copied from class: CommandInterceptor
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
Overrides:
dumpStatistics in class CommandInterceptor
Returns:
an empty map

visitInvalidateCommand

public Object visitInvalidateCommand(InvocationContext ctx,
                                     InvalidateCommand command)
                              throws Throwable
Description copied from interface: Visitor
Visits a InvalidateCommand.

Specified by:
visitInvalidateCommand in interface Visitor
Overrides:
visitInvalidateCommand in class AbstractVisitor
Parameters:
ctx - invocation context
command - command to visit
Returns:
response from the visit
Throws:
Throwable - in the event of problems.

handleDefault

public Object handleDefault(InvocationContext ctx,
                            VisitableCommand command)
                     throws Throwable
Tests if we already have a tx running. If so, register a sync handler for this method invocation. if not, create a local tx if we're using opt locking.

Overrides:
handleDefault in class CommandInterceptor
Parameters:
ctx - invocation context
command - command to invoke
Returns:
Throws:
Throwable

runCommitPhase

protected void runCommitPhase(InvocationContext ctx,
                              GlobalTransaction gtx,
                              Transaction tx,
                              List modifications,
                              List clModifications,
                              boolean onePhaseCommit)
creates a commit() MethodCall and feeds it to handleCommitRollback();


runRollbackPhase

protected void runRollbackPhase(InvocationContext ctx,
                                GlobalTransaction gtx,
                                Transaction tx,
                                List<ReversibleCommand> modifications)
creates a rollback() MethodCall and feeds it to handleCommitRollback();

Parameters:
gtx -

runPreparePhase

public Object runPreparePhase(InvocationContext ctx,
                              GlobalTransaction gtx,
                              List<ReversibleCommand> modifications)
                       throws Throwable
Handles a local prepare - invoked by the sync handler. Tests if the current tx matches the gtx passed in to the method call and passes the prepare() call up the chain.

Returns:
Throws:
Throwable


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