tyrex.tm.impl
Class TransactionDomainImpl

java.lang.Object
  extended bytyrex.tm.TransactionDomain
      extended bytyrex.tm.impl.TransactionDomainImpl
All Implemented Interfaces:
DomainMetrics, java.lang.Runnable

public class TransactionDomainImpl
extends TransactionDomain
implements java.lang.Runnable, DomainMetrics

Implementation of a transaction domain.

Version:
$Revision: 1.34 $ $Date: 2005/11/30 13:21:03 $
Author:
Assaf Arkin

Field Summary
protected  Category _category
          The log4J category for this transaction domain.
protected  Journal _journal
          The transaction journal used by this domain.
protected  org.omg.CORBA.ORB _orb
          The CORBA ORB used by this transaction domain, or null if no CORBA ORB is used.
protected  TransactionManagerImpl _txManager
          A singleton transaction manager implementation.
static int TABLE_SIZE
          The size of the hash table.
 
Fields inherited from class tyrex.tm.TransactionDomain
ACTIVE, READY, RECOVERING, TERMINATED
 
Constructor Summary
TransactionDomainImpl(DomainConfig config)
          Constructs a new transaction domain.
 
Method Summary
 void addInterceptor(TransactionInterceptor interceptor)
          Adds a transaction interceptor to this transaction domain.
protected  TransactionImpl createTransaction(TransactionImpl parent, long timeout)
          Creates a new transaction.
protected  void delistThread(ThreadContext context, java.lang.Thread thread)
          Called to dissociatethe transaction from the thread.
protected  void dumpTransactionList(java.io.PrintWriter writer)
           
protected  boolean enlistThread(TransactionImpl tx, ThreadContext context, java.lang.Thread thread)
          Called to associate the transaction with the thread.
 TransactionImpl findTransaction(java.lang.String xid)
           
 TransactionImpl findTransaction(javax.transaction.xa.Xid xid)
           
protected  void forgetTransaction(TransactionImpl tx)
          Called by forget to forget about the transaction once it has been commited/rolledback.
 int getActive()
          Returns the current number of active transactions.
 float getAvgDuration()
          Returns the average duration for active transactions.
 DomainMetrics getDomainMetrics()
          Returns the transaction domain metrics.
 java.lang.String getDomainName()
          Returns the transaction domain name.
 boolean getNestedTransactions()
           
 TransactionDomainImpl getNextDomain()
           
 Resources getResources()
          Returns resources installed for this transaction domain.
 int getState()
          Returns the transaction domain state.
 int getTotalCommitted()
          Returns the total number of committed transactions.
 int getTotalRolledback()
          Returns the total number of rolled back transactions.
 org.omg.CosTransactions.TransactionFactory getTransactionFactory()
          Returns an OTS transaction factory for this transaction domain.
 javax.transaction.TransactionManager getTransactionManager()
          Returns a transaction manager for this transaction domain.
 int getTransactionTimeout()
           
protected  int getTransactionTimeout(TransactionImpl tx)
          Called by ControlImpl to obtain the timeout on a transaction for the purpose of the propagation context.
 javax.transaction.UserTransaction getUserTransaction()
          Returns a user transaction for this transaction domain.
 void identifyORB(org.omg.CORBA.ORB orb, org.omg.CORBA.TSIdentification tsi, java.util.Properties prop)
           
protected  javax.transaction.Transaction[] listTransactions()
           
protected  void notifyCommit(TransactionImpl tx)
           
protected  void notifyCompletion(TransactionImpl tx, int heuristic)
           
protected  void notifyRollback(TransactionImpl tx)
           
 void recover()
          Called to initiate recovery.
protected  TransactionImpl recreateTransaction(org.omg.CosTransactions.PropagationContext pgContext)
          Creates a new transaction to represent a remote OTS transaction, but does not activate it yet.
 void removeInterceptor(TransactionInterceptor interceptor)
          Removes a transaction interceptor to this transaction domain.
 void reset()
          Called to reset this metrics object.
 void run()
          Background thread that looks for transactions that have timed out and terminates them.
 void setNextDomain(TransactionDomainImpl nextDomain)
           
protected  void setTransactionTimeout(int timeout)
          Called to set the timeout of all transactions created from this domain.
protected  void setTransactionTimeout(TransactionImpl tx, int timeout)
          Called to change the timeout of the transaction and all the resources enlisted with that transaction.
 void terminate()
          Terminates the transaction domain.
 java.lang.String toString()
           
 
Methods inherited from class tyrex.tm.TransactionDomain
createDomain, createDomain, createDomain, getDomain, getTransaction, getTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TABLE_SIZE

public static final int TABLE_SIZE
The size of the hash table. This must be a prime value.

See Also:
Constant Field Values

_txManager

protected final TransactionManagerImpl _txManager
A singleton transaction manager implementation.


_orb

