Methods Summary |
---|
public void | addConnectionEventListener(javax.resource.spi.ConnectionEventListener l)Add a connection event listener.
listeners.addElement(l);
if (log.isTraceEnabled())
log.trace("ConnectionEvent listener added: " + l);
|
public void | associateConnection(java.lang.Object obj)Move a handler from one mc to this one.
//
// Should we check auth, ie user and pwd? FIXME
//
if (!isDestroyed && obj instanceof JmsSession)
{
JmsSession h = (JmsSession)obj;
h.setManagedConnection(this);
handles.add(h);
}
else
throw new IllegalStateException
("ManagedConnection in an illegal state");
|
public void | cleanup()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
if (isDestroyed)
throw new IllegalStateException("ManagedConnection already destroyed");
// destory handles
destroyHandles();
|
public void | destroy()Destroy the physical connection.
if (isDestroyed) return;
isDestroyed = true;
try
{
con.setExceptionListener(null);
}
catch (JMSException e)
{
log.debug("Error unsetting the exception listener " + this, e);
}
// destory handles
destroyHandles();
try
{
// Close session and connection
try
{
if (info.getType() == JmsConnectionFactory.TOPIC)
{
topicSession.close();
if (xaTransacted) {
xaTopicSession.close();
}
}
else if (info.getType() == JmsConnectionFactory.QUEUE)
{
queueSession.close();
if (xaTransacted)
xaQueueSession.close();
}
else
{
session.close();
if (xaTransacted)
xaSession.close();
}
}
catch (JMSException e)
{
log.debug("Error closing session " +this, e);
}
con.close();
}
catch (JMSException e)
{
throw new JBossResourceException
("Could not properly close the session and connection", e);
}
|
private void | destroyHandles()Destroy all handles.
try
{
if (con != null)
con.stop();
}
catch (Throwable t)
{
log.trace("Ignored error stopping connection", t);
}
Iterator iter = handles.iterator();
while (iter.hasNext())
((JmsSession)iter.next()).destroy();
// clear the handles map
handles.clear();
|
public java.lang.Object | getConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo info)Get the physical connection handler.
This bummer will be called in two situations:
- When a new mc has bean created and a connection is needed
- 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.
// Check user first
JmsCred cred = JmsCred.getJmsCred(mcf,subject,info);
// Null users are allowed!
if (user != null && !user.equals(cred.name))
throw new SecurityException
("Password credentials not the same, reauthentication not allowed");
if (cred.name != null && user == null) {
throw new SecurityException
("Password credentials not the same, reauthentication not allowed");
}
user = cred.name; // Basically meaningless
if (isDestroyed)
throw new IllegalStateException("ManagedConnection already destroyd");
// Create a handle
JmsSession handle = new JmsSession(this, (JmsConnectionRequestInfo) info);
handles.add(handle);
return handle;
|
protected javax.resource.spi.ConnectionRequestInfo | getInfo()Get the request info for this connection.
return info;
|
public javax.resource.spi.LocalTransaction | getLocalTransaction()Get the location transaction for the connection.
LocalTransaction tx = new JmsLocalTransaction(this);
if (log.isTraceEnabled())
log.trace("LocalTransaction=" + tx);
return tx;
|
public java.io.PrintWriter | getLogWriter()Get the log writer for this connection.
//
// jason: screw the logWriter stuff for now it sucks ass
//
return null;
|
protected JmsManagedConnectionFactory | getManagedConnectionFactory()Get the connection factory for this connection.
return mcf;
|
public javax.resource.spi.ManagedConnectionMetaData | getMetaData()Get the meta data for the connection.
if (isDestroyed)
throw new IllegalStateException("ManagedConnection already destroyd");
return new JmsMetaData(this);
|
private org.jboss.jms.jndi.JMSProviderAdapter | getProviderAdapter()Get the JMS provider adapter that will be used to create JMS
resources.
JMSProviderAdapter adapter;
if (mcf.getJmsProviderAdapterJNDI() != null)
{
// lookup the adapter from JNDI
Context ctx = new InitialContext();
try
{
adapter = (JMSProviderAdapter)
ctx.lookup(mcf.getJmsProviderAdapterJNDI());
}
finally
{
ctx.close();
}
}
else
adapter = mcf.getJmsProviderAdapter();
return adapter;
|
protected javax.jms.Session | getSession()Get the session for this connection.
if (info.getType() == JmsConnectionFactory.TOPIC)
return topicSession;
else if (info.getType() == JmsConnectionFactory.QUEUE)
return queueSession;
else
return session;
|
protected java.lang.String | getUserName()Get the user name for this connection.
return user;
|
public javax.transaction.xa.XAResource | getXAResource()Get the XAResource for the connection.
//
// Spec says a mc must allways return the same XA resource,
// so we cache it.
//
if (!xaTransacted)
throw new NotSupportedException("Non XA transaction not supported");
if (xaResource == null)
{
if (info.getType() == JmsConnectionFactory.TOPIC)
xaResource = xaTopicSession.getXAResource();
else if (info.getType() == JmsConnectionFactory.QUEUE)
xaResource = xaQueueSession.getXAResource();
else
xaResource = xaSession.getXAResource();
}
if (log.isTraceEnabled())
log.trace("XAResource=" + xaResource);
return xaResource;
|
public void | onException(javax.jms.JMSException exception)
if (isDestroyed)
{
if (log.isTraceEnabled())
log.trace("Ignoring error on already destroyed connection " + this, exception);
return;
}
log.warn("Handling jms exception failure: " + this, exception);
try
{
con.setExceptionListener(null);
}
catch (JMSException e)
{
log.debug("Unable to unset exception listener", e);
}
ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, exception);
sendEvent(event);
|
public void | removeConnectionEventListener(javax.resource.spi.ConnectionEventListener l)Remove a connection event listener.
listeners.removeElement(l);
|
protected void | removeHandle(JmsSession handle)Remove a handle from the handle map.
handles.remove(handle);
|
protected void | sendEvent(javax.resource.spi.ConnectionEvent event)Send an event.
int type = event.getId();
if (log.isTraceEnabled())
log.trace("Sending connection event: " + type);
// convert to an array to avoid concurrent modification exceptions
ConnectionEventListener[] list =
(ConnectionEventListener[])listeners.toArray(new ConnectionEventListener[listeners.size()]);
for (int i=0; i<list.length; i++)
{
switch (type) {
case ConnectionEvent.CONNECTION_CLOSED:
list[i].connectionClosed(event);
break;
case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
list[i].localTransactionStarted(event);
break;
case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
list[i].localTransactionCommitted(event);
break;
case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
list[i].localTransactionRolledback(event);
break;
case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
list[i].connectionErrorOccurred(event);
break;
default:
throw new IllegalArgumentException("Illegal eventType: " + type);
}
}
|
public void | setLogWriter(java.io.PrintWriter out)Set the log writer for this connection.
//
// jason: screw the logWriter stuff for now it sucks ass
//
|
private void | setup()Setup the connection.
boolean trace = log.isTraceEnabled();
try
{
JMSProviderAdapter adapter = getProviderAdapter();
Context context = adapter.getInitialContext();
Object factory;
boolean transacted = info.isTransacted();
int ack = Session.AUTO_ACKNOWLEDGE;
if (info.getType() == JmsConnectionFactory.TOPIC)
{
String jndi = adapter.getTopicFactoryRef();
if (jndi == null)
throw new IllegalStateException("No configured 'TopicFactoryRef' on the jms provider " + mcf.getJmsProviderAdapterJNDI());
factory = context.lookup(jndi);
con = ConnectionFactoryHelper.createTopicConnection(factory, user, pwd);
if (info.getClientID() != null)
con.setClientID(info.getClientID());
con.setExceptionListener(this);
if (trace)
log.trace("created connection: " + con);
if (con instanceof XATopicConnection)
{
xaTopicSession = ((XATopicConnection)con).createXATopicSession();
topicSession = xaTopicSession.getTopicSession();
xaTransacted = true;
}
else if (con instanceof TopicConnection)
{
topicSession =
((TopicConnection)con).createTopicSession(transacted, ack);
if (trace)
log.trace("Using a non-XA TopicConnection. " +
"It will not be able to participate in a Global UOW");
}
else
throw new JBossResourceException("Connection was not recognizable: " + con);
if (trace)
log.trace("xaTopicSession=" + xaTopicSession + ", topicSession=" + topicSession);
}
else if (info.getType() == JmsConnectionFactory.QUEUE)
{
String jndi = adapter.getQueueFactoryRef();
if (jndi == null)
throw new IllegalStateException("No configured 'QueueFactoryRef' on the jms provider " + mcf.getJmsProviderAdapterJNDI());
factory = context.lookup(jndi);
con = ConnectionFactoryHelper.createQueueConnection(factory, user, pwd);
if (info.getClientID() != null)
con.setClientID(info.getClientID());
con.setExceptionListener(this);
if (trace)
log.debug("created connection: " + con);
if (con instanceof XAQueueConnection)
{
xaQueueSession =
((XAQueueConnection)con).createXAQueueSession();
queueSession = xaQueueSession.getQueueSession();
xaTransacted = true;
}
else if (con instanceof QueueConnection)
{
queueSession =
((QueueConnection)con).createQueueSession(transacted, ack);
if (trace)
log.trace("Using a non-XA QueueConnection. " +
"It will not be able to participate in a Global UOW");
}
else
throw new JBossResourceException("Connection was not reconizable: " + con);
if (trace)
log.trace("xaQueueSession=" + xaQueueSession + ", queueSession=" + queueSession);
}
else
{
String jndi = adapter.getFactoryRef();
if (jndi == null)
throw new IllegalStateException("No configured 'FactoryRef' on the jms provider " + mcf.getJmsProviderAdapterJNDI());
factory = context.lookup(jndi);
con = ConnectionFactoryHelper.createConnection(factory, user, pwd);
if (info.getClientID() != null)
con.setClientID(info.getClientID());
con.setExceptionListener(this);
if (trace)
log.trace("created connection: " + con);
if (con instanceof XAConnection)
{
xaSession =
((XAConnection)con).createXASession();
session = xaSession.getSession();
xaTransacted = true;
}
else
{
session = con.createSession(transacted, ack);
if (trace)
log.trace("Using a non-XA Connection. " +
"It will not be able to participate in a Global UOW");
}
if (trace)
log.debug("xaSession=" + xaQueueSession + ", Session=" + session);
}
if (trace)
log.debug("transacted=" + transacted + ", ack=" + ack);
}
catch (NamingException e)
{
throw new JBossResourceException("Unable to setup connection", e);
}
catch (JMSException e)
{
throw new JBossResourceException("Unable to setup connection", e);
}
|
void | start()
con.start();
|
void | stop()
con.stop();
|