if (!valid) return;
valid = false;
}
logger.log(Logger.DEBUG,"Close Session " + uid);
Connection conn = Globals.getConnectionManager().getConnection(getConnectionUID());
boolean old = false;
if (conn != null && conn.getClientProtocolVersion() < Connection.RAPTOR_PROTOCOL) {
old =true;
}
Iterator itr = null;
synchronized (this) {
itr = new HashSet(consumers.values()).iterator();
}
while (itr.hasNext()) {
Consumer c =(Consumer)itr.next();
itr.remove();
detatchConsumer(c, null, old, false);
}
// deal w/ old messages
synchronized(deliveredMessages) {
if (!deliveredMessages.isEmpty()) {
// get the list by IDs
HashMap openMsgs = new HashMap();
itr = deliveredMessages.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry)itr.next();
ackEntry e = (ackEntry)entry.getValue();
ConsumerUID cuid = e.getConsumerUID();
ConsumerUID storeduid = (e.getStoredUID() == null ? cuid:e.getStoredUID());
// deal w/ orphan messages
TransactionUID tid = e.getTUID();
if (tid != null) {
JMQXid jmqxid = Globals.getTransactionList().UIDToXid(tid);
if (jmqxid != null) {
Globals.getTransactionList().addOrphanAck(
tid, e.getSysMessageID(), storeduid, cuid);
itr.remove();
continue;
}
TransactionState ts = Globals.getTransactionList().retrieveState(tid, true);
if (ts != null && ts.getState() == TransactionState.PREPARED) {
Globals.getTransactionList().addOrphanAck(
tid, e.getSysMessageID(), storeduid, cuid);
itr.remove();
continue;
}
if (ts != null && ts.getState() == TransactionState.COMMITTED) {
itr.remove();
continue;
}
if (ts != null && conn != null &&
ts.getState() == TransactionState.COMPLETE &&
conn.getConnectionState() >= Connection.STATE_CLOSED) {
String[] args = { ""+tid,
TransactionState.toString(ts.getState()),
getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(
BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));