org.objectweb.jonas_tm
Class Current

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

public class Current
extends Object
implements UserTransaction, TransactionManager, Referenceable

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 an EJBServer. This object is unique in a VM, i.e. each EJBServer has ONE Current object and each client program should normally issue only ONE lookup on JNDI. Current also implements Referenceable, because of JNDI.


Constructor Summary
Current()
          Default constructor.
Current(TransactionFactory tmfact)
          Constructor for EJBServer.
 
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(ResourceManagerEvent event)
          Call back from a resource manager indicating that a close has been called on a connection that had been opened before a transaction had begun
 void connectionErrorOccured(ResourceManagerEvent event)
          Call back from a resource manager indicating that an error has occured on a connection that had been opened before a transaction had begun
 void connectionOpened(ResourceManagerEvent event)
          Call back from a resource manager indicating that a connection has been opened before a transaction had begun
 void forgetTx(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.
 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:
 Transaction getTransaction()
          Get the transaction object that represents the transaction context of the calling thread.
static TransactionManager getTransactionManager()
           
 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
 List popThreadLocalRMEventList()
          Pop the current list from the stack of thread local resource event lists
 void pushThreadLocalRMEventList(List eventList)
          Push a new empty list on the stack of thread local resource event lists
 void resetAllTxTotalCounters()
          MBean method: reset total number of tx
 void resume(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 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.
 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)
Constructor for EJBServer. The TM factory is passed as argument. Note that the TM factory can be either local or remote.

Method Detail

getTransactionManager

public static TransactionManager getTransactionManager()

begin

public void begin()
           throws NotSupportedException,
                  SystemException
Create a new transaction and associate it with the current thread.

Specified by:
begin in interface UserTransaction
Throws:
NotSupportedException - Thrown if the thread is already associated with a transaction. (nested transaction are not supported)
SystemException - Thrown if the transaction manager encounters an unexpected error condition

commit

public void commit()
            throws RollbackException,
                   HeuristicMixedException,
                   HeuristicRollbackException,
                   SecurityException,
                   IllegalStateException,
                   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 UserTransaction
Throws:
RollbackException - Thrown to indicate that the transaction has been rolled back rather than committed.
HeuristicMixedException - Thrown to indicate that a heuristic decision was made and that some relevant updates have been committed while others have been rolled back.
HeuristicRollbackException - Thrown to indicate that a heuristic decision was made and that some relevant updates have been rolled back.
SecurityException - Thrown to indicate that the thread is not allowed to commit the transaction.
IllegalStateException - Thrown if the current thread is not associated with a transaction.
SystemException - Thrown if the transaction manager encounters an unexpected error condition

rollback

public void rollback()
              throws IllegalStateException,
                     SecurityException,
                     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 UserTransaction
Throws:
SecurityException - Thrown to indicate that the thread is not allowed to roll back the transaction.
IllegalStateException - Thrown if the current thread is not associated with a transaction.
SystemException - Thrown if the transaction manager encounters an unexpected error condition

setRollbackOnly

public void setRollbackOnly()
                     throws IllegalStateException,
                            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 UserTransaction
Throws:
IllegalStateException - Thrown if the current thread is not associated with a transaction.
SystemException - Thrown if the transaction manager encounters an unexpected error condition

getStatus

public int getStatus()
              throws SystemException
Obtain the status of the transaction associated with the current thread.

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

setTransactionTimeout

public void setTransactionTimeout(int seconds)
                           throws 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 UserTransaction
Parameters:
seconds - The value of the timeout in seconds. If the value is zero, the transaction service restores the default value.
Throws:
SystemException - Thrown if the transaction manager encounters an unexpected error condition

getTransaction

public Transaction getTransaction()
                           throws SystemException
Get the transaction object that represents the transaction context of the calling thread.

Specified by:
getTransaction in interface 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:
SystemException - Thrown if the transaction manager encounters an unexpected error condition

resume

public void resume(Transaction tobj)
            throws InvalidTransactionException,
                   IllegalStateException,
                   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 TransactionManager
Parameters:
tobj - The Transaction object that represents the transaction to be resumed.
Throws:
InvalidTransactionException - Thrown if the parameter transaction object contains an invalid transaction
IllegalStateException - Thrown if the thread is already associated with another transaction.
SystemException - Thrown if the transaction manager encounters an unexpected error condition

suspend

public Transaction suspend()
                    throws 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 TransactionManager
Returns:
Transaction object representing the suspended transaction.
Throws:
SystemException - Thrown if the transaction manager encounters an unexpected error condition
SystemException - Thrown if the transaction manager encounters an unexpected error condition

connectionOpened

public void connectionOpened(ResourceManagerEvent event)
Call back from a resource manager indicating that a connection has been opened before a transaction had begun

Specified by:
connectionOpened in interface ResourceManagerEventListener
Parameters:
event - event sent to the listener

connectionClosed

public void connectionClosed(ResourceManagerEvent event)
Call back from a resource manager indicating that a close has been called on a connection that had been opened before a transaction had begun

Specified by:
connectionClosed in interface ResourceManagerEventListener

connectionErrorOccured

public void connectionErrorOccured(ResourceManagerEvent event)
Call back from a resource manager indicating that an error has occured on a connection that had been opened before a transaction had begun

Specified by:
connectionErrorOccured in interface ResourceManagerEventListener
Parameters:
event - event sent to the listener

pushThreadLocalRMEventList

public void pushThreadLocalRMEventList(List eventList)
Push a new empty list on the stack of thread local resource event lists

Specified by:
pushThreadLocalRMEventList in interface TransactionManager
Parameters:
eventList - the possibly null list of events to store forecoming ResourceManagerEvent events occuring in the current thread.

popThreadLocalRMEventList

public List popThreadLocalRMEventList()
Pop the current list from the stack of thread local resource event lists

Specified by:
popThreadLocalRMEventList in interface TransactionManager
Returns:
The possibly null ResourceManagerEvent list of events that have occured in the current thread since the last call of pushThreadLocalRMEventList or since the thread started.

getReference

public Reference getReference()
                       throws NamingException
Retrieves the Reference of this object.

Specified by:
getReference in interface Referenceable
Returns:
The non-null Reference of this object.
Throws:
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


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(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 Integer[] getTxCounters()
management method:

Returns:
all counter