org.jboss.resource.connectionmanager
Class TxConnectionManager

java.lang.Object
  extended by org.jboss.mx.util.JBossNotificationBroadcasterSupport
      extended by org.jboss.system.ServiceMBeanSupport
          extended by org.jboss.resource.connectionmanager.BaseConnectionManager2
              extended by org.jboss.resource.connectionmanager.TxConnectionManager
All Implemented Interfaces:
javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, BaseConnectionManager2MBean, ConnectionCacheListener, ConnectionListenerFactory, TxConnectionManagerMBean, org.jboss.system.Service, org.jboss.system.ServiceMBean, org.jboss.tm.TransactionTimeoutConfiguration

public class TxConnectionManager
extends BaseConnectionManager2
implements TxConnectionManagerMBean

The TxConnectionManager is a JBoss ConnectionManager implementation for jca adapters implementing LocalTransaction and XAResource support. It implements a ConnectionEventListener that implements XAResource to manage transactions through the Transaction Manager. To assure that all work in a local transaction occurs over the same ManagedConnection, it includes a xid to ManagedConnection map. When a Connection is requested or a transaction started with a connection handle in use, it checks to see if a ManagedConnection already exists enrolled in the global transaction and uses it if found. Otherwise a free ManagedConnection has its LocalTransaction started and is used. From the BaseConnectionManager2, it includes functionality to obtain managed connections from a ManagedConnectionPool mbean, find the Subject from a SubjectSecurityDomain, and interact with the CachedConnectionManager for connections held over transaction and method boundaries. Important mbean references are to a ManagedConnectionPool supplier (typically a JBossManagedConnectionPool), and a RARDeployment representing the ManagedConnectionFactory. This connection manager has to perform the following operations: 1. When an application component requests a new ConnectionHandle, it must find a ManagedConnection, and make sure a ConnectionEventListener is registered. It must inform the CachedConnectionManager that a connection handle has been given out. It needs to count the number of handles for each ManagedConnection. If there is a current transaction, it must enlist the ManagedConnection's LocalTransaction in the transaction using the ConnectionEventListeners XAResource XAResource implementation. Entry point: ConnectionManager.allocateConnection. written. 2. When a ConnectionClosed event is received from the ConnectionEventListener, it must reduce the handle count. If the handle count is zero, the XAResource should be delisted from the Transaction, if any. The CachedConnectionManager must be notified that the connection is closed. Entry point: ConnectionEventListener.ConnectionClosed. written 3. When a transaction begun notification is received from the UserTransaction (via the CachedConnectionManager, all managedConnections associated with the current object must be enlisted in the transaction. Entry point: (from CachedConnectionManager) ConnectionCacheListener.transactionStarted(Transaction, Collection). The collection is of ConnectionRecord objects. written. 5. When an "entering object" notification is received from the CachedConnectionInterceptor, all the connections for the current object must be associated with a ManagedConnection. if there is a Transaction, the XAResource must be enlisted with it. Entry point: ConnectionCacheListener.reconnect(Collection conns) The Collection is of ConnectionRecord objects. written. 6. When a "leaving object" notification is received from the CachedConnectionInterceptor, all the managedConnections for the current object must have their XAResources delisted from the current Transaction, if any, and cleanup called on each ManagedConnection. Entry point: ConnectionCacheListener.disconnect(Collection conns). written.

Version:
$Revision: 57189 $
Author:
David Jencks, Adrian Brock

Nested Class Summary
protected  class TxConnectionManager.TxConnectionEventListener
           
 
Nested classes/interfaces inherited from class org.jboss.resource.connectionmanager.BaseConnectionManager2
BaseConnectionManager2.BaseConnectionEventListener, BaseConnectionManager2.ConnectionManagerProxy
 
Field Summary
 
Fields inherited from class org.jboss.resource.connectionmanager.BaseConnectionManager2
ccm, ccmName, jaasSecurityManagerService, jndiName, managedConnectionPoolName, poolingStrategy, securityDomain, securityDomainJndiName, STOPPING_NOTIFICATION, trace
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport
log, server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.resource.connectionmanager.TxConnectionManagerMBean
OBJECT_NAME
 
Fields inherited from interface org.jboss.system.ServiceMBean
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
TxConnectionManager()
          Default managed TxConnectionManager constructor for mbean instances.
TxConnectionManager(CachedConnectionManager ccm, ManagedConnectionPool poolingStrategy, TransactionManager tm)
          Creates a new TxConnectionManager instance.
 
Method Summary
 ConnectionListener createConnectionListener(javax.resource.spi.ManagedConnection mc, Object context)
          Create a managed connection listener for the managed connection
 ConnectionListener getManagedConnection(Subject subject, javax.resource.spi.ConnectionRequestInfo cri)
          Public for use in testing pooling functionality by itself.
 long getTimeLeftBeforeTransactionTimeout(boolean errorRollback)
           
 String getTransactionManager()
          Deprecated.  
 TransactionManager getTransactionManagerInstance()
          Get the transaction manager
 javax.management.ObjectName getTransactionManagerService()
          mbean get-set pair for field transactionManagerService Get the value of transactionManagerService
 int getXAResourceTransactionTimeout()
           
 boolean isLocalTransactions()
          mbean get-set pair for field localTransactions Get the value of localTransactions
 boolean isTrackConnectionByTx()
          mbean get-set pair for field trackConnectionByTx Get the value of trackConnectionByTx
 boolean isTransactional()
          Determine whether is a transaction
