org.objectweb.joram.client.connector
Class ManagedConnectionImpl

java.lang.Object
  extended by org.objectweb.joram.client.connector.ManagedConnectionImpl
All Implemented Interfaces:
javax.jms.ExceptionListener, javax.resource.spi.LocalTransaction, javax.resource.spi.ManagedConnection

public class ManagedConnectionImpl
extends java.lang.Object
implements javax.resource.spi.ManagedConnection, javax.resource.spi.LocalTransaction, javax.jms.ExceptionListener

A ManagedConnectionImpl instance wraps a physical connection to an underlying JORAM server, and provides "handles" for handling this physical connection.


Field Summary
private  javax.jms.XAConnection cnx
          Physical connection to the JORAM server.
private  java.util.Vector handles
          Vector of connection handles.
private  int hashCode
          hashCode
(package private)  java.lang.String hostName
          Underlying JORAM server host name.
private  java.util.Vector listeners
          Vector of condition event listeners.
private  ManagedConnectionMetaDataImpl metaData
          Connection meta data.
(package private)  java.lang.String mode
          Messaging mode (PTP or PubSub or Unified).
private  java.io.PrintWriter out
          Out stream for error logging and tracing.
private  JoramAdapter ra
          Central adapter authority.
(package private)  int serverPort
          Underlying JORAM server port number.
(package private)  javax.jms.Session session
          Unique session for the use of managed components, involved in local or distributed transactions.
private  boolean startedLocalTx
          true if a local transaction has been started.
(package private)  java.lang.String userName
          User identification.
private  boolean valid
          true if the connection is valid.
 
Constructor Summary
ManagedConnectionImpl(JoramAdapter ra, javax.jms.XAConnection cnx, java.lang.String hostName, int serverPort, java.lang.String userName)
          Creates a ManagedConnectionImpl instance wrapping a physical connection to the underlying JORAM server.
 
Method Summary
 void addConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)
          Adds a connection event listener.
 void associateConnection(java.lang.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()
          Invalidates 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(java.lang.Object o)
          Compares ManagedConnectionImpl instances according to their server and user identification parameters.
 java.lang.Object getConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
          Returns a new OutboundConnection instance for handling the physical connection.
 javax.resource.spi.LocalTransaction getLocalTransaction()
          Returns this managed connection instance as a LocalTransaction instance for managing local transactions.
 java.io.PrintWriter getLogWriter()
          Gets the log writer for this ManagedConnectionImpl instance.
 javax.resource.spi.ManagedConnectionMetaData getMetaData()
          Returns the metadata information for the underlying JORAM server.
 javax.transaction.xa.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 isValid()
          Returns false if the wrapped physical connection has been lost or destroyed, true if it is still valid.
(package private)  boolean matches(java.lang.String hostName, int serverPort, java.lang.String userName, java.lang.String mode)
          Returns true if this managed connection matches given parameters.
 void onException(javax.jms.JMSException exc)
          Notifies that the wrapped physical connection has been lost.
 void removeConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)
          Removes a connection event listener.
 void rollback()
          Rollsback the local transaction.
 void setLogWriter(java.io.PrintWriter out)
          Sets the log writer for this ManagedConnectionImpl instance.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ra

private JoramAdapter ra
Central adapter authority.


cnx

private javax.jms.XAConnection cnx
Physical connection to the JORAM server.


handles

private java.util.Vector handles
Vector of connection handles.


listeners

private java.util.Vector listeners
Vector of condition event listeners.


startedLocalTx

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


metaData

private ManagedConnectionMetaDataImpl metaData
Connection meta data.


out

private java.io.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

java.lang.String hostName
Underlying JORAM server host name.


serverPort

int serverPort
Underlying JORAM server port number.


mode

java.lang.String mode
Messaging mode (PTP or PubSub or Unified).


userName

java.lang.String userName
User identification.


session

javax.jms.Session session
Unique session for the use of managed components, involved in local or distributed transactions.

Constructor Detail

ManagedConnectionImpl

ManagedConnectionImpl(JoramAdapter ra,
                      javax.jms.XAConnection cnx,
                      java.lang.String hostName,
                      int serverPort,
                      java.lang.String userName)
Creates a ManagedConnectionImpl instance wrapping a physical connection to the underlying JORAM server.

Parameters:
ra - Central adapter authority.
cnx - Physical connection to the JORAM server.
hostName - JORAM server host name.
serverPort - JORAM server port number.
userName - User identification.
Method Detail

getConnection

