make absolutely sure that a session is always removed from the connection even if there is a failure while closing

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@451323 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-09-29 15:10:28 +00:00
parent 3c441d03ae
commit 72491912ad
2 changed files with 28 additions and 26 deletions

View File

@ -165,8 +165,6 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
* Construct an <code>ActiveMQConnection</code>
* @param transport
* @param factoryStats
* @param userName
* @param password
* @throws Exception
*/
protected ActiveMQConnection(final Transport transport, IdGenerator clientIdGenerator, JMSStatsImpl factoryStats)

View File

@ -535,32 +535,36 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta
synchronized public void dispose() throws JMSException {
if (!closed) {
executor.stop();
for (Iterator iter = consumers.iterator(); iter.hasNext();) {
ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) iter.next();
consumer.dispose();
}
consumers.clear();
for (Iterator iter = producers.iterator(); iter.hasNext();) {
ActiveMQMessageProducer producer = (ActiveMQMessageProducer) iter.next();
producer.dispose();
}
producers.clear();
try {
if (getTransactionContext().isInLocalTransaction()) {
rollback();
executor.stop();
for (Iterator iter = consumers.iterator(); iter.hasNext();) {
ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) iter.next();
consumer.dispose();
}
} catch (JMSException e) {
consumers.clear();
for (Iterator iter = producers.iterator(); iter.hasNext();) {
ActiveMQMessageProducer producer = (ActiveMQMessageProducer) iter.next();
producer.dispose();
}
producers.clear();
try {
if (getTransactionContext().isInLocalTransaction()) {
rollback();
}
}
catch (JMSException e) {
}
}
finally {
connection.removeSession(this);
this.transactionContext = null;
closed = true;
}
connection.removeSession(this);
this.transactionContext=null;
closed = true;
}
}