protected  void managedConnectionDisconnected(ConnectionListener cl)
          For polymorphism.
protected  void managedConnectionReconnected(ConnectionListener cl)
          For polymorphism.
protected static void rethrowAsSystemException(String context, Transaction tx, Throwable t)
           
 void setLocalTransactions(boolean localTransactions)
          Set the value of localTransactions
 void setTrackConnectionByTx(boolean trackConnectionByTx)
          Set the value of trackConnectionByTx
 void setTransactionManager(String tmName)
          Deprecated.  
 void setTransactionManagerInstance(TransactionManager tm)
           
 void setTransactionManagerService(javax.management.ObjectName transactionManagerService)
          Set the value of transactionManagerService
 void setXAResourceTransactionTimeout(int timeout)
           
protected  void startService()
           
protected  void stopService()
           
 void transactionStarted(Collection crs)
          Notification of transaction started
 
Methods inherited from class org.jboss.resource.connectionmanager.BaseConnectionManager2
allocateConnection, disconnect, disconnectManagedConnection, getCachedConnectionManager, getCcm, getConnectionCount, getInstance, getJaasSecurityManagerService, getJndiName, getManagedConnection, getManagedConnectionFactory, getManagedConnectionPool, getNotificationInfo, getPoolingStrategy, getSecurityDomainJndiName, getTransactionTimeout, reconnect, reconnectManagedConnection, rethrowAsResourceException, returnManagedConnection, setCachedConnectionManager, setJaasSecurityManagerService, setJndiName, setManagedConnectionPool, setSecurityDomainJndiName, unregisterAssociation
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport
create, createService, destroy, destroyService, getDeploymentInfo, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, postDeregister, postRegister, preDeregister, preRegister, start, stop
 
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport
addNotificationListener, handleNotification, nextNotificationSequenceNumber, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.resource.connectionmanager.BaseConnectionManager2MBean
getCachedConnectionManager, getInstance, getJaasSecurityManagerService, getJndiName, getManagedConnectionFactory, getManagedConnectionPool, getSecurityDomainJndiName, setCachedConnectionManager, setJaasSecurityManagerService, setJndiName, setManagedConnectionPool, setSecurityDomainJndiName
 
Methods inherited from interface org.jboss.system.ServiceMBean
getName, getState, getStateString, jbossInternalLifecycle
 
Methods inherited from interface org.jboss.system.Service
create, destroy, start, stop
 

Constructor Detail

TxConnectionManager

public TxConnectionManager()
Default managed TxConnectionManager constructor for mbean instances.


TxConnectionManager

public TxConnectionManager(CachedConnectionManager ccm,
                           ManagedConnectionPool poolingStrategy,
                           TransactionManager tm)
Creates a new TxConnectionManager instance. for TESTING ONLY!!! not a managed constructor!!

Parameters:
ccm - a CachedConnectionManager value
poolingStrategy - a ManagedConnectionPool value
tm - a TransactionManager value
Method Detail

rethrowAsSystemException

protected static void rethrowAsSystemException(String context,
                                               Transaction tx,
                                               Throwable t)
                                        throws SystemException
Throws:
SystemException

getTransactionManagerService

public javax.management.ObjectName getTransactionManagerService()
Description copied from interface: TxConnectionManagerMBean
mbean get-set pair for field transactionManagerService Get the value of transactionManagerService

Specified by:
getTransactionManagerService in interface TxConnectionManagerMBean
Returns:
value of transactionManagerService

setTransactionManagerService

public void setTransactionManagerService(javax.management.ObjectName transactionManagerService)
Description copied from interface: TxConnectionManagerMBean
Set the value of transactionManagerService

Specified by:
setTransactionManagerService in interface TxConnectionManagerMBean
Parameters:
transactionManagerService - Value to assign to transactionManagerService

setTransactionManager

public void setTransactionManager(String tmName)
Deprecated. 

Description copied from interface: TxConnectionManagerMBean
The TransactionManager attribute contains the jndi name of the TransactionManager. This is normally java:/TransactionManager.

Specified by:
setTransactionManager in interface TxConnectionManagerMBean
Parameters:
tmName - an String value

getTransactionManager

public String getTransactionManager()
Deprecated. 

Description copied from interface: TxConnectionManagerMBean
Describe getTransactionManager method here.

Specified by:
getTransactionManager in interface TxConnectionManagerMBean
Returns:
an String value

getTransactionManagerInstance

public TransactionManager getTransactionManagerInstance()
Description copied from interface: ConnectionListenerFactory
Get the transaction manager

