use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class SessionOp method detachConsumer.
/**
* @param id last SysMessageID seen (null indicates all have been seen)
* @param redeliverAll ignore id and redeliver all
* @param redeliverPendingConsume - redeliver pending messages
*/
@Override
public boolean detachConsumer(ConsumerSpi c, SysMessageID id, boolean idInTransaction, boolean redeliverPendingConsume, boolean redeliverAll, Connection conn) {
if (Session.DEBUG || Session.DEBUG_CLUSTER_MSG) {
logger.log(logger.INFO, "detachConsumer(" + c + ", " + id + ", " + redeliverPendingConsume + ", " + redeliverAll + ", " + conn.getConnectionUID() + ")");
}
Consumer con = (Consumer) c;
ConsumerUID cuid = con.getConsumerUID();
ConsumerUID suid = con.getStoredConsumerUID();
// OK, we have 2 sets of messages:
// messages which were seen (and need the state
// set to consumed)
// messages which were NOT seen (and need the
// state reset)
// get delivered messages
Set s = new LinkedHashSet();
HashMap remotePendings = new HashMap();
boolean holdmsgs = false;
TransactionList[] tls = DL.getTransactionList(((IMQConnection) conn).getPartitionedStore());
TransactionList translist = tls[0];
TransactionUID tid = null;
// get all the messages for the consumer
synchronized (deliveredMessages) {
ackEntry startEntry = null;
// workaround for client sending ack if acknowledged
if (id != null) {
ackEntry entry = new ackEntry(id, cuid);
startEntry = (ackEntry) deliveredMessages.get(entry);
}
// make a copy of all of the data
cleanupList.put(cuid, con.getParentList());
storeMap.put(cuid, con.getStoredConsumerUID());
// OK first loop through all of the consumed
// messages and mark them consumed
Iterator itr = deliveredMessages.values().iterator();
boolean found = (startEntry == null && id != null);
while (!redeliverAll && !found && itr.hasNext()) {
ackEntry val = (ackEntry) itr.next();
if (val == startEntry) {
// we are done with consumed messages
found = true;
}
// forward port 6829773
if (!val.storedcid.equals(suid) || !val.uid.equals(cuid)) {
continue;
}
PacketReference pr = val.getReference();
tid = null;
if (session.isTransacted() || idInTransaction) {
tid = translist.getConsumedInTransaction(val.getSysMessageID(), val.uid);
if (tid == null) {
if (pr != null) {
pr.removeInDelivery(suid);
s.add(pr);
addRemotePendings(pr, val.storedcid, new TransactionUID(0), remotePendings);
}
itr.remove();
continue;
}
}
// we know the consumer saw it .. mark it consumed
if (pr != null) {
try {
pr.consumed(suid, !session.isUnsafeAck(cuid), session.isAutoAck(cuid));
val.markConsumed();
} catch (Exception ex) {
Object[] args = { "[" + pr + "," + suid + "]", cuid, ex.getMessage() };
logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_UNABLE_UPDATE_REF_STATE_ON_CLOSE_CONSUMER, args), ex);
}
}
if (redeliverPendingConsume) {
if (pr != null) {
pr.removeInDelivery(suid);
s.add(pr);
}
itr.remove();
continue;
}
if (pr != null && !pr.isLocal() && session.isValid()) {
if (addRemotePendings(pr, val.storedcid, tid, remotePendings)) {
detachedRConsumerUIDs.add(val.uid);
}
}
holdmsgs = true;
}
// now deal with re-queueing messages
while (itr.hasNext()) {
ackEntry val = (ackEntry) itr.next();
// see if we are for a different consumer
if (!val.storedcid.equals(suid) || !val.uid.equals(cuid)) {
continue;
}
PacketReference pr = val.getReference();
if (session.isTransacted()) {
tid = translist.getConsumedInTransaction(val.getSysMessageID(), val.uid);
if (tid != null) {
if (pr != null && !pr.isLocal() && session.isValid()) {
if (addRemotePendings(pr, val.storedcid, tid, remotePendings)) {
detachedRConsumerUIDs.add(val.uid);
}
}
holdmsgs = true;
continue;
}
}
if (pr != null) {
pr.removeInDelivery(suid);
s.add(pr);
}
itr.remove();
try {
if (pr != null) {
pr.removeDelivered(suid, false);
}
} catch (Exception ex) {
logger.log(Logger.WARNING, "Unable to consume " + suid + ":" + pr, ex);
}
}
}
con.destroyConsumer(s, remotePendings, (con.tobeRecreated() || (!session.isValid() && !session.isXATransacted())), false, true);
if (!holdmsgs && session.isValid()) {
synchronized (deliveredMessages) {
cleanupList.remove(cuid);
storeMap.remove(cuid);
}
return true;
}
return false;
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class Destination method txnSize.
public int txnSize(Set<PacketReference> msgset, DestinationInfo dinfo) {
Set<PacketReference> msgs = msgset;
if (msgs == null) {
synchronized (destMessages) {
msgs = new HashSet<>(destMessages.values());
}
}
Iterator<PacketReference> itr = msgs.iterator();
int cnt = 0;
TransactionList tl = DL.getTransactionList();
while (itr.hasNext()) {
PacketReference ref = itr.next();
TransactionUID tid = ref.getTransactionID();
if (tid == null) {
continue;
}
TransactionState ts = tl.retrieveState(tid, true);
if (ts == null || ts.getState() == TransactionState.COMMITTED) {
continue;
}
cnt++;
if (dinfo != null) {
dinfo.nTxnMessages++;
dinfo.nTxnMessageBytes += ref.getSize();
}
}
return cnt;
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class TransactionUtil method getTransactionIDs.
public static String[] getTransactionIDs() {
TransactionList[] tls = Globals.getDestinationList().getTransactionList(null);
// PART
TransactionList tl = tls[0];
Vector transactions = tl.getTransactions(-1);
String[] ids;
if ((transactions == null) || (transactions.size() == 0)) {
return (null);
}
ids = new String[transactions.size()];
Enumeration e = transactions.elements();
int i = 0;
while (e.hasMoreElements()) {
TransactionUID tid = (TransactionUID) e.nextElement();
long txnID = tid.longValue();
ids[i] = Long.toString(txnID);
i++;
}
return (ids);
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class TransactionUtil method getXID.
public static String getXID(TransactionUID tid) {
TransactionList[] tls = Globals.getDestinationList().getTransactionList(null);
TransactionList tl = tls[0];
JMQXid xid;
if (tl == null) {
return (null);
}
xid = tl.UIDToXid(tid);
if (xid == null) {
return (null);
}
return (xid.toString());
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionList in project openmq by eclipse-ee4j.
the class TransactionUtil method getState.
public static Integer getState(TransactionUID tid) {
TransactionList[] tls = Globals.getDestinationList().getTransactionList(null);
// PART
TransactionList tl = tls[0];
TransactionState ts;
if (tl == null) {
return (null);
}
ts = tl.retrieveState(tid);
if (ts == null) {
return (null);
}
return (Integer.valueOf(toExternalTransactionState(ts.getState())));
}
Aggregations