public class JmsManagedConnection extends Object implements ManagedConnection, ExceptionListener
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?
Constructor and Description |
---|
JmsManagedConnection(JmsManagedConnectionFactory mcf,
ConnectionRequestInfo info,
String user,
String pwd)
Create a JmsManagedConnection.
|
Modifier and Type | Method and Description |
---|---|
void |
addConnectionEventListener(ConnectionEventListener l)
Add a connection event listener.
|
void |
associateConnection(Object obj)
Move a handler from one mc to this one.
|
void |
cleanup()
Cleans up, from the spec - The cleanup of ManagedConnection instance resets its client specific state.
|
Connection |
createConnection(Object factory,
String username,
String password)
Create a connection from the given factory.
|
void |
destroy()
Destroy the physical connection.
|
Object |
getConnection(Subject subject,
ConnectionRequestInfo info)
Get the physical connection handler.
|
protected ConnectionRequestInfo |
getInfo()
Get the request info for this connection.
|
LocalTransaction |
getLocalTransaction()
Get the location transaction for the connection.
|
PrintWriter |
getLogWriter()
Get the log writer for this connection.
|
protected JmsManagedConnectionFactory |
getManagedConnectionFactory()
Get the connection factory for this connection.
|
ManagedConnectionMetaData |
getMetaData()
Get the meta data for the connection.
|
protected Session |
getSession()
Get the session for this connection.
|
protected String |
getUserName()
Get the user name for this connection.
|
XAResource |
getXAResource()
Get the XAResource for the connection.
|
protected void |
lock() |
void |
onException(JMSException exception)
Notifies user of a JMS exception.
|
void |
removeConnectionEventListener(ConnectionEventListener l)
Remove a connection event listener.
|
protected void |
removeHandle(JmsSession handle)
Remove a handle from the handle map.
|
protected void |
sendEvent(ConnectionEvent event)
Send an event.
|
void |
setLogWriter(PrintWriter out)
Set the log writer for this connection.
|
protected void |
tryLock() |
protected void |
unlock() |
public JmsManagedConnection(JmsManagedConnectionFactory mcf, ConnectionRequestInfo info, String user, String pwd) throws ResourceException
mcf
- info
- user
- pwd
- ResourceException
public Object getConnection(Subject subject, ConnectionRequestInfo info) throws ResourceException
getConnection
in interface ManagedConnection
subject
- info
- ResourceException
ResourceAdapterInternalException
- resource adapter internal error conditionSecurityException
- security related error conditionCommException
- failed communication with EIS instanceEISSystemException
- internal error condition in EIS instance
- used if EIS instance is involved in
setting state of ManagedConnectionpublic void destroy() throws ResourceException
destroy
in interface ManagedConnection
ResourceException
- Could not property close the session and connection.public void cleanup() throws ResourceException
cleanup
in interface ManagedConnection
ResourceException
- generic exception if operation failsResourceAdapterInternalException
- resource adapter internal error conditionIllegalStateException
- Illegal state for calling connection
cleanup. Example - if a localtransaction
is in progress that doesn't allow
connection cleanuppublic void associateConnection(Object obj) throws ResourceException
associateConnection
in interface ManagedConnection
obj
- An object of type JmsSession.ResourceException
- Failed to associate connection.IllegalStateException
- ManagedConnection in an illegal state.protected void lock()
protected void tryLock() throws JMSException
JMSException
protected void unlock()
public void addConnectionEventListener(ConnectionEventListener l)
addConnectionEventListener
in interface ManagedConnection
l
- The connection event listener to be added.public void removeConnectionEventListener(ConnectionEventListener l)
removeConnectionEventListener
in interface ManagedConnection
l
- The connection event listener to be removed.public XAResource getXAResource() throws ResourceException
getXAResource
in interface ManagedConnection
ResourceException
- XA transaction not supportedpublic LocalTransaction getLocalTransaction() throws ResourceException
getLocalTransaction
in interface ManagedConnection
ResourceException
NotSupportedException
- if the operation is not supportedResourceAdapterInternalException
- resource adapter internal error conditionpublic ManagedConnectionMetaData getMetaData() throws ResourceException
getMetaData
in interface ManagedConnection
ResourceException
IllegalStateException
- ManagedConnection already destroyed.NotSupportedException
- if the operation is not supportedpublic void setLogWriter(PrintWriter out) throws ResourceException
setLogWriter
in interface ManagedConnection
out
- The log writer for this connection.ResourceException
ResourceAdapterInternalException
- resource adapter related error conditionpublic PrintWriter getLogWriter() throws ResourceException
getLogWriter
in interface ManagedConnection
ResourceException
- generic exception if operation failspublic void onException(JMSException exception)
ExceptionListener
onException
in interface ExceptionListener
exception
- the JMS exceptionprotected Session getSession()
protected void sendEvent(ConnectionEvent event)
event
- The event to send.protected void removeHandle(JmsSession handle)
handle
- The handle to remove.protected ConnectionRequestInfo getInfo()
protected JmsManagedConnectionFactory getManagedConnectionFactory()
protected String getUserName()
public Connection createConnection(Object factory, String username, String password) throws JMSException
factory
- An object that implements ConnectionFactory,
XAQConnectionFactoryusername
- The username to use or null for no user.password
- The password for the given username or null if no
username was specified.JMSException
- Failed to create connection.IllegalArgumentException
- Factory is null or invalid.Copyright © 2018 JBoss by Red Hat. All rights reserved.