org.objectweb.jotm
Class Current

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

public class Current
extends Object
implements UserTransaction, TransactionManager, Referenceable, Serializable

Current is the common implementation for both UserTransaction and TransactionManager.

This object is unique in a VM, i. e. each application server has ONE Current object and each client program should normally issue only ONE lookup on JNDI.

Current also implements Referenceable and Serializable because of JNDI.

See Also:
Serialized Form

Constructor Summary
Current()
          Default constructor.
Current(TransactionFactory tmfact)
          Constructor for an application server.
 
Method Summary
 void associateThreadTx(Xid xid)
          Associate Thread to this transaction.
 void begin()
          Creates a new transaction and associate it with the current thread.
 void commit()
          Commits the transaction associated with the current thread.
 void connectionClosed(ResourceManagerEvent event)
          This method is called by the resource manager when a logical connection that was opened without transaction context is closed.
 void connectionErrorOccured(ResourceManagerEvent event)
          This method is called by the resource manager when a logical connection that was opened without transaction context is about to throw an exception.
 void connectionOpened(ResourceManagerEvent event)
          This method is called by the resource manager when a getConnection call is made without a transaction context.
 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 getDefaultTimeout()
          Gets the default timeout value
static TransactionFactory getJTM()
          Returns the TMFactory (in JTM)
 TransactionContext getPropagationContext(boolean hold)
          Get the transaction 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()
          Returns the status of the transaction associated with the current thread.
 int getTotalBegunTransactions()
          Returns the total number of begun transactions.
 int getTotalCommittedTransactions()
          Returns the total number of committed transactions.
 int getTotalCurrentTransactions()
          Returns the current number of transactions.
 int getTotalExpiredTransactions()
          Returns the total number of rolled back transactions due to timeout.
 int getTotalRolledbackTransactions()
          Returns the total number of rolled back transactions.
 Transaction getTransaction()
          Gets the transaction object that represents the transaction context of the calling thread.
 Integer[] getTransactionCounters()
          Returns all counters.
static TransactionManager getTransactionManager()
          Gets the TransactionManager instance.
 void incrementBeginCounter()
          Increments number of begun transactions by one.
 List popThreadLocalRMEventList()
          Pop the current set from the stack of thread local resource event sets The list contains ResourceManagerEvent objects.
 void pushThreadLocalRMEventList(List eventList)
          Push a new event list on the stack of thread local resource event sets.
 void resume(Transaction tobj)
          Resumes the transaction context association of the calling thread with the transaction represented by the supplied Transaction object.
 void rollback()
          Rolls 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 transaction 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 timeout)
          Modifies the value of the timeout value that is associated with the transactions started by the current thread with the begin method.
 Transaction suspend()
          Suspends 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 an application server. The TM factory is passed as an argument. Note that the TM factory can be either local or remote.

Parameters:
tmfact - TM Factory to use
Method Detail

getTransactionManager

public static TransactionManager getTransactionManager()
Gets the TransactionManager instance.

Returns:
TransactionManager

begin

public void begin()
           throws NotSupportedException,
                  SystemException
Creates 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
Commits 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
Rolls 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
Returns the status of the transaction associated with the current thread.

Specified by:
getStatus in interface UserTransaction
Returns:
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 timeout)
                           throws SystemException
Modifies 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:
timeout - 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
Gets 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
Resumes 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:
  1. getConnection()
  2. SQL code
  3. connection.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
Suspends 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 null. When this method returns, the calling thread is associated with no transaction.

Warning: No XA start is done here. We suppose it is already done after a getConnection().

The supposed programming model is:
  1. getConnection()
  2. SQL code
  3. connection.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)
Description copied from interface: ResourceManagerEventListener
This method is called by the resource manager when a getConnection call is made without a transaction context. The ResourceManagerEvent is to be used by the listener to keep track of those events and perform a late enrolment of those logical connection when the transaction begins.

Specified by:
connectionOpened in interface ResourceManagerEventListener
Parameters:
event - event sent to the listener
See Also:
ResourceManagerEventListener.connectionOpened(org.objectweb.transaction.jta.ResourceManagerEvent)

connectionClosed

public void connectionClosed(ResourceManagerEvent event)
Description copied from interface: ResourceManagerEventListener
This method is called by the resource manager when a logical connection that was opened without transaction context is closed. It is to be used by the listener to keep track of those events and perform clean-up.

Specified by:
connectionClosed in interface ResourceManagerEventListener
Parameters:
event - event sent to the listener
See Also:
ResourceManagerEventListener.connectionClosed(org.objectweb.transaction.jta.ResourceManagerEvent)

connectionErrorOccured

public void connectionErrorOccured(ResourceManagerEvent event)
Description copied from interface: ResourceManagerEventListener
This method is called by the resource manager when a logical connection that was opened without transaction context is about to throw an exception. It is to be used by the listener to keep track of those events and perform clean-up.

Specified by:
connectionErrorOccured in interface ResourceManagerEventListener
Parameters:
event - event sent to the listener
See Also:
ResourceManagerEventListener.connectionErrorOccured(org.objectweb.transaction.jta.ResourceManagerEvent)

pushThreadLocalRMEventList

public void pushThreadLocalRMEventList(List eventList)
Description copied from interface: TransactionManager
Push a new event list on the stack of thread local resource event sets. The list must contain only ResourceManagerEvent objects.

Specified by:
pushThreadLocalRMEventList in interface TransactionManager
Parameters:
eventList - the possibly null list of events to store forecoming ResourceManagerEvent events occuring in the current thread.
See Also:
TransactionManager.pushThreadLocalRMEventList(java.util.List)

popThreadLocalRMEventList

public List popThreadLocalRMEventList()
Description copied from interface: TransactionManager
Pop the current set from the stack of thread local resource event sets The list contains ResourceManagerEvent objects.

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.
See Also:
TransactionManager.popThreadLocalRMEventList()

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)

Returns:
The TransactionFactory

setDefaultTimeout

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

Parameters:
timeout - timeout value (in seconds)

getDefaultTimeout

public int getDefaultTimeout()
Gets the default timeout value

Returns:
default timeout value (in seconds)

setPropagationContext

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

Parameters:
pctx - TransactionContext
isReply - true before calling a request, false after receiving a reply

getPropagationContext

public TransactionContext getPropagationContext(boolean hold)
Get the transaction 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. References to TransactionImpl must be destroyed to allow the garbage collector to free memory allocated to this transaction.

Parameters:
xid - Xid of the transaction

associateThreadTx

public void associateThreadTx(Xid xid)
Associate Thread to this transaction. (used by iiop interceptor)


getTotalCurrentTransactions

public int getTotalCurrentTransactions()
Returns the current number of transactions.

Returns:
current number of transaction

incrementBeginCounter

public void incrementBeginCounter()
Increments number of begun transactions by one.


getTotalBegunTransactions

public int getTotalBegunTransactions()
Returns the total number of begun transactions.

Returns:
total number of begun transactions

getTotalRolledbackTransactions

public int getTotalRolledbackTransactions()
Returns the total number of rolled back transactions.

Returns:
total number of rolled back transactions

getTotalCommittedTransactions

public int getTotalCommittedTransactions()
Returns the total number of committed transactions.

Returns:
total number of commited transactions

getTotalExpiredTransactions

public int getTotalExpiredTransactions()
Returns the total number of rolled back transactions due to timeout.

Returns:
number of rolled back transactions due to timeout

getTransactionCounters

public Integer[] getTransactionCounters()
Returns all counters.

Returns:
an array of all counters (current tx, begun tx, committed tx, rolled back tx, timeouted tx)