public java.lang.Object getConnection(javax.security.auth.Subject subject,
                                      javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
                               throws javax.resource.ResourceException
Returns a new OutboundConnection instance for handling the physical connection.

Specified by:
getConnection in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.spi.CommException - If the wrapped physical connection is lost.
javax.resource.ResourceException

associateConnection

public void associateConnection(java.lang.Object connection)
                         throws javax.resource.ResourceException
Dissociates a given connection handle and associates it to this managed connection.

Specified by:
associateConnection in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.spi.CommException - If the wrapped physical connection is lost.
javax.resource.ResourceException - If the provided handle is invalid.

addConnectionEventListener

public void addConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)
Adds a connection event listener.

Specified by:
addConnectionEventListener in interface javax.resource.spi.ManagedConnection

removeConnectionEventListener

public void removeConnectionEventListener(javax.resource.spi.ConnectionEventListener listener)
Removes a connection event listener.

Specified by:
removeConnectionEventListener in interface javax.resource.spi.ManagedConnection

getXAResource

public javax.transaction.xa.XAResource getXAResource()
                                              throws javax.resource.ResourceException
Provides a XAResource instance for managing distributed transactions.

Specified by:
getXAResource in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.spi.CommException - If the physical connection is lost.
javax.resource.spi.IllegalStateException - If the managed connection is involved in a local transaction.
javax.resource.spi.ResourceAdapterInternalException - If the XA resource can't be retrieved.
javax.resource.ResourceException

getLocalTransaction

public javax.resource.spi.LocalTransaction getLocalTransaction()
                                                        throws javax.resource.ResourceException
Returns this managed connection instance as a LocalTransaction instance for managing local transactions.

Specified by:
getLocalTransaction in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.spi.CommException - If the physical connection is lost.
javax.resource.spi.IllegalStateException - If the managed connection is involved in a distributed transaction.
javax.resource.spi.LocalTransactionException - If the LocalTransaction resource can't be created.
javax.resource.ResourceException

getMetaData

public javax.resource.spi.ManagedConnectionMetaData getMetaData()
                                                         throws javax.resource.ResourceException
Returns the metadata information for the underlying JORAM server.

Specified by:
getMetaData in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException - Never thrown.

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws javax.resource.ResourceException
Sets the log writer for this ManagedConnectionImpl instance.

Specified by:
setLogWriter in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException - Never thrown.

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws javax.resource.ResourceException
Gets the log writer for this ManagedConnectionImpl instance.

Specified by:
getLogWriter in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException - Never thrown.

cleanup

public void cleanup()
             throws javax.resource.ResourceException
Invalidates the created handles and prepares the physical connection to be put back into a connection pool.

Specified by:
cleanup in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException - Never thrown.

destroy

public void destroy()
             throws javax.resource.ResourceException
Destroys the physical connection to the underlying JORAM server.

Specified by:
destroy in interface javax.resource.spi.ManagedConnection
Throws:
javax.resource.ResourceException - Never thrown.

hashCode

public int hashCode()
Returns a code based on the JORAM server and user identification parameters.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Compares ManagedConnectionImpl instances according to their server and user identification parameters.

Overrides:
equals in class java.lang.Object

onException

public void onException(javax.jms.JMSException exc)
Notifies that the wrapped physical connection has been lost.

Specified by:
onException in interface javax.jms.ExceptionListener

begin

public void begin()
           throws javax.resource.ResourceException
Notifies that the local transaction is beginning.

Specified by:
begin in interface javax.resource.spi.LocalTransaction
Throws:
javax.resource.spi.CommException - If the wrapped physical connection is lost.
javax.resource.spi.LocalTransactionException - If a local transaction has already begun.
javax.resource.ResourceException

commit

public void commit()
            throws javax.resource.ResourceException
Commits the local transaction.

Specified by:
commit in interface javax.resource.spi.LocalTransaction
Throws:
javax.resource.spi.CommException - If the wrapped physical connection is lost.
javax.resource.spi.LocalTransactionException - If the local transaction has not begun, or if the commit fails.
javax.resource.ResourceException

rollback

public void rollback()
              throws javax.resource.ResourceException
Rollsback the local transaction.

Specified by:
rollback in interface javax.resource.spi.LocalTransaction
Throws:
javax.resource.spi.CommException - If the wrapped physical connection is lost.
javax.resource.spi.LocalTransactionException - If the local transaction has not begun, or if the rollback fails.
javax.resource.ResourceException

matches

boolean matches(java.lang.String hostName,
                int serverPort,
                java.lang.String userName,
                java.lang.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.



Copyright © 2010 ScalAgent D.T.. All Rights Reserved.