Search in sources :

Example 46 with TransactionUID

use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.

the class JMSServiceImpl method commitTransaction.

/**
 * Commit a transaction.
 *
 * @param connectionId The Id of the connection
 * @param transactionId If non-zero, the transaction being committed is identified by this broker-generated id
 * @param xid If transactionId is zero, then xid contains the Xid of the XA transaction being committed
 * @param flags If this is an XA transaction, then flags is one of:
 * <UL>
 * <LI>XAResource.TMONEPHASE:One phase commit. The transaction need not be in the PREPARED state</LI>
 * <LI>XAResource.TMNOFLAGS: Two phase commit. The transaction must be in the PREPARED state</LI>
 * </UL>
 *
 * @return The JMSServiceReply of the request to commit a transaction
 *
 * @throws JMSServiceException if the Status returned for the commitTransaction method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSServiceReply.Status#getJMQTransactionID
 *
 * @see JMSServiceReply.Status#BAD_REQUEST
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#PRECONDITION_FAILED
 * @see JMSServiceReply.Status#TIMEOUT
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply commitTransaction(long connectionId, long transactionId, Xid xid, int flags) throws JMSServiceException {
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    TransactionUID txnUID = null;
    JMQXid jmqXid = null;
    Integer xaFlags;
    cxn = checkConnectionId(connectionId, "commitTransaction");
    txnUID = new TransactionUID(transactionId);
    if (xid != null) {
        jmqXid = new JMQXid(xid);
    }
    xaFlags = Integer.valueOf(flags);
    try {
        protocol.commitTransaction(txnUID, jmqXid, xaFlags, cxn);
    } catch (BrokerException be) {
        String errStr = "CommitTransaction: commit failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId;
        logger.logStack(Logger.ERROR, errStr, be);
        props.put("JMQStatus", getErrorReplyStatus(be));
        throw new JMSServiceException(errStr, be, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQTransactionID", txnUID.longValue());
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Example 47 with TransactionUID

use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.

the class JMSServiceImpl method startTransaction.

/**
 * Start a transaction.
 *
 * @param connectionId The Id of the connection
 * @param sessionId If non-zero, this is the Id of the session in which the transaction is being created. This parameter
 * is zero for XA transactions
 * @param xid If non-null, an XA transaction is being started
 * @param flags If xId is non-null, then flags is one of:
 * <p>
 * <UL>
 * <LI>XAResource.TMNOFLAGS = start a brand new transaction</LI>
 * <LI>XAResource.TMRESUNE = resume a previously suspended transaction</LI>
 * </UL>
 * @param rollback The type of transaction rollback behavior to use
 * @param timeout The transaction timeout to use. The timeout is the maximum time in seconds that the transaction will
 * be allowed to be in an un-prepared state.
 *
 * @return The JMSServiceReply of the request to start a transaction
 *
 * @throws JMSServiceException if the Status returned for the startTransaction method is not
 * {@link JMSServiceReply.Status#OK}
 */