Specified by:
getTransactionManagerInstance in interface ConnectionListenerFactory
Overrides:
getTransactionManagerInstance in class BaseConnectionManager2
Returns:
the transaction manager

setTransactionManagerInstance

public void setTransactionManagerInstance(TransactionManager tm)

isTrackConnectionByTx

public boolean isTrackConnectionByTx()
Description copied from interface: TxConnectionManagerMBean
mbean get-set pair for field trackConnectionByTx Get the value of trackConnectionByTx

Specified by:
isTrackConnectionByTx in interface TxConnectionManagerMBean
Returns:
value of trackConnectionByTx

setTrackConnectionByTx

public void setTrackConnectionByTx(boolean trackConnectionByTx)
Description copied from interface: TxConnectionManagerMBean
Set the value of trackConnectionByTx

Specified by:
setTrackConnectionByTx in interface TxConnectionManagerMBean
Parameters:
trackConnectionByTx - Value to assign to trackConnectionByTx

isLocalTransactions

public boolean isLocalTransactions()
Description copied from interface: TxConnectionManagerMBean
mbean get-set pair for field localTransactions Get the value of localTransactions

Specified by:
isLocalTransactions in interface TxConnectionManagerMBean
Returns:
value of localTransactions

setLocalTransactions

public void setLocalTransactions(boolean localTransactions)
Description copied from interface: TxConnectionManagerMBean
Set the value of localTransactions

Specified by:
setLocalTransactions in interface TxConnectionManagerMBean
Parameters:
localTransactions - Value to assign to localTransactions

getXAResourceTransactionTimeout

public int getXAResourceTransactionTimeout()
Specified by:
getXAResourceTransactionTimeout in interface TxConnectionManagerMBean

setXAResourceTransactionTimeout

public void setXAResourceTransactionTimeout(int timeout)
Specified by:
setXAResourceTransactionTimeout in interface TxConnectionManagerMBean

getTimeLeftBeforeTransactionTimeout

public long getTimeLeftBeforeTransactionTimeout(boolean errorRollback)
                                         throws RollbackException
Specified by:
getTimeLeftBeforeTransactionTimeout in interface org.jboss.tm.TransactionTimeoutConfiguration
Overrides:
getTimeLeftBeforeTransactionTimeout in class BaseConnectionManager2
Throws:
RollbackException

startService

protected void startService()
                     throws Exception
Overrides:
startService in class BaseConnectionManager2
Throws:
Exception

stopService

protected void stopService()
                    throws Exception
Overrides:
stopService in class BaseConnectionManager2
Throws:
Exception

getManagedConnection

public ConnectionListener getManagedConnection(Subject subject,
                                               javax.resource.spi.ConnectionRequestInfo cri)
                                        throws javax.resource.ResourceException
Description copied from class: BaseConnectionManager2
Public for use in testing pooling functionality by itself. called by both allocateConnection and reconnect.

Overrides:
getManagedConnection in class BaseConnectionManager2
Parameters:
subject - a Subject value
cri - a ConnectionRequestInfo value
Returns:
a ManagedConnection value
Throws:
javax.resource.ResourceException - if an error occurs

transactionStarted

public void transactionStarted(Collection crs)
                        throws SystemException
Description copied from interface: ConnectionCacheListener
Notification of transaction started

Specified by:
transactionStarted in interface ConnectionCacheListener
Overrides:
transactionStarted in class BaseConnectionManager2
Parameters:
crs - the connections
Throws:
SystemException - for any error

managedConnectionReconnected

protected void managedConnectionReconnected(ConnectionListener cl)
                                     throws javax.resource.ResourceException
Description copied from class: BaseConnectionManager2
For polymorphism.

Do not invoke directly use reconnectManagedConnection which does the relevent exception handling

Overrides:
managedConnectionReconnected in class BaseConnectionManager2
Throws:
javax.resource.ResourceException

managedConnectionDisconnected

protected void managedConnectionDisconnected(ConnectionListener cl)
                                      throws javax.resource.ResourceException
Description copied from class: BaseConnectionManager2
For polymorphism.

Do not invoke directly use disconnectManagedConnection which does the relevent exception handling

Overrides:
managedConnectionDisconnected in class BaseConnectionManager2
Throws:
javax.resource.ResourceException

createConnectionListener

public ConnectionListener createConnectionListener(javax.resource.spi.ManagedConnection mc,
                                                   Object context)
                                            throws javax.resource.ResourceException
Description copied from interface: ConnectionListenerFactory
Create a managed connection listener for the managed connection

Specified by:
createConnectionListener in interface ConnectionListenerFactory
Parameters:
mc - the managed connection
context - a context object used by the pool
Returns:
a new connection event listener
Throws:
javax.resource.ResourceException - for any error

isTransactional

public boolean isTransactional()
Description copied from interface: ConnectionListenerFactory
Determine whether is a transaction

Specified by:
isTransactional in interface ConnectionListenerFactory
Overrides:
isTransactional in class BaseConnectionManager2
Returns:
whether there is a transaction


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.