org.jboss.jca.core.connectionmanager.tx
Class TxConnectionManagerImpl

java.lang.Object
  extended by org.jboss.jca.core.connectionmanager.AbstractConnectionManager
      extended by org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl
All Implemented Interfaces:
Serializable, javax.resource.spi.ConnectionManager, org.jboss.jca.core.api.connectionmanager.listener.ConnectionCacheListener, ConnectionListenerFactory, TxConnectionManager, org.jboss.jca.core.spi.transaction.TransactionTimeoutConfiguration

public class TxConnectionManagerImpl
extends AbstractConnectionManager
implements TxConnectionManager

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.

Author:
David Jencks, Adrian Brock, Weston Price, Jesper Pedersen
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jboss.jca.core.connectionmanager.AbstractConnectionManager
trace
 
Constructor Summary
TxConnectionManagerImpl(org.jboss.jca.core.spi.transaction.TransactionIntegration txIntegration, boolean localTransactions)
          Constructor
 
Method Summary
 ConnectionListener createConnectionListener(javax.resource.spi.ManagedConnection mc, Object context)
          Create a managed connection listener for the managed connection.
 boolean getIsSameRMOverride()
          Get the IsSameRMOverride value
protected  CoreLogger getLogger()
          Get the logger.
 ConnectionListener getManagedConnection(Subject subject, javax.resource.spi.ConnectionRequestInfo cri)
          Public for use in testing pooling functionality by itself.
 boolean getPadXid()
          Get PadXis status
 long getTimeLeftBeforeTransactionTimeout(boolean errorRollback)
          Gets time left.
 org.jboss.jca.core.spi.transaction.TransactionIntegration getTransactionIntegration()
          Get the transaction integration instance
 int getTransactionTimeout()
          
 boolean getWrapXAResource()
          Returns true if wrap xa resource.
 int getXAResourceTimeout()
          Gets XA resource transaction time out.
 boolean isInterleaving()
          Gets interleaving flag.
 boolean isLocalTransactions()
          Returns local tx or not.
 boolean isTransactional()
          Determine whether there connection is a transactional.
protected  void managedConnectionDisconnected(ConnectionListener cl)
          For polymorphism.
protected  void managedConnectionReconnected(ConnectionListener cl)
          For polymorphism.
static void rethrowAsSystemException(String context, Transaction tx, Throwable t)
          RethrowAsSystemException.
 void setInterleaving(boolean value)
          Sets interleaving flag.
 void setIsSameRMOverride(boolean v)
          Set the IsSameRMOverride value.
 void setPadXid(boolean v)
          Set if the Xid should be padded
 void setWrapXAResource(boolean v)
          Set if the XAResource should be wrapped
 void setXAResourceTimeout(int timeout)
          Sets XA resource transaction timeout.
 void transactionStarted(Collection<ConnectionRecord> crs)
          Notification of transaction started
 
Methods inherited from class org.jboss.jca.core.connectionmanager.AbstractConnectionManager
allocateConnection, disconnect, disconnectManagedConnection, getAllocationRetry, getAllocationRetryWaitMillis, getCachedConnectionManager, getFlushStrategy, getJndiName, getManagedConnection, getManagedConnectionFactory, getPool, getSecurityDomain, getSubjectFactory, reconnect, reconnectManagedConnection, returnManagedConnection, setAllocationRetry, setAllocationRetryWaitMillis, setCachedConnectionManager, setFlushStrategy, setJndiName, setPool, setSecurityDomain, setShutDown, setSubjectFactory, setUserTransactionRegistry, unregisterAssociation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.jca.core.connectionmanager.ConnectionManager
getAllocationRetry, getAllocationRetryWaitMillis, getCachedConnectionManager, getJndiName, getPool, getSecurityDomain, getSubjectFactory, setJndiName, unregisterAssociation
 
Methods inherited from interface org.jboss.jca.core.api.connectionmanager.ConnectionManager
returnManagedConnection
 
Methods inherited from interface javax.resource.spi.ConnectionManager
allocateConnection
 
Methods inherited from interface org.jboss.jca.core.connectionmanager.listener.ConnectionCacheListener
disconnect, reconnect
 

Constructor Detail

TxConnectionManagerImpl

public TxConnectionManagerImpl(org.jboss.jca.core.spi.transaction.TransactionIntegration txIntegration,
                               boolean localTransactions)
Constructor

Parameters:
txIntegration - The transaction integration layer
localTransactions - Is local transactions enabled
Method Detail

getLogger

protected CoreLogger getLogger()
Get the logger.

