org.jboss.resource.adapter.jms
Class JmsManagedConnection

java.lang.Object
  extended byorg.jboss.resource.adapter.jms.JmsManagedConnection
All Implemented Interfaces:
ExceptionListener (src) , ManagedConnection (src)

public class JmsManagedConnection
extends java.lang.Object
implements ManagedConnection (src) , ExceptionListener (src)

Managed Connection, manages one or more JMS sessions.

Every ManagedConnection will have a physical JMSConnection under the hood. This may leave out several session, as specifyed in 5.5.4 Multiple Connection Handles. Thread safe semantics is provided

Hm. If we are to follow the example in 6.11 this will not work. We would have to use the SAME session. This means we will have to guard against concurrent access. We use a stack, and only allowes the handle at the top of the stack to do things.

As to transactions we some fairly hairy alternatives to handle: XA - we get an XA. We may now only do transaction through the XAResource, since a XASession MUST throw exceptions in commit etc. But since XA support implies LocatTransaction support, we will have to use the XAResource in the LocalTransaction class. LocalTx - we get a normal session. The LocalTransaction will then work against the normal session api.

An invokation of JMS MAY BE DONE in none transacted context. What do we do then? How much should we leave to the user???

One possible solution is to use transactions any way, but under the hood. If not LocalTransaction or XA has been aquired by the container, we have to do the commit in send and publish. (CHECK is the container required to get a XA every time it uses a managed connection? No its is not, only at creation!)

Does this mean that a session one time may be used in a transacted env, and another time in a not transacted.

Maybe we could have this simple rule:

If a user is going to use non trans:

From the JMS tutorial: "When you create a session in an enterprise bean, the container ignores the arguments you specify, because it manages all transactional properties for enterprise beans."

And further: "You do not specify a message acknowledgment mode when you create a message-driven bean that uses container-managed transactions. The container handles acknowledgment automatically."

On Session or Connection:

From Tutorial: "A JMS API resource is a JMS API connection or a JMS API session." But in the J2EE spec only connection is considered a resource.

Not resolved: connectionErrorOccurred: it is verry hard to know from the exceptions thrown if it is a connection error. Should we register an ExceptionListener and mark al handles as errounous? And then let them send the event and throw an exception?

Created: Tue Apr 10 13:09:45 2001


Constructor Summary
JmsManagedConnection(JmsManagedConnectionFactory (src)  mcf, ConnectionRequestInfo (src)  info, java.lang.String user, java.lang.String pwd)
          Create a JmsManagedConnection.
 
Method Summary
 void addConnectionEventListener(ConnectionEventListener (src)  l)
          Add a connection event listener.
 void associateConnection(java.lang.Object obj)
          Move a handler from one mc to this one.
 void cleanup()
          Cleans up the, from the spec - The cleanup of ManagedConnection instance resets its client specific state.
 void destroy()
          Destroy the physical connection.
 java.lang.Object getConnection(javax.security.auth.Subject subject, ConnectionRequestInfo (src)  info)
          Get the physical connection handler.
protected  ConnectionRequestInfo (src) getInfo()
          Get the request info for this connection.
 LocalTransaction (src) getLocalTransaction()
          Get the location transaction for the connection.
 java.io.PrintWriter getLogWriter()
          Get the log writer for this connection.
protected  JmsManagedConnectionFactory (src) getManagedConnectionFactory()
          Get the connection factory for this connection.
 ManagedConnectionMetaData (src) getMetaData()
          Get the meta data for the connection.
protected  Session (src) getSession()
          Get the session for this connection.
protected  java.lang.String getUserName()
          Get the user name for this connection.
 XAResource (src) getXAResource()
          Get the XAResource for the connection.
 void onException(JMSException (src)  exception)
          Notifies user of a JMS exception.
 void removeConnectionEventListener(ConnectionEventListener (src)  l)
          Remove a connection event listener.
protected  void removeHandle(JmsSession (src)  handle)
          Remove a handle from the handle map.
protected  void sendEvent(ConnectionEvent (src)  event)
          Send an event.
 void setLogWriter(java.io.PrintWriter out)
          Set the log writer for this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmsManagedConnection

public JmsManagedConnection(JmsManagedConnectionFactory (src)  mcf,
                            ConnectionRequestInfo (src)  info,
                            java.lang.String user,
                            java.lang.String pwd)
                     throws ResourceException (src) 
Create a JmsManagedConnection.

