org.jboss.tm
Class TxManager

java.lang.Object
  extended byorg.jboss.tm.TxManager
All Implemented Interfaces:
JBossXATerminator (src) , TransactionLocalDelegate (src) , TransactionManager (src) , TransactionPropagationContextFactory (src) , TransactionPropagationContextImporter (src) , TransactionTimeoutConfiguration (src) , XATerminator (src)

public class TxManager
extends java.lang.Object
implements TransactionManager (src) , TransactionPropagationContextImporter (src) , TransactionPropagationContextFactory (src) , TransactionLocalDelegate (src) , TransactionTimeoutConfiguration (src) , JBossXATerminator (src)

Our TransactionManager implementation.


Method Summary
 void associateThread(Transaction (src)  transaction)
           
 void begin()
          Begin a new transaction.
 void cancelWork(Work (src)  work, Xid (src)  xid)
          Invoked when the work fails
 void commit()
          Commit the transaction associated with the currently running thread.
 void commit(Xid (src)  xid, boolean onePhase)
          Commit the transaction
 boolean containsValue(TransactionLocal (src)  local, Transaction (src)  tx)
          does TransactionImpl contain object?
 Transaction (src) disassociateThread()
          The following 2 methods are here to provide association and disassociation of the thread.
 void endWork(Work (src)  work, Xid (src)  xid)
          Invoked when transaction inflow work ends
 void forget(Xid (src)  xid)
          Forget the transaction
 long getCommitCount()
          A count of the transactions that have been committed
 int getDefaultTransactionTimeout()
          Get the default transaction timeout.
 boolean getGlobalIdsEnabled()
          Getter for attribute globalIdsEnabled.
static TxManager (src) getInstance()
          Get a reference to the singleton instance.
 long getRollbackCount()
          A count of the transactions that have been rolled back
 int getStatus()
          Return the status of the transaction associated with the currently running thread, or Status.STATUS_NO_TRANSACTION if no active transaction is currently associated.
 Transaction (src) getTransaction()
          Return the transaction currently associated with the invoking thread, or null if no active transaction is currently associated.
 int getTransactionCount()
          Return the number of active transactions
 java.lang.Object getTransactionPropagationContext()
          Return a TPC for the current transaction.
 java.lang.Object getTransactionPropagationContext(Transaction (src)  tx)
          Return a TPC for the argument transaction.
 int getTransactionTimeout()
          Get the transaction timeout.
 java.lang.Object getValue(TransactionLocal (src)  local, Transaction (src)  tx)
          get the transaction local value.
 Transaction (src) importTransactionPropagationContext(java.lang.Object tpc)
          Import a transaction propagation context into this TM.
 boolean isInterruptThreads()
          Is thread interruption enabled at transaction timeout
 int prepare(Xid (src)  xid)
          Prepare the transaction
 Xid (src) [] recover(int flag)
          Retrieve xids that are recoverable
 void registerWork(Work (src)  work, Xid (src)  xid, long timeout)
          Invoked for transaction inflow of work
 void resume(Transaction (src)  transaction)
          Resume a transaction.
 void rollback()
          Roll back the transaction associated with the currently running thread.
 void rollback(Xid (src)  xid)
          Rollback the transaction
 void setDefaultTransactionTimeout(int seconds)
          Set the default transaction timeout for new transactions.
 void setGlobalIdsEnabled(boolean newValue)
          Setter for attribute globalIdsEnabled.
 void setInterruptThreads(boolean interruptThreads)
          Enable/disable thread interruption at transaction timeout.
 void setRollbackOnly()
          Mark the transaction associated with the currently running thread so that the only possible outcome is a rollback.
 void setTransactionTimeout(int seconds)
          Set the transaction timeout for new transactions started by the calling thread.
 void startWork(Work (src)  work, Xid (src)  xid)
          Invoked for transaction inflow of work
 void storeValue(TransactionLocal (src)  local, Transaction (src)  tx, java.lang.Object value)
          put the value in the TransactionImpl map
 Transaction (src) suspend()
          Suspend the transaction currently associated with the current thread, and return it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static TxManager (src)  getInstance()