@Override
public JMSServiceReply startTransaction(long connectionId, long sessionId, Xid xid, int flags, JMSService.TransactionAutoRollback rollback, long timeout) throws JMSServiceException {
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    TransactionUID txnUID = null;
    JMQXid jmqXid = null;
    Integer xaFlags = null;
    cxn = checkConnectionId(connectionId, "startTransaction");
    if (xid != null) {
        jmqXid = new JMQXid(xid);
        xaFlags = Integer.valueOf(flags);
    }
    try {
        txnUID = protocol.startTransaction(jmqXid, xaFlags, null, /* type */
        timeout, cxn);
    } catch (BrokerException be) {
        String errStr = "startTransaction: start transaction failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", XID: " + xid;
        logger.logStack(Logger.ERROR, errStr, be);
        props.put("JMQStatus", getErrorReplyStatus(be));
        throw new JMSServiceException(errStr, be, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQTransactionID", txnUID.longValue());
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Example 48 with TransactionUID

use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.

the class IMQConnection method cleanUpTransactions.

private synchronized void cleanUpTransactions() {
    logger.log(Logger.DEBUG, "Cleaning up transactions on connection " + this);
    List conlist = (List) getClientData(TRANSACTION_LIST);
    if (conlist != null) {
        boolean xaretainall = Globals.getConfig().getBooleanProperty(TransactionList.XA_TXN_DETACHED_RETAINALL_PROP, false);
        ArrayList timeoutTIDs = new ArrayList();
        TransactionUID tid = null;
        boolean xaretainallLogged = false;
        TransactionHandler rollbackHandler = (TransactionHandler) Globals.getPacketRouter(0).getHandler(PacketType.ROLLBACK_TRANSACTION);
        TransactionList[] tls = Globals.getDestinationList().getTransactionList(pstore);
        TransactionList tl = tls[0];
        TransactionUID[] tuids = (TransactionUID[]) conlist.toArray(new TransactionUID[conlist.size()]);
        for (int i = 0; i < tuids.length; i++) {
            tid = tuids[i];
            TransactionState ts = tl.retrieveState(tid);
            if (ts == null) {
                // nothing to do if no transaction state
                continue;
            }
            int tstate = ts.getState();
            if (tstate == TransactionState.PREPARED && ts.getOnephasePrepare()) {
                ts.detachedFromConnection();
                timeoutTIDs.add(tid);
                String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate) + "[onephase=true]", getConnectionUID().toString() };
                logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                continue;
            }
            if (ts.getXid() != null) {
                if (xaretainall) {
                    if (!xaretainallLogged) {
                        logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_RETAIN_XA));
                        xaretainallLogged = true;
                    }
                    continue;
                }
                if (tstate > TransactionState.COMPLETE) {
                    String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate), getConnectionUID().toString() };
                    logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                    continue;
                }
                if (tstate == TransactionState.INCOMPLETE || tstate == TransactionState.COMPLETE) {
                    ts.detachedFromConnection();
                    timeoutTIDs.add(tid);
                    String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate), getConnectionUID().toString() };
                    logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                    continue;
                }
            }
            if (tstate == TransactionState.PREPARED || tstate == TransactionState.COMMITTED || tstate == TransactionState.ROLLEDBACK) {
                String[] args = { "" + tid, TransactionState.toString(tstate), getConnectionUID().toString() };
                logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                continue;
            }
            if (DEBUG || DEBUG_TXN) {
                logger.log(Logger.INFO, "Cleanup connection [" + getConnectionUID() + "]: cleaning up transaction " + tid + "[" + TransactionState.toString(tstate) + "]");
            }
            try {
                rollbackHandler.doRollback(tl, tid, ts.getXid(), null, ts, conlist, null, RollbackReason.CONNECTION_CLEANUP);
            } catch (Exception e) {
                String[] args = { "" + tid + "[" + TransactionState.toString(tstate) + "]", getConnectionUID().toString(), e.getMessage() };
                logger.logStack(logger.WARNING, Globals.getBrokerResources().getString(BrokerResources.W_CONN_CLEANUP_ROLLBACK_TRAN_FAIL, args), e);
            }
        }
        Iterator itr = timeoutTIDs.iterator();
        while (itr.hasNext()) {
            tid = (TransactionUID) itr.next();
            tl.addDetachedTransactionID(tid);
        }
        timeoutTIDs.clear();
        conlist.clear();
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 49 with TransactionUID

use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.

the class BrokerConsumers method getDebugState.