Parameters:
mcf -
info -
user -
pwd -
Throws:
ResourceException (src)
Method Detail

getConnection

public java.lang.Object getConnection(javax.security.auth.Subject subject,
                                      ConnectionRequestInfo (src)  info)
                               throws ResourceException (src) 
Get the physical connection handler.

This bummer will be called in two situations:

  1. When a new mc has bean created and a connection is needed
  2. When an mc has been fetched from the pool (returned in match*)

It may also be called multiple time without a cleanup, to support connection sharing.

Specified by:
getConnection in interface ManagedConnection (src)
Parameters:
subject -
info -
Returns:
A new connection object.
Throws:
ResourceException (src)

destroy

public void destroy()
             throws ResourceException (src) 
Destroy the physical connection.

Specified by:
destroy in interface ManagedConnection (src)
Throws:
ResourceException (src) - Could not property close the session and connection.

cleanup

public void cleanup()
             throws ResourceException (src) 
Cleans up the, from the spec - The cleanup of ManagedConnection instance resets its client specific state. Does that mean that autentication should be redone. FIXME

Specified by:
cleanup in interface ManagedConnection (src)
Throws:
ResourceException (src) - for a generic error

associateConnection

public void associateConnection(java.lang.Object obj)
                         throws ResourceException (src) 
Move a handler from one mc to this one.

Specified by:
associateConnection in interface ManagedConnection (src)
Parameters:
obj - An object of type JmsSession.
Throws:
ResourceException (src) - Failed to associate connection.
IllegalStateException (src) - ManagedConnection in an illegal state.

addConnectionEventListener

public void addConnectionEventListener(ConnectionEventListener (src)  l)
Add a connection event listener.

Specified by:
addConnectionEventListener in interface ManagedConnection (src)
Parameters:
l - The connection event listener to be added.

removeConnectionEventListener

public void removeConnectionEventListener(ConnectionEventListener (src)  l)
Remove a connection event listener.

Specified by:
removeConnectionEventListener in interface ManagedConnection (src)
Parameters:
l - The connection event listener to be removed.

getXAResource

public XAResource (src)  getXAResource()
                         throws ResourceException (src) 
Get the XAResource for the connection.

Specified by:
getXAResource in interface ManagedConnection (src)
Returns:
The XAResource for the connection.
Throws:
ResourceException (src) - XA transaction not supported

getLocalTransaction

public LocalTransaction (src)  getLocalTransaction()
                                     throws ResourceException (src) 
Get the location transaction for the connection.

Specified by:
getLocalTransaction in interface ManagedConnection (src)
Returns:
The local transaction for the connection.
Throws:
ResourceException (src)

getMetaData

public ManagedConnectionMetaData (src)  getMetaData()
                                      throws ResourceException (src) 
Get the meta data for the connection.

Specified by:
getMetaData in interface ManagedConnection (src)
Returns:
The meta data for the connection.
Throws:
ResourceException (src)
IllegalStateException (src) - ManagedConnection already destroyed.

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws ResourceException (src) 
Set the log writer for this connection.

Specified by:
setLogWriter in interface ManagedConnection (src)
Parameters:
out - The log writer for this connection.
Throws:
ResourceException (src)

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws ResourceException (src) 
Get the log writer for this connection.

Specified by:
getLogWriter in interface ManagedConnection (src)
Returns:
Always null
Throws:
ResourceException (src) - for a generic error

onException

public void onException(JMSException (src)  exception)
Description copied from interface: ExceptionListener (src)
Notifies user of a JMS exception.

Specified by:
onException in interface ExceptionListener (src)
Parameters:
exception - the JMS exception

getSession

protected Session (src)  getSession()
Get the session for this connection.

Returns:
Either a topic or queue connection.

sendEvent

protected void sendEvent(ConnectionEvent (src)  event)
Send an event.

Parameters:
event - The event to send.

removeHandle

protected void removeHandle(JmsSession (src)  handle)
Remove a handle from the handle map.

Parameters:
handle - The handle to remove.

getInfo

protected ConnectionRequestInfo (src)  getInfo()
Get the request info for this connection.

Returns:
The request info for this connection.

getManagedConnectionFactory

protected JmsManagedConnectionFactory (src)  getManagedConnectionFactory()
Get the connection factory for this connection.

Returns:
The connection factory for this connection.

getUserName

protected java.lang.String getUserName()
Get the user name for this connection.

Returns:
The user name for this connection.