Get a reference to the singleton instance.


setGlobalIdsEnabled

public void setGlobalIdsEnabled(boolean newValue)
Setter for attribute globalIdsEnabled.


getGlobalIdsEnabled

public boolean getGlobalIdsEnabled()
Getter for attribute globalIdsEnabled.


setInterruptThreads

public void setInterruptThreads(boolean interruptThreads)
Enable/disable thread interruption at transaction timeout.

Parameters:
interruptThreads - pass true to interrupt threads, false otherwise

isInterruptThreads

public boolean isInterruptThreads()
Is thread interruption enabled at transaction timeout

Returns:
true for interrupt threads, false otherwise

begin

public void begin()
           throws NotSupportedException (src) ,
                  SystemException (src) 
Begin a new transaction. The new transaction will be associated with the calling thread.

Specified by:
begin in interface TransactionManager (src)
Throws:
NotSupportedException (src) - If the calling thread is already associated with a transaction, and nested transactions are not supported.
SystemException (src) - If the transaction service fails in an unexpected way.

commit

public void commit()
            throws RollbackException (src) ,
                   HeuristicMixedException (src) ,
                   HeuristicRollbackException (src) ,
                   java.lang.SecurityException,
                   java.lang.IllegalStateException,
                   SystemException (src) 
Commit the transaction associated with the currently running thread.

Specified by:
commit in interface TransactionManager (src)
Throws:
java.lang.SecurityException - If the caller is not allowed to commit this transaction.
SystemException (src) - If the transaction service fails in an unexpected way.
RollbackException (src) - If the transaction was marked for rollback only, the transaction is rolled back and this exception is thrown.
HeuristicMixedException (src) - If a heuristic decision was made and some some parts of the transaction have been committed while other parts have been rolled back.
java.lang.IllegalStateException - If the calling thread is not associated with a transaction.
HeuristicRollbackException (src) - If a heuristic decision to roll back the transaction was made.

getStatus

public int getStatus()
              throws SystemException (src) 
Return the status of the transaction associated with the currently running thread, or Status.STATUS_NO_TRANSACTION if no active transaction is currently associated.

Specified by:
getStatus in interface TransactionManager (src)
Returns:
The status of the transaction. This is one of the Status (src) constants. If no transaction is associated with the calling thread, Status.STATUS_NO_TRANSACTION is returned.
Throws:
SystemException (src) - If the transaction service fails in an unexpected way.

getTransaction

public Transaction (src)  getTransaction()
                           throws SystemException (src) 
Return the transaction currently associated with the invoking thread, or null if no active transaction is currently associated.

Specified by:
getTransaction in interface TransactionManager (src)
Returns:
The transaction associated with the calling thread, or null if the calling thread is not associated with a transaction.
Throws:
SystemException (src) - If the transaction service fails in an unexpected way.

resume

public void resume(Transaction (src)  transaction)
            throws InvalidTransactionException (src) ,
                   java.lang.IllegalStateException,
                   SystemException (src) 
Resume a transaction. Note: This will not enlist any resources involved in this transaction. According to JTA1.0.1 specification section 3.2.3, that is the responsibility of the application server.

Specified by:
resume in interface TransactionManager (src)
Parameters:
transaction - The transaction to be associated with the calling thread.
Throws:
java.lang.IllegalStateException - If the calling thread is already associated with a transaction.
SystemException (src) - If the transaction service fails in an unexpected way.
InvalidTransactionException (src) - If the argument does not represent a valid transaction.

suspend

public Transaction (src)  suspend()
                    throws SystemException (src) 
Suspend the transaction currently associated with the current thread, and return it. Note: This will not delist any resources involved in this transaction. According to JTA1.0.1 specification section 3.2.3, that is the responsibility of the application server.

