org.objectweb.jonas_tm
Class Current

java.lang.Object
  |
  +--org.objectweb.jonas_tm.Current
All Implemented Interfaces:
javax.naming.Referenceable, org.objectweb.transaction.api.ResourceManagerEventListener, javax.transaction.TransactionManager, javax.transaction.UserTransaction

public class Current
extends java.lang.Object
implements javax.transaction.UserTransaction, javax.transaction.TransactionManager, javax.naming.Referenceable, org.objectweb.transaction.api.ResourceManagerEventListener

Current is the common Implementation for UserTransaction and TransactionManager. UserTransaction is used by clients that want manage transactions themselves. It is referenceable via JNDI TransactionManager is used by a JOnAS Server. This object is unique in a VM, i.e. each JOnAS Server has ONE Current object and each client program should normally issue only ONE lookup on JNDI. Current also implements Referenceable, because of JNDI.

Author:
Philippe Durieux Contributor(s): 01/11/06 Christophe Ney cney@batisseurs.com for Lutris Technologies Added ResourceManagerListener mechanism to remove ThreadData dependency. 01/12/03 Dean Jennings - synchronizedMap for txXids

Constructor Summary
Current()
          Default constructor.
Current(TransactionFactory tmfact, boolean iscorba)
          Constructor for JOnAS Server.
 
Method Summary
 void begin()
          Create a new transaction and associate it with the current thread.
 void commit()
          Complete the transaction associated with the current thread.
 void connectionClosed(org.objectweb.transaction.api.ResourceManagerEvent event)
           
 void connectionErrorOccured(org.objectweb.transaction.api.ResourceManagerEvent event)
           
 void connectionOpened(org.objectweb.transaction.api.ResourceManagerEvent event)
           
 void forgetTx(javax.transaction.xa.Xid xid)
          Forget all about this transaction.
static Current getCurrent()
          Returns the unique instance of the class or null if not initialized in case of plain client.
 int getCurrentNumberOfTx()
          MBean method:
 int getDefaultTimeout()
          Gets the default timeout value
static TransactionFactory getJTM()
          Returns the TMFactory (in JTM)
 TransactionContext getPropagationContext(boolean hold)
          Get the propagation context associated with the current thread or null if the thread is not involved in a transaction.
 javax.naming.Reference getReference()
          Retrieves the Reference of this object.
 int getStatus()
          Obtain the status of the transaction associated with the current thread.
 int getTotalNumberOfBeginTx()
          MBean method:
 int getTotalNumberOfCommitTx()
          MBean method:
 int getTotalNumberOfRollbackTx()
          MBean method:
 int getTotalNumberOfTimeOutExpired()
          management method:
 javax.transaction.Transaction getTransaction()
          Get the transaction object that represents the transaction context of the calling thread.
static javax.transaction.TransactionManager getTransactionManager()
           
 java.lang.Integer[] getTxCounters()
          management method:
 void incrementBeginCounter()
          management method: increment the number of beginned tx
 void incrementCommitCounter()
          management method: increment the number of beginned tx
 void incrementRollbackCounter()
          management method: increment the number of rollbacked tx
 void incrementTimeOutExpCounter()
          management method: increment the number of rollbacked by time out
 void resetAllTxTotalCounters()
          MBean method: reset total number of tx
 void resume(javax.transaction.Transaction tobj)
          Resume the transaction context association of the calling thread with the transaction represented by the supplied Transaction object.
 void rollback()
          Roll back the transaction associated with the current thread.
 void setCorba(boolean iscorba)
          Sets the corba value
 void setDefaultTimeout(int timeout)
          Sets the default timeout value
 void setPropagationContext(TransactionContext pctx, boolean isReply)
          Associate to the current thread a transaction represented by its propagation context.
 void setRollbackOnly()
          Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.
 void setTransactionTimeout(int seconds)
          Modify the value of the timeout value that is associated with the transactions started by the current thread with the begin method.
 javax.transaction.Transaction suspend()
          Suspend the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Current

public Current()
Default constructor. A client does not need the TMFactory.

Current

public Current(TransactionFactory tmfact,
               boolean iscorba)