protected org.omg.CORBA.ORB _orb
The CORBA ORB used by this transaction domain, or null if no CORBA ORB is used.


_category

protected final Category _category
The log4J category for this transaction domain.


_journal

protected final Journal _journal
The transaction journal used by this domain.

Constructor Detail

TransactionDomainImpl

public TransactionDomainImpl(DomainConfig config)
                      throws DomainConfigurationException
Constructs a new transaction domain.

Parameters:
config - The domain configuration object
Throws:
DomainConfigurationException - Failed to create the transaction domain
Method Detail

toString

public java.lang.String toString()

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
Description copied from class: TransactionDomain
Returns a transaction manager for this transaction domain.

The transaction managed can be used to begin, commit and rollback transactions in this domain only.

Calling this method multiple times will return the same instance of the transaction manager.

Specified by:
getTransactionManager in class TransactionDomain
Returns:
The transaction manager for this domain

getUserTransaction

public javax.transaction.UserTransaction getUserTransaction()
Description copied from class: TransactionDomain
Returns a user transaction for this transaction domain.

The user transaction can be used to begin, commit and rollback transactions in this domain only.

Calling this method multiple times will return the same instance of the user transaction.

Specified by:
getUserTransaction in class TransactionDomain
Returns:
The user transaction for this domain

getTransactionFactory

public org.omg.CosTransactions.TransactionFactory getTransactionFactory()
Description copied from class: TransactionDomain
Returns an OTS transaction factory for this transaction domain.

The transaction factory can be used to create and re-create OTS transactions in this domain only. It is also used to identify the ORB by implementing TransactionService.

Calling this method multiple times will return the same instance of the transaction factory.

Specified by:
getTransactionFactory in class TransactionDomain
Returns:
The transaction factory for this domain

getTransactionTimeout

public int getTransactionTimeout()

getNestedTransactions

public boolean getNestedTransactions()

addInterceptor

public void addInterceptor(TransactionInterceptor interceptor)
Description copied from class: TransactionDomain
Adds a transaction interceptor to this transaction domain. The interceptor will be notified of all transactional activities within this domain.

Specified by:
addInterceptor in class TransactionDomain
Parameters:
interceptor - The transaction interceptor

removeInterceptor

public void removeInterceptor(TransactionInterceptor interceptor)
Description copied from class: TransactionDomain
Removes a transaction interceptor to this transaction domain.

Specified by:
removeInterceptor in class TransactionDomain
Parameters:
interceptor - The transaction interceptor

terminate

public void terminate()
Description copied from class: TransactionDomain
Terminates the transaction domain. After this method returns, the transaction manager is no longer able to begin new transactions in this domain.

Specified by:
terminate in class TransactionDomain

getDomainMetrics

public DomainMetrics getDomainMetrics()
Description copied from class: TransactionDomain
Returns the transaction domain metrics.

Specified by:
getDomainMetrics in class TransactionDomain
Returns:
The transaction domain metrics

getDomainName

public java.lang.String getDomainName()
Description copied from class: TransactionDomain
Returns the transaction domain name.

Specified by:
getDomainName in class TransactionDomain
Returns:
The transaction domain name

getResources

public Resources getResources()
Description copied from class: TransactionDomain
Returns resources installed for this transaction domain.

Initially the resource list is based on resources defined in the domain configuration file. This method can be used to add new resources or disable existing resources.

Specified by:
getResources in class TransactionDomain
Returns:
Resources installed for this transaction domain

getState

public int getState()
Description copied from class: TransactionDomain
Returns the transaction domain state.

The initial state for a transaction domain is TransactionDomain.READY. The domain transitions to TransactionDomain.ACTIVE after recovery has completed by calling recover.

The domain transitions to TransactionDomain.TERMINATED after it has been terminated by calling terminate.

Specified by:
getState in class TransactionDomain
Returns:
The transaction domain state

recover

public void recover()
             throws RecoveryException
Description copied from class: TransactionDomain
Called to initiate recovery. This method must be called before the transaction domain is active and can be used to create new transactions. This method may be called multiple times, but will initiate recovery only the first time.

Specified by:
recover in class TransactionDomain
Throws:
RecoveryException - A chain of errors reported during recovery

getTotalCommitted

public int getTotalCommitted()
Description copied from interface: DomainMetrics
Returns the total number of committed transactions.

Specified by:
getTotalCommitted in interface DomainMetrics
Returns:
The total number of committed transactions

getTotalRolledback

public int getTotalRolledback()
Description copied from interface: DomainMetrics
Returns the total number of rolled back transactions.

Specified by:
getTotalRolledback in interface DomainMetrics
Returns:
The total number of rolled back transactions

getAvgDuration

public float getAvgDuration()
Description copied from interface: DomainMetrics
Returns the average duration for active transactions. Returns the average number of seconds transactions have been active, whether eventually committed or rolledback. Ignores any transactions that are currently in progress.