Specified by:
suspend in interface TransactionManager (src)
Returns:
The transaction that the calling thread was associated with, or null if the calling thread was not associated with a transaction.
Throws:
SystemException (src) - If the transaction service fails in an unexpected way.

rollback

public void rollback()
              throws java.lang.IllegalStateException,
                     java.lang.SecurityException,
                     SystemException (src) 
Roll back the transaction associated with the currently running thread.

Specified by:
rollback in interface TransactionManager (src)
Throws:
SystemException (src) - If the transaction service fails in an unexpected way.
java.lang.IllegalStateException - If the transaction is in a state where it cannot be rolled back. This could be because the calling thread is not associated with a transaction, or because it is in the prepared state.
java.lang.SecurityException - If the caller is not allowed to roll back this transaction.

setRollbackOnly

public void setRollbackOnly()
                     throws java.lang.IllegalStateException,
                            SystemException (src) 
Mark the transaction associated with the currently running thread so that the only possible outcome is a rollback.

Specified by:
setRollbackOnly in interface TransactionManager (src)
Throws:
SystemException (src) - If the transaction service fails in an unexpected way.
java.lang.IllegalStateException - If the transaction is in a state where it cannot be rolled back. This could be because the calling thread is not associated with a transaction, or because it is in the prepared state.

getTransactionTimeout

public int getTransactionTimeout()
Description copied from interface: TransactionTimeoutConfiguration (src)
Get the transaction timeout.

Specified by:
getTransactionTimeout in interface TransactionTimeoutConfiguration (src)
Returns:
the timeout in seconds associated with this thread

setTransactionTimeout

public void setTransactionTimeout(int seconds)
                           throws SystemException (src) 
Set the transaction timeout for new transactions started by the calling thread.

Specified by:
setTransactionTimeout in interface TransactionManager (src)
Parameters:
seconds - The new timeout value, in seconds. If this parameter is 0, the timeout value is reset to the default value.
Throws:
SystemException (src) - If the transaction service fails in an unexpected way.

setDefaultTransactionTimeout

public void setDefaultTransactionTimeout(int seconds)
Set the default transaction timeout for new transactions. This default value is used if setTransactionTimeout() was never called, or if it was called with a value of 0.


getDefaultTransactionTimeout

public int getDefaultTransactionTimeout()
Get the default transaction timeout.

Returns:
Default transaction timeout in seconds.

disassociateThread

public Transaction (src)  disassociateThread()
The following 2 methods are here to provide association and disassociation of the thread.


associateThread

public void associateThread(Transaction (src)  transaction)

getTransactionCount

public int getTransactionCount()
Return the number of active transactions


getCommitCount

public long getCommitCount()
A count of the transactions that have been committed


getRollbackCount

public long getRollbackCount()
A count of the transactions that have been rolled back


importTransactionPropagationContext

public Transaction (src)  importTransactionPropagationContext(java.lang.Object tpc)
Import a transaction propagation context into this TM. The TPC is loosely typed, as we may (at a later time) want to import TPCs that come from other transaction domains without offloading the conversion to the client.

Specified by:
importTransactionPropagationContext in interface TransactionPropagationContextImporter (src)
Parameters:
tpc - The transaction propagation context that we want to import into this TM. Currently this is an instance of LocalId. At some later time this may be an instance of a transaction propagation context from another transaction domain like org.omg.CosTransactions.PropagationContext.
Returns:
A transaction representing this transaction propagation context, or null if this TPC cannot be imported.

getTransactionPropagationContext

public java.lang.Object getTransactionPropagationContext()
Return a TPC for the current transaction.

Specified by:
getTransactionPropagationContext in interface TransactionPropagationContextFactory (src)

getTransactionPropagationContext

public java.lang.Object getTransactionPropagationContext(Transaction (src)  tx)
Return a TPC for the argument transaction.