Constructor for JOnAS Server. The TM factory is passed as argument. Note that the TM factory can be either local or remote.
Method Detail

getTransactionManager

public static javax.transaction.TransactionManager getTransactionManager()

begin

public void begin()
           throws javax.transaction.NotSupportedException,
                  javax.transaction.SystemException
Create a new transaction and associate it with the current thread.
Specified by:
begin in interface javax.transaction.UserTransaction
Throws:
javax.transaction.NotSupportedException - Thrown if the thread is already associated with a transaction. (nested transaction are not supported)
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

commit

public void commit()
            throws javax.transaction.RollbackException,
                   javax.transaction.HeuristicMixedException,
                   javax.transaction.HeuristicRollbackException,
                   java.lang.SecurityException,
                   java.lang.IllegalStateException,
                   javax.transaction.SystemException
Complete the transaction associated with the current thread. When this method completes, the thread becomes associated with no transaction.
Specified by:
commit in interface javax.transaction.UserTransaction
Throws:
javax.transaction.RollbackException - Thrown to indicate that the transaction has been rolled back rather than committed.
javax.transaction.HeuristicMixedException - Thrown to indicate that a heuristic decision was made and that some relevant updates have been committed while others have been rolled back.
javax.transaction.HeuristicRollbackException - Thrown to indicate that a heuristic decision was made and that some relevant updates have been rolled back.
java.lang.SecurityException - Thrown to indicate that the thread is not allowed to commit the transaction.
java.lang.IllegalStateException - Thrown if the current thread is not associated with a transaction.
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

rollback

public void rollback()
              throws java.lang.IllegalStateException,
                     java.lang.SecurityException,
                     javax.transaction.SystemException
Roll back the transaction associated with the current thread. When this method completes, the thread becomes associated with no transaction.
Specified by:
rollback in interface javax.transaction.UserTransaction
Throws:
java.lang.SecurityException - Thrown to indicate that the thread is not allowed to roll back the transaction.
java.lang.IllegalStateException - Thrown if the current thread is not associated with a transaction.
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

setRollbackOnly

public void setRollbackOnly()
                     throws java.lang.IllegalStateException,
                            javax.transaction.SystemException
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.
Specified by:
setRollbackOnly in interface javax.transaction.UserTransaction
Throws:
java.lang.IllegalStateException - Thrown if the current thread is not associated with a transaction.
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

getStatus

public int getStatus()
              throws javax.transaction.SystemException
Obtain the status of the transaction associated with the current thread.
Specified by:
getStatus in interface javax.transaction.UserTransaction
Returns:
The transaction status. If no transaction is associated with the current thread, this method returns the Status.NoTransaction value.
Throws:
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

setTransactionTimeout

public void setTransactionTimeout(int seconds)
                           throws javax.transaction.SystemException
Modify the value of the timeout value that is associated with the transactions started by the current thread with the begin method.

If an application has not called this method, the transaction service uses some default value for the transaction timeout.

Specified by:
setTransactionTimeout in interface javax.transaction.UserTransaction
Parameters:
seconds - The value of the timeout in seconds. If the value is zero, the transaction service restores the default value.
Throws:
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

getTransaction

public javax.transaction.Transaction getTransaction()
                                             throws javax.transaction.SystemException
Get the transaction object that represents the transaction context of the calling thread.
Specified by:
getTransaction in interface javax.transaction.TransactionManager
Returns:
the Transaction object representing the transaction associated with the calling thread. If the calling thread is not associated with a transaction, a null object reference is returned.
Throws:
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

resume

public void resume(javax.transaction.Transaction tobj)
            throws javax.transaction.InvalidTransactionException,
                   java.lang.IllegalStateException,
                   javax.transaction.SystemException
Resume the transaction context association of the calling thread with the transaction represented by the supplied Transaction object. When this method returns, the calling thread is associated with the transaction context specified. Warning: No XA start is done here. We suppose it is already done after a getConnection. The supposed programming model is: getConnection, SQL, close.
Specified by:
resume in interface javax.transaction.TransactionManager
Parameters:
tobj - The Transaction object that represents the transaction to be resumed.
Throws:
javax.transaction.InvalidTransactionException - Thrown if the parameter transaction object contains an invalid transaction
java.lang.IllegalStateException - Thrown if the thread is already associated with another transaction.
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

