Class ManagedConnectionImpl
- java.lang.Object
-
- org.objectweb.joram.client.connector.ManagedConnectionImpl
-
- All Implemented Interfaces:
ExceptionListener,LocalTransaction,ManagedConnection
public class ManagedConnectionImpl extends Object implements ManagedConnection, LocalTransaction, 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 XAConnectioncnxPhysical connection to the JORAM server.(package private) ConnectionRequestInfocxRequestonly used for reconnectionprivate static booleanDEBUGprivate Vector<OutboundConnection>handlesVector of connection handles.private inthashCodehashCode(package private) StringhostNameUnderlying JORAM server host name.private Vector<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 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, 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(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, ConnectionRequestInfo cxRequestInfo)Returns a newOutboundConnectioninstance for handling the physical connection.LocalTransactiongetLocalTransaction()Returns this managed connection instance as aLocalTransactioninstance for managing local transactions.PrintWritergetLogWriter()Gets the log writer for thisManagedConnectionImplinstance.ManagedConnectionMetaDatagetMetaData()Returns the metadata information for the underlying JORAM server.(package private) 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(JMSException exc)Notifies that the wrapped physical connection has been lost.(package private) voidreconnect()voidremoveConnectionEventListener(ConnectionEventListener listener)Removes a connection event listener.voidrollback()Rollsback the local transaction.voidsetLogWriter(PrintWriter out)Sets the log writer for thisManagedConnectionImplinstance.(package private) voidsetSession(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 XAConnection cnx
Physical connection to the JORAM server.
-
handles
private Vector<OutboundConnection> handles
Vector of connection handles.
-
listeners
private Vector<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 Session session
Unique session for the use of managed components, involved in local or distributed transactions.
-
subject
Subject subject
only used for reconnection
-
cxRequest
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, 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 Session getSession()
-
setSession
final void setSession(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, ConnectionRequestInfo cxRequestInfo) throws ResourceException
Returns a newOutboundConnectioninstance for handling the physical connection.- Specified by:
getConnectionin interfaceManagedConnection- Throws:
CommException- If the wrapped physical connection is lost.ResourceException
-
associateConnection
public void associateConnection(Object connection) throws ResourceException
Dissociates a given connection handle and associates it to this managed connection.- Specified by:
associateConnectionin interfaceManagedConnection- Throws:
CommException- If the wrapped physical connection is lost.ResourceException- If the provided handle is invalid.
-
addConnectionEventListener
public void addConnectionEventListener(ConnectionEventListener listener)
Adds a connection event listener.- Specified by:
addConnectionEventListenerin interfaceManagedConnection
-
removeConnectionEventListener
public void removeConnectionEventListener(ConnectionEventListener listener)
Removes a connection event listener.- Specified by:
removeConnectionEventListenerin interfaceManagedConnection
-
getXAResource
public XAResource getXAResource() throws ResourceException
Provides aXAResourceinstance for managing distributed transactions.- Specified by:
getXAResourcein interfaceManagedConnection- Throws:
CommException- If the physical connection is lost.IllegalStateException- If the managed connection is involved in a local transaction.ResourceAdapterInternalException- If the XA resource can't be retrieved.ResourceException
-
getLocalTransaction
public LocalTransaction getLocalTransaction() throws ResourceException
Returns this managed connection instance as aLocalTransactioninstance for managing local transactions.- Specified by:
getLocalTransactionin interfaceManagedConnection- Throws:
CommException- If the physical connection is lost.IllegalStateException- If the managed connection is involved in a distributed transaction.LocalTransactionException- If the LocalTransaction resource can't be created.ResourceException
-
getMetaData
public ManagedConnectionMetaData getMetaData() throws ResourceException
Returns the metadata information for the underlying JORAM server.- Specified by:
getMetaDatain interfaceManagedConnection- Throws:
ResourceException- Never thrown.
-
setLogWriter
public void setLogWriter(PrintWriter out) throws ResourceException
Sets the log writer for thisManagedConnectionImplinstance.- Specified by:
setLogWriterin interfaceManagedConnection- Throws:
ResourceException- Never thrown.
-
getLogWriter
public PrintWriter getLogWriter() throws ResourceException
Gets the log writer for thisManagedConnectionImplinstance.- Specified by:
getLogWriterin interfaceManagedConnection- Throws:
ResourceException- Never thrown.
-
cleanup
public void cleanup() throws ResourceExceptionRemove the created handles and prepares the physical connection to be put back into a connection pool.- Specified by:
cleanupin interfaceManagedConnection- Throws:
ResourceException- Never thrown.
-
destroy
public void destroy() throws ResourceExceptionDestroys the physical connection to the underlying JORAM server.- Specified by:
destroyin interfaceManagedConnection- Throws:
ResourceException- Never thrown.
-
onException
public void onException(JMSException exc)
Notifies that the wrapped physical connection has been lost.- Specified by:
onExceptionin interfaceExceptionListener
-
reconnect
void reconnect()
-
isReconnected
boolean isReconnected()
-
begin
public void begin() throws ResourceExceptionNotifies that the local transaction is beginning.- Specified by:
beginin interfaceLocalTransaction- Throws:
CommException- If the wrapped physical connection is lost.LocalTransactionException- If a local transaction has already begun.ResourceException
-
commit
public void commit() throws ResourceExceptionCommits the local transaction.- Specified by:
commitin interfaceLocalTransaction- Throws:
CommException- If the wrapped physical connection is lost.LocalTransactionException- If the local transaction has not begun, or if the commit fails.ResourceException
-
rollback
public void rollback() throws ResourceExceptionRollsback the local transaction.- Specified by:
rollbackin interfaceLocalTransaction- Throws:
CommException- If the wrapped physical connection is lost.LocalTransactionException- If the local transaction has not begun, or if the rollback fails.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.
-
-