Class 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
    A ManagedConnectionImpl instance wraps a physical connection to an underlying JORAM server, and provides "handles" for handling this physical connection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addConnectionEventListener​(jakarta.resource.spi.ConnectionEventListener listener)
      Adds a connection event listener.
      void associateConnection​(Object connection)
      Dissociates a given connection handle and associates it to this managed connection.
      void begin()
      Notifies that the local transaction is beginning.
      void cleanup()
      Remove the created handles and prepares the physical connection to be put back into a connection pool.
      (package private) void closeHandle​(OutboundConnection handle)
      Notifies of the closing of one of the connection handles.
      void commit()
      Commits the local transaction.
      void destroy()
      Destroys the physical connection to the underlying JORAM server.
      boolean equals​(Object o)
      Compares ManagedConnectionImpl instances according to their server and user identification parameters.
      Object getConnection​(Subject subject, jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo)
      Returns a new OutboundConnection instance for handling the physical connection.
      jakarta.resource.spi.LocalTransaction getLocalTransaction()
      Returns this managed connection instance as a LocalTransaction instance for managing local transactions.
      PrintWriter getLogWriter()
      Gets the log writer for this ManagedConnectionImpl instance.
      jakarta.resource.spi.ManagedConnectionMetaData getMetaData()
      Returns the metadata information for the underlying JORAM server.
      (package private) jakarta.jms.Session getSession()  
      XAResource getXAResource()
      Provides a XAResource instance for managing distributed transactions.
      int hashCode()
      Returns a code based on the JORAM server and user identification parameters.
      (package private) boolean isReconnected()  
      (package private) boolean isValid()
      Returns false if the wrapped physical connection has been lost or destroyed, true if it is still valid.
      (package private) boolean matches​(String hostName, int serverPort, String userName, String mode)
      Returns true if this managed connection matches given parameters.
      void onException​(jakarta.jms.JMSException exc)
      Notifies that the wrapped physical connection has been lost.
      (package private) void reconnect()  
      void removeConnectionEventListener​(jakarta.resource.spi.ConnectionEventListener listener)
      Removes a connection event listener.
      void rollback()
      Rollsback the local transaction.
      void setLogWriter​(PrintWriter out)
      Sets the log writer for this ManagedConnectionImpl instance.
      (package private) void setSession​(jakarta.jms.Session session)  
    • Field Detail

      • logger

        private static final Logger logger
      • DEBUG

        private static final boolean DEBUG
      • cnx

        private jakarta.jms.XAConnection cnx
        Physical connection to the JORAM server.
      • listeners

        private Vector<jakarta.resource.spi.ConnectionEventListener> listeners
        Vector of condition event listeners.
      • startedLocalTx

        private boolean startedLocalTx
        true if a local transaction has been started.
      • out

        private PrintWriter out
        Out stream for error logging and tracing.
      • valid

        private boolean valid
        true if 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 a ManagedConnectionImpl instance wrapping a physical connection to the underlying JORAM server.
        Parameters:
        ra - Central adapter authority.
        mcf - The Managed Connection Factory
        cnx - 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.
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object o)
        Compares ManagedConnectionImpl instances according to their server and user identification parameters.
        Overrides:
        equals in class Object
      • getConnection

        public Object getConnection​(Subject subject,
                                    jakarta.resource.spi.ConnectionRequestInfo cxRequestInfo)
                             throws jakarta.resource.ResourceException
        Returns a new OutboundConnection instance for handling the physical connection.
        Specified by:
        getConnection in interface jakarta.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:
        associateConnection in interface jakarta.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:
        addConnectionEventListener in interface jakarta.resource.spi.ManagedConnection
      • removeConnectionEventListener

        public void removeConnectionEventListener​(jakarta.resource.spi.ConnectionEventListener listener)
        Removes a connection event listener.
        Specified by:
        removeConnectionEventListener in interface jakarta.resource.spi.ManagedConnection
      • getXAResource

        public XAResource getXAResource()
                                 throws jakarta.resource.ResourceException
        Provides a XAResource instance for managing distributed transactions.
        Specified by:
        getXAResource in interface jakarta.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.ResourceException
        Returns this managed connection instance as a LocalTransaction instance for managing local transactions.
        Specified by:
        getLocalTransaction in interface jakarta.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.ResourceException
        Returns the metadata information for the underlying JORAM server.
        Specified by:
        getMetaData in interface jakarta.resource.spi.ManagedConnection
        Throws:
        jakarta.resource.ResourceException - Never thrown.
      • setLogWriter

        public void setLogWriter​(PrintWriter out)
                          throws jakarta.resource.ResourceException
        Sets the log writer for this ManagedConnectionImpl instance.
        Specified by:
        setLogWriter in interface jakarta.resource.spi.ManagedConnection
        Throws:
        jakarta.resource.ResourceException - Never thrown.
      • getLogWriter

        public PrintWriter getLogWriter()
                                 throws jakarta.resource.ResourceException
        Gets the log writer for this ManagedConnectionImpl instance.
        Specified by:
        getLogWriter in interface jakarta.resource.spi.ManagedConnection
        Throws:
        jakarta.resource.ResourceException - Never thrown.
      • cleanup

        public void cleanup()
                     throws jakarta.resource.ResourceException
        Remove the created handles and prepares the physical connection to be put back into a connection pool.
        Specified by:
        cleanup in interface jakarta.resource.spi.ManagedConnection
        Throws:
        jakarta.resource.ResourceException - Never thrown.
      • destroy

        public void destroy()
                     throws jakarta.resource.ResourceException
        Destroys the physical connection to the underlying JORAM server.
        Specified by:
        destroy in interface jakarta.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:
        onException in interface jakarta.jms.ExceptionListener
      • reconnect

        void reconnect()
      • isReconnected

        boolean isReconnected()
      • begin

        public void begin()
                   throws jakarta.resource.ResourceException
        Notifies that the local transaction is beginning.
        Specified by:
        begin in interface jakarta.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.ResourceException
        Commits the local transaction.
        Specified by:
        commit in interface jakarta.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.ResourceException
        Rollsback the local transaction.
        Specified by:
        rollback in interface jakarta.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)
        Returns true if this managed connection matches given parameters.
      • isValid

        boolean isValid()
        Returns false if the wrapped physical connection has been lost or destroyed, true if it is still valid.
      • closeHandle

        void closeHandle​(OutboundConnection handle)
        Notifies of the closing of one of the connection handles.