suspend

public javax.transaction.Transaction suspend()
                                      throws javax.transaction.SystemException
Suspend the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended. If the calling thread is not associated with a transaction, the method returns a null object reference. When this method returns, the calling thread is associated with no transaction. Warning: No XA end is done here. We suppose it is already done after a close. The supposed programming model is: getConnection, SQL, close.
Specified by:
suspend in interface javax.transaction.TransactionManager
Returns:
Transaction object representing the suspended transaction.
Throws:
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition
javax.transaction.SystemException - Thrown if the transaction manager encounters an unexpected error condition

connectionOpened

public void connectionOpened(org.objectweb.transaction.api.ResourceManagerEvent event)
Specified by:
connectionOpened in interface org.objectweb.transaction.api.ResourceManagerEventListener

connectionClosed

public void connectionClosed(org.objectweb.transaction.api.ResourceManagerEvent event)
Specified by:
connectionClosed in interface org.objectweb.transaction.api.ResourceManagerEventListener

connectionErrorOccured

public void connectionErrorOccured(org.objectweb.transaction.api.ResourceManagerEvent event)
Specified by:
connectionErrorOccured in interface org.objectweb.transaction.api.ResourceManagerEventListener

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Retrieves the Reference of this object.
Specified by:
getReference in interface javax.naming.Referenceable
Returns:
The non-null Reference of this object.
Throws:
javax.naming.NamingException - If a naming exception was encountered while retrieving the reference.

getCurrent

public static Current getCurrent()
Returns the unique instance of the class or null if not initialized in case of plain client.
Returns:
The Current object created

getJTM

public static TransactionFactory getJTM()
Returns the TMFactory (in JTM)

setDefaultTimeout

public void setDefaultTimeout(int timeout)
Sets the default timeout value

getDefaultTimeout

public int getDefaultTimeout()
Gets the default timeout value

setCorba

public void setCorba(boolean iscorba)
Sets the corba value

setPropagationContext

public void setPropagationContext(TransactionContext pctx,
                                  boolean isReply)
Associate to the current thread a transaction represented by its propagation context. This is used internally by the implicit propagation of the transactionnal context: - in the skeleton, before calling the request (isReply = false) - in the stub, after receiving the reply (isReply = true)

getPropagationContext

public TransactionContext getPropagationContext(boolean hold)
Get the propagation context associated with the current thread or null if the thread is not involved in a transaction.

forgetTx

public void forgetTx(javax.transaction.xa.Xid xid)
Forget all about this transaction. We must destroy references to TransactionImpl object to allow the garbage collector to free memory allocated to this transaction.

getCurrentNumberOfTx

public int getCurrentNumberOfTx()
MBean method:
Returns:
the current number of transaction

incrementBeginCounter

public void incrementBeginCounter()
management method: increment the number of beginned tx

getTotalNumberOfBeginTx

public int getTotalNumberOfBeginTx()
MBean method:
Returns:
the Total number of transaction

incrementRollbackCounter

public void incrementRollbackCounter()
management method: increment the number of rollbacked tx

getTotalNumberOfRollbackTx

public int getTotalNumberOfRollbackTx()
MBean method:
Returns:
the current number of rollbacked transaction

incrementCommitCounter

public void incrementCommitCounter()
management method: increment the number of beginned tx

getTotalNumberOfCommitTx

public int getTotalNumberOfCommitTx()
MBean method:
Returns:
the current number of commited transaction

resetAllTxTotalCounters

public void resetAllTxTotalCounters()
MBean method: reset total number of tx

incrementTimeOutExpCounter

public void incrementTimeOutExpCounter()
management method: increment the number of rollbacked by time out

getTotalNumberOfTimeOutExpired

public int getTotalNumberOfTimeOutExpired()
management method:
Returns:
the number of rollbacked tx by time out

getTxCounters

public java.lang.Integer[] getTxCounters()
management method:
Returns:
all counter