Package org.ow2.joram.jakarta.connector
Class ManagedConnectionImpl
- java.lang.Object
-
- org.ow2.joram.jakarta.connector.ManagedConnectionImpl
-
- All Implemented Interfaces:
jakarta.jms.ExceptionListener,jakarta.resource.spi.LocalTransaction,jakarta.resource.spi.ManagedConnection
public class ManagedConnectionImpl extends Object implements jakarta.resource.spi.ManagedConnection, jakarta.resource.spi.LocalTransaction, jakarta.jms.ExceptionListener
AManagedConnectionImplinstance wraps a physical connection to an underlying JORAM server, and provides "handles" for handling this physical connection.
-
-
Field Summary
Fields Modifier and Type Field Description private jakarta.jms.XAConnectioncnxPhysical connection to the JORAM server.(package private) jakarta.resource.spi.ConnectionRequestInfocxRequestonly used for reconnectionprivate static booleanDEBUGprivate Vector<OutboundConnection>handlesVector of connection handles.private inthashCodehashCode(package private) StringhostNameUnderlying JORAM server host name.private Vector<jakarta.resource.spi.ConnectionEventListener>listenersVector of condition event listeners.private ObjectlockUse for reconnection synchronizationprivate ObjectlockForExcprivate static Loggerlogger(package private) ManagedConnectionFactoryImplmcfRef to the managed connection factory (use to reconnect)private ManagedConnectionMetaDataImplmetaDataConnection meta data.(package private) StringmodeMessaging mode (PTP or PubSub or Unified).private PrintWriteroutOut stream for error logging and tracing.private JoramResourceAdapterraCentral adapter authority.(package private) intserverPortUnderlying JORAM server port number.private jakarta.jms.SessionsessionUnique session for the use of managed components, involved in local or distributed transactions.private booleanstartedLocalTxtrueif a local transaction has been started.(package private) Subjectsubjectonly used for reconnectionprivate longtimeWaitReconnectThe waiting time in ms for reconnection.(package private) StringuserNameUser identification.private booleanvalidtrueif the connection is valid.
-
Constructor Summary
Constructors Constructor Description ManagedConnectionImpl(JoramResourceAdapter ra, ManagedConnectionFactoryImpl mcf, jakarta.jms.XAConnection cnx, String hostName, int serverPort, String userName)Creates aManagedConnectionImplinstance wrapping a physical connection to the underlying JORAM server.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)Adds a connection event listener.voidassociateConnection(Object connection)Dissociates a given connection handle and associates it to this managed connection.voidbegin()Notifies that the local transaction is beginning.voidcleanup()Remove the created handles and prepares the physical connection to be put back into a connection pool.(package private) voidcloseHandle(OutboundConnection handle)Notifies of the closing of one of the connection handles.voidcommit()Commits the local transaction.voiddestroy()Destroys the physical connection to the underlying JORAM server.booleanequals(Object o)ComparesManagedConnectionImplinstances according to their server and user identification parameters.ObjectgetConnection(Subject subject, jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo)Returns a newOutboundConnectioninstance for handling the physical connection.jakarta.resource.spi.LocalTransactiongetLocalTransaction()Returns this managed connection instance as aLocalTransactioninstance for managing local transactions.PrintWritergetLogWriter()Gets the log writer for thisManagedConnectionImplinstance.jakarta.resource.spi.ManagedConnectionMetaDatagetMetaData()Returns the metadata information for the underlying JORAM server.(package private) jakarta.jms.SessiongetSession()XAResourcegetXAResource()Provides aXAResourceinstance for managing distributed transactions.inthashCode()Returns a code based on the JORAM server and user identification parameters.(package private) booleanisReconnected()(package private) booleanisValid()Returnsfalseif the wrapped physical connection has been lost or destroyed,trueif it is still valid.(package private) booleanmatches(String hostName, int serverPort, String userName, String mode)Returnstrueif this managed connection matches given parameters.voidonException(jakarta.jms.JMSException exc)Notifies that the wrapped physical connection has been lost.(package private) voidreconnect()voidremoveConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)Removes a connection event listener.voidrollback()Rollsback the local transaction.voidsetLogWriter(PrintWriter out)Sets the log writer for thisManagedConnectionImplinstance.(package private) voidsetSession(jakarta.jms.Session session)
-
-
-
Field Detail
-
logger
private static final Logger logger
-
DEBUG
private static final boolean DEBUG
-
ra
private JoramResourceAdapter ra
Central adapter authority.
-
mcf
ManagedConnectionFactoryImpl mcf
Ref to the managed connection factory (use to reconnect)
-
cnx
private jakarta.jms.XAConnection cnx
Physical connection to the JORAM server.
-
handles
private Vector<OutboundConnection> handles
Vector of connection handles.
-
listeners
private Vector<jakarta.resource.spi.ConnectionEventListener> listeners
Vector of condition event listeners.
-
startedLocalTx
private boolean startedLocalTx
trueif a local transaction has been started.
-
metaData
private ManagedConnectionMetaDataImpl metaData
Connection meta data.
-
out
private PrintWriter out
Out stream for error logging and tracing.
-
valid
private boolean valid
trueif the connection is valid.
-
hashCode
private int hashCode
hashCode
-
hostName
String hostName
Underlying JORAM server host name.
-
serverPort
int serverPort
Underlying JORAM server port number.
-
mode
String mode
Messaging mode (PTP or PubSub or Unified).
-
userName
String userName
User identification.
-
session
private jakarta.jms.Session session
Unique session for the use of managed components, involved in local or distributed transactions.
-
subject
Subject subject
only used for reconnection
-
cxRequest
jakarta.resource.spi.ConnectionRequestInfo cxRequest
only used for reconnection
-
lock
private Object lock
Use for reconnection synchronization
-
timeWaitReconnect
private long timeWaitReconnect
The waiting time in ms for reconnection.
-
lockForExc
private Object lockForExc
-
-
Constructor Detail
-
ManagedConnectionImpl
ManagedConnectionImpl(JoramResourceAdapter ra, ManagedConnectionFactoryImpl mcf, jakarta.jms.XAConnection cnx, String hostName, int serverPort, String userName)
Creates aManagedConnectionImplinstance wrapping a physical connection to the underlying JORAM server.- Parameters:
ra- Central adapter authority.mcf- The Managed Connection Factorycnx- Physical connection to the JORAM server.hostName- JORAM server host name.serverPort- JORAM server port number.userName- User identification.
-
-
Method Detail
-
getSession
final jakarta.jms.Session getSession()
-
setSession
final void setSession(jakarta.jms.Session session)
-
hashCode
public int hashCode()
Returns a code based on the JORAM server and user identification parameters.
-
equals
public boolean equals(Object o)
ComparesManagedConnectionImplinstances according to their server and user identification parameters.
-
getConnection
public Object getConnection(Subject subject, jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo) throws jakarta.resource.ResourceException
Returns a newOutboundConnectioninstance for handling the physical connection.- Specified by:
getConnectionin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.spi.CommException- If the wrapped physical connection is lost.jakarta.resource.ResourceException
-
associateConnection
public void associateConnection(Object connection) throws jakarta.resource.ResourceException
Dissociates a given connection handle and associates it to this managed connection.- Specified by:
associateConnectionin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.spi.CommException- If the wrapped physical connection is lost.jakarta.resource.ResourceException- If the provided handle is invalid.
-
addConnectionEventListener
public void addConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)
Adds a connection event listener.- Specified by:
addConnectionEventListenerin interfacejakarta.resource.spi.ManagedConnection
-
removeConnectionEventListener
public void removeConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)
Removes a connection event listener.- Specified by:
removeConnectionEventListenerin interfacejakarta.resource.spi.ManagedConnection
-
getXAResource
public XAResource getXAResource() throws jakarta.resource.ResourceException
Provides aXAResourceinstance for managing distributed transactions.- Specified by:
getXAResourcein interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.spi.CommException- If the physical connection is lost.jakarta.resource.spi.IllegalStateException- If the managed connection is involved in a local transaction.jakarta.resource.spi.ResourceAdapterInternalException- If the XA resource can't be retrieved.jakarta.resource.ResourceException
-
getLocalTransaction
public jakarta.resource.spi.LocalTransaction getLocalTransaction() throws jakarta.resource.ResourceExceptionReturns this managed connection instance as aLocalTransactioninstance for managing local transactions.- Specified by:
getLocalTransactionin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.spi.CommException- If the physical connection is lost.jakarta.resource.spi.IllegalStateException- If the managed connection is involved in a distributed transaction.jakarta.resource.spi.LocalTransactionException- If the LocalTransaction resource can't be created.jakarta.resource.ResourceException
-
getMetaData
public jakarta.resource.spi.ManagedConnectionMetaData getMetaData() throws jakarta.resource.ResourceExceptionReturns the metadata information for the underlying JORAM server.- Specified by:
getMetaDatain interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.ResourceException- Never thrown.
-
setLogWriter
public void setLogWriter(PrintWriter out) throws jakarta.resource.ResourceException
Sets the log writer for thisManagedConnectionImplinstance.- Specified by:
setLogWriterin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.ResourceException- Never thrown.
-
getLogWriter
public PrintWriter getLogWriter() throws jakarta.resource.ResourceException
Gets the log writer for thisManagedConnectionImplinstance.- Specified by:
getLogWriterin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.ResourceException- Never thrown.
-
cleanup
public void cleanup() throws jakarta.resource.ResourceExceptionRemove the created handles and prepares the physical connection to be put back into a connection pool.- Specified by:
cleanupin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.ResourceException- Never thrown.
-
destroy
public void destroy() throws jakarta.resource.ResourceExceptionDestroys the physical connection to the underlying JORAM server.- Specified by:
destroyin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.ResourceException- Never thrown.
-
onException
public void onException(jakarta.jms.JMSException exc)
Notifies that the wrapped physical connection has been lost.- Specified by:
onExceptionin interfacejakarta.jms.ExceptionListener
-
reconnect
void reconnect()
-
isReconnected
boolean isReconnected()
-
begin
public void begin() throws jakarta.resource.ResourceExceptionNotifies that the local transaction is beginning.- Specified by:
beginin interfacejakarta.resource.spi.LocalTransaction- Throws:
jakarta.resource.spi.CommException- If the wrapped physical connection is lost.jakarta.resource.spi.LocalTransactionException- If a local transaction has already begun.jakarta.resource.ResourceException
-
commit
public void commit() throws jakarta.resource.ResourceExceptionCommits the local transaction.- Specified by:
commitin interfacejakarta.resource.spi.LocalTransaction- Throws:
jakarta.resource.spi.CommException- If the wrapped physical connection is lost.jakarta.resource.spi.LocalTransactionException- If the local transaction has not begun, or if the commit fails.jakarta.resource.ResourceException
-
rollback
public void rollback() throws jakarta.resource.ResourceExceptionRollsback the local transaction.- Specified by:
rollbackin interfacejakarta.resource.spi.LocalTransaction- Throws:
jakarta.resource.spi.CommException- If the wrapped physical connection is lost.jakarta.resource.spi.LocalTransactionException- If the local transaction has not begun, or if the rollback fails.jakarta.resource.ResourceException
-
matches
boolean matches(String hostName, int serverPort, String userName, String mode)
Returnstrueif this managed connection matches given parameters.
-
isValid
boolean isValid()
Returnsfalseif the wrapped physical connection has been lost or destroyed,trueif it is still valid.
-
closeHandle
void closeHandle(OutboundConnection handle)
Notifies of the closing of one of the connection handles.
-
-