Specified by:
getTransactionPropagationContext in interface TransactionPropagationContextFactory (src)

registerWork

public void registerWork(Work (src)  work,
                         Xid (src)  xid,
                         long timeout)
                  throws WorkCompletedException (src) 
Description copied from interface: JBossXATerminator (src)
Invoked for transaction inflow of work

Specified by:
registerWork in interface JBossXATerminator (src)
Parameters:
work - the work starting
xid - the xid of the work
timeout - the transaction timeout
Throws:
WorkCompletedException (src) - with error code WorkException.TX_CONCURRENT_WORK_DISALLOWED when work is already present for the xid or whose completion is in progress, only the global part of the xid must be used for this check.

startWork

public void startWork(Work (src)  work,
                      Xid (src)  xid)
               throws WorkCompletedException (src) 
Description copied from interface: JBossXATerminator (src)
Invoked for transaction inflow of work

Specified by:
startWork in interface JBossXATerminator (src)
Parameters:
work - the work starting
xid - the xid of the work
Throws:
WorkCompletedException (src) - with error code WorkException.TX_RECREATE_FAILED if it is unable to recreate the transaction context

endWork

public void endWork(Work (src)  work,
                    Xid (src)  xid)
Description copied from interface: JBossXATerminator (src)
Invoked when transaction inflow work ends

Specified by:
endWork in interface JBossXATerminator (src)
Parameters:
work - the work ending
xid - the xid of the work

cancelWork

public void cancelWork(Work (src)  work,
                       Xid (src)  xid)
Description copied from interface: JBossXATerminator (src)
Invoked when the work fails

Specified by:
cancelWork in interface JBossXATerminator (src)
Parameters:
work - the work ending
xid - the xid of the work

prepare

public int prepare(Xid (src)  xid)
            throws XAException (src) 
Description copied from interface: XATerminator (src)
Prepare the transaction

Specified by:
prepare in interface XATerminator (src)
Parameters:
xid - the xid
Returns:
Either XA_RDONLY or XA_OK
Throws:
XAException (src) - for an error

rollback

public void rollback(Xid (src)  xid)
              throws XAException (src) 
Description copied from interface: XATerminator (src)
Rollback the transaction

Specified by:
rollback in interface XATerminator (src)
Parameters:
xid - the xid
Throws:
XAException (src) - for an error

commit

public void commit(Xid (src)  xid,
                   boolean onePhase)
            throws XAException (src) 
Description copied from interface: XATerminator (src)
Commit the transaction

Specified by:
commit in interface XATerminator (src)
Parameters:
xid - the xid
onePhase - true for one phase commit, false for two phase
Throws:
XAException (src) - for an error

forget

public void forget(Xid (src)  xid)
            throws XAException (src) 
Description copied from interface: XATerminator (src)
Forget the transaction

Specified by:
forget in interface XATerminator (src)
Parameters:
xid - the xid
Throws:
XAException (src) - for an error

recover

public Xid (src) [] recover(int flag)
              throws XAException (src) 
Description copied from interface: XATerminator (src)
Retrieve xids that are recoverable

Specified by:
recover in interface XATerminator (src)
Parameters:
flag - the recovery option
Throws:
XAException (src) - for an error

getValue

public java.lang.Object getValue(TransactionLocal (src)  local,
                                 Transaction (src)  tx)
get the transaction local value. Pull it from the TransactionImpl object

Specified by:
getValue in interface TransactionLocalDelegate (src)

storeValue

public void storeValue(TransactionLocal (src)  local,
                       Transaction (src)  tx,
                       java.lang.Object value)
put the value in the TransactionImpl map

Specified by:
storeValue in interface TransactionLocalDelegate (src)

containsValue

public boolean containsValue(TransactionLocal (src)  local,
                             Transaction (src)  tx)
does TransactionImpl contain object?

Specified by:
containsValue in interface TransactionLocalDelegate (src)