org.infinispan.interceptors
Class TxInterceptor

java.lang.Object
  extended by org.infinispan.commands.AbstractVisitor
      extended by org.infinispan.interceptors.base.CommandInterceptor
          extended by org.infinispan.interceptors.BaseTransactionalContextInterceptor
              extended by org.infinispan.interceptors.TxInterceptor
All Implemented Interfaces:
Visitor
Direct Known Subclasses:
DistTxInterceptor

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.

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

Field Summary
protected  CommandsFactory commandsFactory
           
 
Fields inherited from class org.infinispan.interceptors.BaseTransactionalContextInterceptor
txManager, txTable
 
Fields inherited from class org.infinispan.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<WriteCommand> modifications, boolean onePhaseCommit)
           
protected  void cleanupStaleLocks(InvocationContext ctx)
           
protected  Transaction createLocalTx()
          Creates and starts a local tx
protected  VisitableCommand getCommandToReplay(VisitableCommand modification)
          Designed to be overridden.
 long getCommits()
           
 long getPrepares()
           
 long getRollbacks()
           
 boolean getStatisticsEnabled()
           
 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.
 void intialize(CacheManager cacheManager, ContextFactory contextFactory, CacheNotifier notifier, InvocationContextContainer icc, CommandsFactory factory, ComponentRegistry componentRegistry, LockManager lockManager, TransactionLog transactionLog)
           
 void resetStatistics()
           
protected  void runCommitPhase(InvocationContext ctx, GlobalTransaction gtx, List<WriteCommand> 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)
           
 Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command)
           
 Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command)
           
 
Methods inherited from class org.infinispan.interceptors.BaseTransactionalContextInterceptor
injectDependencies, isRollingBack, setTransactionalContext
 
Methods inherited from class org.infinispan.interceptors.base.CommandInterceptor
getNext, hasNext, invokeNextInterceptor, setNext
 
Methods inherited from class org.infinispan.commands.AbstractVisitor
visitClearCommand, visitCollection, visitEvictCommand, visitGetKeyValueCommand, visitInvalidateCommand, visitPutKeyValueCommand, visitPutMapCommand, visitRemoveCommand, visitReplaceCommand, visitSizeCommand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandsFactory

protected CommandsFactory commandsFactory
Constructor Detail

TxInterceptor

public TxInterceptor()
Method Detail

intialize

public void intialize(CacheManager cacheManager,
                      ContextFactory contextFactory,
                      CacheNotifier notifier,
                      InvocationContextContainer icc,
                      CommandsFactory factory,
                      ComponentRegistry componentRegistry,
                      LockManager lockManager,
                      TransactionLog transactionLog)

visitPrepareCommand

public Object visitPrepareCommand(InvocationContext ctx,
                                  PrepareCommand command)
                           throws Throwable
Specified by:
visitPrepareCommand in interface Visitor
Overrides:
visitPrepareCommand in class AbstractVisitor
Throws:
Throwable

visitCommitCommand

public Object visitCommitCommand(InvocationContext ctx,
                                 CommitCommand command)
                          throws Throwable
Specified by:
visitCommitCommand in interface Visitor
Overrides:
visitCommitCommand in class AbstractVisitor
Throws:
Throwable

visitRollbackCommand

public Object visitRollbackCommand(InvocationContext ctx,
                                   RollbackCommand command)
                            throws Throwable
Specified by:
visitRollbackCommand in interface Visitor
Overrides:
visitRollbackCommand in class AbstractVisitor
Throws:
Throwable

handleDefault

public Object handleDefault(InvocationContext ctx,
                            VisitableCommand command)
                     throws Throwable
Description copied from class: CommandInterceptor
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 CommandInterceptor
Parameters:
ctx - invocation context
command - command to invoke
Returns:
return value
Throws:
Throwable - in the event of problems

attachGtxAndPassUpChain

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

getCommandToReplay

protected VisitableCommand getCommandToReplay(VisitableCommand modification)
Designed to be overridden. Returns a VisitableCommand fit for replaying locally, based on the modification passed in. If a null value is returned, this means that the command should not be replayed.

Parameters:
modification - modification in a prepare call
Returns:
a VisitableCommand representing this modification, fit for replaying, or null if the command should not be replayed.

buildPrepareCommand

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

runCommitPhase

protected void runCommitPhase(InvocationContext ctx,
                              GlobalTransaction gtx,
                              List<WriteCommand> 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()

getStatisticsEnabled

public boolean getStatisticsEnabled()

setStatisticsEnabled

public void setStatisticsEnabled(boolean enabled)

getPrepares

public long getPrepares()

getCommits

public long getCommits()

getRollbacks

public long getRollbacks()


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