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
Direct Known Subclasses:
OptimisticTxInterceptor

public class TxInterceptor
extends BaseTransactionalContextInterceptor

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 AT jboss DOT org), Steve Woodcock (stevew@jofti.com), Galder Zamarreno

Field Summary
protected  CommandsFactory commandsFactory
           
protected  boolean optimistic
           
protected  RPCManager rpcManager
           
 
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
protected  void assertTxIsStillValid(Transaction tx)
           
protected  Object attachGtxAndPassUpChain(InvocationContext ctx, VisitableCommand command)
           
protected  PrepareCommand buildPrepareCommand(GlobalTransaction gtx, List modifications, boolean onePhaseCommit)
           
protected  void cleanupStaleLocks(InvocationContext ctx)
           
protected  Transaction createLocalTx()
          Creates and starts a local tx
 Map<String,Object> dumpStatistics()
           
 long getCommits()
           
 int getNumberOfSyncsRegistered()
           
 long getPrepares()
           
 long getRollbacks()
           
 boolean getStatisticsEnabled()
           
 Object handleDefault(InvocationContext ctx, VisitableCommand command)
          Tests if we already have a tx running.
 void intialize(RPCManager rpcManager, ContextFactory contextFactory, Notifier notifier, InvocationContextContainer icc, TransactionLog transactionLog, CommandsFactory factory, ComponentRegistry componentRegistry, LockManager lockManager)
           
protected  void replayModifications(InvocationContext ctx, Transaction ltx, PrepareCommand command)
          Replays modifications
 void resetStatistics()
           
protected  void runCommitPhase(InvocationContext ctx, GlobalTransaction gtx, List modifications, boolean onePhaseCommit)
          creates a commit()
 Object runPreparePhase(InvocationContext ctx, GlobalTransaction gtx, List<WriteCommand> modifications)
          Handles a local prepare - invoked by the sync handler.
protected  void runRollbackPhase(InvocationContext ctx, GlobalTransaction gtx, Transaction tx)
          creates a rollback()
 void setStatisticsEnabled(boolean enabled)
           
 Object visitCommitCommand(InvocationContext ctx, CommitCommand command)
          Visits a CommitCommand.
 Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command)
          Visits a InvalidateCommand.
 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, hasNext, invokeNextInterceptor, setNext
 
Methods inherited from class org.jboss.cache.commands.AbstractVisitor
visitClearDataCommand, visitCollection, visitCreateNodeCommand, visitEvictFqnCommand, visitExistsNodeCommand, visitGetChildrenNamesCommand, visitGetDataMapCommand, visitGetKeysCommand, visitGetKeyValueCommand, visitGetNodeCommand, visitGravitateDataCommand, visitMoveCommand, visitOptimisticPrepareCommand, visitPutDataMapCommand, visitPutForExternalReadCommand, visitPutKeyValueCommand, visitRemoveKeyCommand, visitRemoveNodeCommand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandsFactory

protected CommandsFactory commandsFactory

rpcManager

protected RPCManager rpcManager

optimistic

protected boolean optimistic
Constructor Detail

TxInterceptor

public TxInterceptor()
Method Detail

intialize

public void intialize(RPCManager rpcManager,
                      ContextFactory contextFactory,
                      Notifier notifier,
                      InvocationContextContainer icc,
                      TransactionLog transactionLog,
                      CommandsFactory factory,
                      ComponentRegistry componentRegistry,
                      LockManager lockManager)

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.

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:
return value
Throws:
Throwable

attachGtxAndPassUpChain

protected Object attachGtxAndPassUpChain(InvocationContext ctx,
                                         VisitableCommand command)
                                  throws Throwable
Throws:
Throwable

replayModifications

protected void replayModifications(InvocationContext ctx,
                                   Transaction ltx,
                                   PrepareCommand command)
                            throws Throwable
Replays modifications

Throws:
Throwable

buildPrepareCommand

protected PrepareCommand buildPrepareCommand(GlobalTransaction gtx,
                                             List modifications,
                                             boolean onePhaseCommit)

runCommitPhase

protected void runCommitPhase(InvocationContext ctx,
                              GlobalTransaction gtx,
                              List modifications,
                              boolean onePhaseCommit)
creates a commit()


cleanupStaleLocks

protected void cleanupStaleLocks(InvocationContext ctx)
                          throws Throwable
Throws:
Throwable

runRollbackPhase

protected void runRollbackPhase(InvocationContext ctx,
                                GlobalTransaction gtx,
                                Transaction tx)
creates a rollback()


runPreparePhase

public Object runPreparePhase(InvocationContext ctx,
                              GlobalTransaction gtx,
                              List<WriteCommand> 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.

Throws:
Throwable

assertTxIsStillValid

protected void assertTxIsStillValid(Transaction tx)

createLocalTx

protected Transaction createLocalTx()
                             throws Exception
Creates and starts a local tx

Throws:
Exception

resetStatistics

public void resetStatistics()

dumpStatistics

public Map<String,Object> dumpStatistics()

getStatisticsEnabled

public boolean getStatisticsEnabled()

setStatisticsEnabled

public void setStatisticsEnabled(boolean enabled)

getPrepares

public long getPrepares()

getCommits

public long getCommits()

getRollbacks

public long getRollbacks()

getNumberOfSyncsRegistered

public int getNumberOfSyncsRegistered()


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