Specified by:
getLogger in class AbstractConnectionManager
Returns:
The value

getTransactionIntegration

public org.jboss.jca.core.spi.transaction.TransactionIntegration getTransactionIntegration()
Get the transaction integration instance

Specified by:
getTransactionIntegration in interface ConnectionListenerFactory
Specified by:
getTransactionIntegration in class AbstractConnectionManager
Returns:
The transaction integration

isInterleaving

public boolean isInterleaving()
Gets interleaving flag.

Specified by:
isInterleaving in interface TxConnectionManager
Returns:
interleaving flag

setInterleaving

public void setInterleaving(boolean value)
Sets interleaving flag.

Parameters:
value - interleaving

isLocalTransactions

public boolean isLocalTransactions()
Returns local tx or not.

Specified by:
isLocalTransactions in interface TxConnectionManager
Returns:
local tx or not

getXAResourceTimeout

public int getXAResourceTimeout()
Gets XA resource transaction time out.

Specified by:
getXAResourceTimeout in interface TxConnectionManager
Returns:
xa resource transaction timeout

setXAResourceTimeout

public void setXAResourceTimeout(int timeout)
Sets XA resource transaction timeout.

Parameters:
timeout - xa resource transaction timeout

getIsSameRMOverride

public boolean getIsSameRMOverride()
Get the IsSameRMOverride value

Specified by:
getIsSameRMOverride in interface TxConnectionManager
Returns:
The value

setIsSameRMOverride

public void setIsSameRMOverride(boolean v)
Set the IsSameRMOverride value.

Parameters:
v - The value

getWrapXAResource

public boolean getWrapXAResource()
Returns true if wrap xa resource.

Specified by:
getWrapXAResource in interface TxConnectionManager
Returns:
true if wrap xa resource

setWrapXAResource

public void setWrapXAResource(boolean v)
Set if the XAResource should be wrapped

Parameters:
v - The value

getPadXid

public boolean getPadXid()
Get PadXis status

Specified by:
getPadXid in interface TxConnectionManager
Returns:
The value

setPadXid

public void setPadXid(boolean v)
Set if the Xid should be padded

Parameters:
v - The value

getTimeLeftBeforeTransactionTimeout

public long getTimeLeftBeforeTransactionTimeout(boolean errorRollback)
                                         throws RollbackException
Gets time left.

Specified by:
getTimeLeftBeforeTransactionTimeout in interface org.jboss.jca.core.spi.transaction.TransactionTimeoutConfiguration
Parameters:
errorRollback - error rollback
Returns:
time left
Throws:
RollbackException - if exception

getManagedConnection

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

Overrides:
getManagedConnection in class AbstractConnectionManager
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<ConnectionRecord> crs)
                        throws SystemException
Notification of transaction started

Specified by:
transactionStarted in class AbstractConnectionManager
Parameters:
crs - the connections
Throws:
SystemException - for any error

managedConnectionReconnected

protected void managedConnectionReconnected(ConnectionListener cl)
                                     throws javax.resource.ResourceException
For polymorphism.

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

Overrides:
managedConnectionReconnected in class AbstractConnectionManager
Parameters:
cl - connection listener
Throws:
javax.resource.ResourceException - for exception

managedConnectionDisconnected

protected void managedConnectionDisconnected(ConnectionListener cl)
                                      throws javax.resource.ResourceException
For polymorphism.

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

Overrides:
managedConnectionDisconnected in class AbstractConnectionManager
Parameters:
cl - connection listener
Throws:
javax.resource.ResourceException - for exception

createConnectionListener

public ConnectionListener createConnectionListener(javax.resource.spi.ManagedConnection mc,
                                                   Object context)
                                            throws javax.resource.ResourceException
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()
Determine whether there connection is a transactional.

Specified by:
isTransactional in interface ConnectionListenerFactory
Specified by:
isTransactional in class AbstractConnectionManager
Returns:
whether it is a transactional or not

getTransactionTimeout

public int getTransactionTimeout()
                          throws SystemException

Specified by:
getTransactionTimeout in interface org.jboss.jca.core.spi.transaction.TransactionTimeoutConfiguration
Throws:
SystemException

rethrowAsSystemException

public static void rethrowAsSystemException(String context,
                                            Transaction tx,
                                            Throwable t)
                                     throws SystemException
RethrowAsSystemException.

Parameters:
context - context
tx - transaction
t - throwable
Throws:
SystemException - system exception


Copyright © 2008 Red Hat Middleware LLC (http://www.jboss.com/)