Specified by:
getAvgDuration in interface DomainMetrics
Returns:
The average duration for active transactions

getActive

public int getActive()
Description copied from interface: DomainMetrics
Returns the current number of active transactions.

Specified by:
getActive in interface DomainMetrics
Returns:
The current number of active transactions

reset

public void reset()
Description copied from interface: DomainMetrics
Called to reset this metrics object.

Specified by:
reset in interface DomainMetrics

findTransaction

public TransactionImpl findTransaction(javax.transaction.xa.Xid xid)

findTransaction

public TransactionImpl findTransaction(java.lang.String xid)

getNextDomain

public TransactionDomainImpl getNextDomain()

setNextDomain

public void setNextDomain(TransactionDomainImpl nextDomain)

createTransaction

protected TransactionImpl createTransaction(TransactionImpl parent,
                                            long timeout)
                                     throws javax.transaction.SystemException
Creates a new transaction. If parent is not null, the transaction is nested within its parent. The transaction timeout is specified in seconds, or zero to use the default transaction timeout. Throws a SystemException if we have reached the quota for new transactions or active transactions, or the server has not been started.

Parameters:
parent - The parent transaction
timeout - The default timeout for the new transaction, specified in seconds
Returns:
The newly created transaction
Throws:
javax.transaction.SystemException - Reached the quota for new transactions

recreateTransaction

protected TransactionImpl recreateTransaction(org.omg.CosTransactions.PropagationContext pgContext)
                                       throws javax.transaction.SystemException
Creates a new transaction to represent a remote OTS transaction, but does not activate it yet. Throws a SystemException if we have reached the quota for new transactions or the server has not been started.

The newly created transaction will have a non-native Xid, therefore it cannot be distributed across two machines using the RMI interface but only through OTS propagation context.

Parameters:
pgContext - The OTS propagation context
Returns:
The newly created transaction
Throws:
javax.transaction.SystemException - Reached the quota for new transactions, or a transaction with the same identifier already exists
See Also:
TransactionFactoryImpl, PropagationContext

forgetTransaction

protected void forgetTransaction(TransactionImpl tx)
Called by forget to forget about the transaction once it has been commited/rolledback.

The transaction will no longer be available to findTransaction. The transaction's association and global identifier are forgotten as well as all thread associated with it. Subsequent calls to findTransaction and getControl will not be able to locate the transaction.

If this is the last transaction in a terminating domain, the domain will close some of its resources (e.g. journal) after this method returns.

Parameters:
tx - The transaction to forget about

setTransactionTimeout

protected void setTransactionTimeout(int timeout)
Called to set the timeout of all transactions created from this domain.

Parameters:
timeout - The new timeout in seconds, zero to restore the default timeout

setTransactionTimeout

protected void setTransactionTimeout(TransactionImpl tx,
                                     int timeout)
Called to change the timeout of the transaction and all the resources enlisted with that transaction.

Parameters:
tx - The transaction
timeout - The new timeout in seconds, zero to use the default timeout for all new transactions.
See Also:
setTransactionTimeout

getTransactionTimeout

protected int getTransactionTimeout(TransactionImpl tx)
Called by ControlImpl to obtain the timeout on a transaction for the purpose of the propagation context.

Parameters:
tx - The transaction
Returns:
The transaction's timeout in seconds

notifyCompletion

protected void notifyCompletion(TransactionImpl tx,
                                int heuristic)

notifyCommit

protected void notifyCommit(TransactionImpl tx)
                     throws javax.transaction.RollbackException
Throws:
javax.transaction.RollbackException

notifyRollback

protected void notifyRollback(TransactionImpl tx)

listTransactions

protected javax.transaction.Transaction[] listTransactions()

dumpTransactionList

protected void dumpTransactionList(java.io.PrintWriter writer)

enlistThread

protected boolean enlistThread(TransactionImpl tx,
                               ThreadContext context,
                               java.lang.Thread thread)
Called to associate the transaction with the thread.

Parameters:
tx - The transaction
context - The thread context
thread - The thread
Returns:
True if transaction enlisted in thread, false if failed

delistThread

protected void delistThread(ThreadContext context,
                            java.lang.Thread thread)
Called to dissociatethe transaction from the thread.

Parameters:
context - The thread context
thread - The thread
See Also:
enlistThread

run

public void run()
Background thread that looks for transactions that have timed out and terminates them. Will be running in a low priority for as long as the server is active, monitoring the transaction table and terminating threads in progress.

This thread is terminated by interrupting it. This thread synchronizes on itself (thread instance) to be notified of a changed in the next timeout.

Specified by:
run in interface java.lang.Runnable

identifyORB

public void identifyORB(org.omg.CORBA.ORB orb,
                        org.omg.CORBA.TSIdentification tsi,
                        java.util.Properties prop)


Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.