if (session != null && endpoint != null) // endpoint can be null in some programmatic tests only in fact
{
Transaction muleTx = TransactionCoordination.getInstance().getTransaction();
final JmsConnector connector = (JmsConnector) endpoint.getConnector();
if (muleTx == null)
{
if (logger.isDebugEnabled())
{
logger.debug("Closing non-transacted jms session: " + session);
}
connector.closeQuietly(session);
}
else if (!muleTx.hasResource(connector.getConnection()))
{
// this is some other session from another connection, don't let it leak
if (logger.isDebugEnabled())
{
logger.debug("Closing an orphaned, but transacted jms session: " + session +
", transaction: " + muleTx);
}
connector.closeQuietly(session);
}
}
// aggressively killing any session refs
session = null;
}