Search in sources :

Example 11 with TransactionList

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) Iterator(java.util.Iterator)

Example 12 with TransactionList

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;
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 13 with TransactionList

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);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) Enumeration(java.util.Enumeration) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) Vector(java.util.Vector)

Example 14 with TransactionList

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());
}
Also used : TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Example 15 with TransactionList

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())));
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Aggregations

TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)48 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)25 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)23 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)23 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)9 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)9 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)8 TransactionHandler (com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)8 List (java.util.List)8 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)7 IOException (java.io.IOException)7 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)6 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)6 JMQXid (com.sun.messaging.jmq.util.JMQXid)6 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)6 Iterator (java.util.Iterator)6 Map (java.util.Map)6 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)5