public Hashtable getDebugState() {
    Hashtable ht = new Hashtable();
    ArrayList l = null;
    synchronized (deliveredMessages) {
        l = new ArrayList(deliveredMessages.values());
    }
    ht.put("CLUSTER_ROUTER:deliveredMessagesCount", l.size());
    Iterator itr = l.iterator();
    while (itr.hasNext()) {
        AckEntry e = (AckEntry) itr.next();
        SysMessageID id = e.getSysMessageID();
        ht.put("[deliveredMessages]" + id.toString(), e.toString());
    }
    synchronized (consumers) {
        l = new ArrayList(consumers.keySet());
    }
    ht.put("consumersCount", l.size());
    itr = l.iterator();
    while (itr.hasNext()) {
        ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
        Consumer c = (Consumer) consumers.get(cuid);
        if (c instanceof Subscription) {
            ht.put("[consumers]" + cuid.toString(), "Subscription: " + c);
        } else {
            ht.put("[consumers]" + cuid.toString(), c.toString());
        }
    }
    synchronized (activeConsumers) {
        l = new ArrayList(activeConsumers);
    }
    ht.put("activeConsumersCount", l.size());
    Vector v = new Vector();
    itr = l.iterator();
    while (itr.hasNext()) {
        Consumer c = (Consumer) itr.next();
        if (c instanceof Subscription) {
            v.add("Subscription: " + c);
        } else {
            v.add(c.toString());
        }
    }
    ht.put("activeConsumers", v);
    synchronized (pendingConsumerUIDs) {
        l = new ArrayList(pendingConsumerUIDs.keySet());
    }
    ht.put("pendingConsumerUIDsCount", l.size());
    itr = l.iterator();
    while (itr.hasNext()) {
        ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
        Map<TransactionUID, Set<AckEntry>> pending0, pending = null;
        synchronized (deliveredMessages) {
            pending0 = pendingConsumerUIDs.get(cuid);
            if (pending0 != null) {
                pending = new LinkedHashMap<>(pending0);
            }
        }
        if (pending == null) {
            ht.put("[pendingConsumerUIDs]" + cuid.toString(), "null");
        } else {
            Hashtable htt = new Hashtable();
            Map.Entry<TransactionUID, Set<AckEntry>> pair = null;
            TransactionUID key = null;
            Iterator<Map.Entry<TransactionUID, Set<AckEntry>>> itr1 = pending.entrySet().iterator();
            while (itr1.hasNext()) {
                pair = itr1.next();
                key = pair.getKey();
                htt.put("PENDING-TID:" + (key == null ? "null" : key), new Vector(pair.getValue()));
            }
            ht.put("[pendingConsumerUIDs]" + cuid.toString(), htt);
        }
    }
    synchronized (cleanupList) {
        l = new ArrayList(cleanupList.keySet());
    }
    ht.put("cleanupListCount", l.size());
    v = new Vector();
    itr = l.iterator();
    while (itr.hasNext()) {
        ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
        v.add(cuid.toString());
    }
    ht.put("cleanupList", v);
    synchronized (listeners) {
        l = new ArrayList(listeners.keySet());
    }
    ht.put("listenersCount", l.size());
    v = new Vector();
    itr = l.iterator();
    while (itr.hasNext()) {
        ConsumerUID cuid = (com.sun.messaging.jmq.jmsserver.core.ConsumerUID) itr.next();
        v.add(cuid.toString());
    }
    ht.put("listeners", v);
    return ht;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Iterator(java.util.Iterator) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) Vector(java.util.Vector) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 50 with TransactionUID

use of com.sun.messaging.jmq.jmsserver.data.TransactionUID in project openmq by eclipse-ee4j.

the class BrokerConsumers method getPendingConsumerUID.

private List<AckEntry> getPendingConsumerUID(TransactionUID tid) {
    assert Thread.holdsLock(deliveredMessages);
    Set<Map<TransactionUID, Set<AckEntry>>> maps = null;
    synchronized (pendingConsumerUIDs) {
        maps = new LinkedHashSet<>(pendingConsumerUIDs.values());
    }
    Map<TransactionUID, Set<AckEntry>> map = null;
    Iterator<Map<TransactionUID, Set<AckEntry>>> itr = maps.iterator();
    while (itr.hasNext()) {
        map = itr.next();
        if (map == null) {
            continue;
        }
        TransactionUID mytid = null;
        Map.Entry<TransactionUID, Set<AckEntry>> pair = null;
        Iterator<Map.Entry<TransactionUID, Set<AckEntry>>> itr1 = map.entrySet().iterator();
        while (itr1.hasNext()) {
            pair = itr1.next();
            mytid = pair.getKey();
            if (mytid == null || !mytid.equals(tid)) {
                continue;
            }
            return new ArrayList<>(pair.getValue());
        }
    }
    return new ArrayList<>();
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)71 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)23 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)22 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)19 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)18 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)15 JMQXid (com.sun.messaging.jmq.util.JMQXid)13 IOException (java.io.IOException)13 HashMap (java.util.HashMap)12 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)10 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)10 ArrayList (java.util.ArrayList)10 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)8 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)7 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)7 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)7 Iterator (java.util.Iterator)7 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)6