Search in sources :

Example 66 with TransactionUID

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

the class RaptorProtocol method receivedTransactionInquiry.

public void receivedTransactionInquiry(GPacket pkt, BrokerAddress from) {
    ClusterTxnInquiryInfo cii = ClusterTxnInquiryInfo.newInstance(pkt);
    if (DEBUG_CLUSTER_TXN) {
        logger.log(logger.INFO, "Received transaction inquiry " + cii.toString() + " from " + from);
    }
    TransactionUID tid = new TransactionUID(cii.getTransactionID().longValue());
    BrokerAddress txnHomeBroker = cii.getTransactionHome();
    TransactionBroker thb = null;
    if (txnHomeBroker != null) {
        thb = new TransactionBroker(txnHomeBroker);
    }
    Object[] oo = TransactionList.getTransListAndState(tid, null, true, false);
    TransactionState ts = null;
    if (oo != null) {
        // tl = (TransactionList)oo[0];
        ts = (TransactionState) oo[1];
    }
    if (ts == null && DEBUG_CLUSTER_TXN) {
        logger.log(logger.INFO, "Transaction " + tid + " not found in local transactions");
    }
    if (ts != null) {
        BrokerAddress currba = (thb == null ? null : thb.getCurrentBrokerAddress());
        if (currba != null && !currba.equals(Globals.getMyAddress())) {
            logger.log(logger.INFO, "Transaction " + tid + " home broker current address " + currba + ", old address " + txnHomeBroker + " inquired from " + from);
        }
        sendClusterTransactionInfo(tid, from, cii.getXid());
        return;
    }
    if (thb != null) {
        BrokerAddress currba = thb.getCurrentBrokerAddress();
        if (currba != null && Globals.getMyAddress().equals(currba)) {
            sendClusterTransactionInfo(tid, from, cii.getXid());
            return;
        }
    }
    sendRemoteTransactionInfo(tid, from, cii.getXid(), false);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker)

Example 67 with TransactionUID

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

the class BaseTransactionManager method writePreparedTransactionsToPreparedTxnStoreOnCheckpoint.

// on checkpoint, we need to store any newly logged prepared transactions to the preparedTxnStore
// as the transaction log is about to be reset
void writePreparedTransactionsToPreparedTxnStoreOnCheckpoint() throws BrokerException {
    if (Store.getDEBUG()) {
        String msg = getPrefix() + " writePreparedTransactionsToPreparedTxnStoreOnCheckpoint" + " num incompleteUnstored=" + incompleteUnstored.size();
        logger.log(Logger.DEBUG, msg);
    }
    ArrayList<TransactionUID> incmps = null;
    synchronized (incompleteUnstored) {
        incmps = new ArrayList<>(incompleteUnstored.keySet());
    }
    TransactionUID tid = null;
    BaseTransaction baseTxn = null;
    Iterator<TransactionUID> iter = incmps.iterator();
    while (iter.hasNext()) {
        tid = iter.next();
        if (!preparedTxnStore.containsTransaction(tid)) {
            baseTxn = incompleteUnstored.get(tid);
            if (baseTxn == null) {
                continue;
            }
            if (Store.getDEBUG()) {
                String msg = getPrefix() + " transaction storing preparedTransaction " + baseTxn;
                logger.log(Logger.DEBUG, msg);
            }
            try {
                preparedTxnStore.storeTransaction(baseTxn, true);
                addToIncompleteStored(baseTxn);
            } catch (IOException ioe) {
                throw new BrokerException("failed to store transaction in preparedTxnStore " + baseTxn, ioe);
            }
        } else {
            String msg = getPrefix() + " transaction already exists in preparedTxnStore " + tid + "[" + incompleteUnstored.get(tid) + "]";
            logger.log(Logger.INFO, msg);
        }
    }
    incompleteUnstored.clear();
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) IOException(java.io.IOException)

Example 68 with TransactionUID

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

the class TransactionManagerConfig method getTransactionIDs.

public String[] getTransactionIDs() throws MBeanException {
    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();
        String id;
        try {
            id = Long.toString(txnID);
            ids[i] = id;
        } catch (Exception ex) {
            handleOperationException(TransactionOperations.GET_TRANSACTION_IDS, ex);
        }
        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) MBeanException(javax.management.MBeanException)

Example 69 with TransactionUID

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

the class TransactionManagerConfig method doRollbackCommit.

public void doRollbackCommit(String transactionID, boolean rollback) throws MBeanException {
    try {
        long longTid = 0;
        if (transactionID == null) {
            throw new Exception("Null transaction ID");
        }
        try {
            longTid = Long.parseLong(transactionID);
        } catch (Exception e) {
            throw new Exception("Invalid transaction ID: " + transactionID);
        }
        TransactionUID tid = new TransactionUID(longTid);
        TransactionList[] tls = Globals.getDestinationList().getTransactionList(null);
        TransactionList tl = null;
        TransactionState ts = null;
        for (int i = 0; i < tls.length; i++) {
            tl = tls[i];
            if (tl == null) {
                continue;
            }
            ts = tl.retrieveState(tid);
            if (ts == null) {
                continue;
            }
            break;
        }
        if (ts == null) {
            throw new Exception(rb.getString(rb.E_NO_SUCH_TRANSACTION, tid));
        }
        if (ts.getState() != TransactionState.PREPARED) {
            throw new Exception(rb.getString(rb.E_TRANSACTION_NOT_PREPARED, tid));
        }
        JMQXid xid = tl.UIDToXid(tid);
        if (xid == null) {
            throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not find Xid for " + tid));
        }
        PacketRouter pr = Globals.getPacketRouter(0);
        if (pr == null) {
            throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not locate Packet Router"));
        }
        TransactionHandler thandler = (TransactionHandler) pr.getHandler(PacketType.ROLLBACK_TRANSACTION);
        if (thandler == null) {
            throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not locate Transaction Handler"));
        }
        if (rollback) {
            thandler.doRollback(tl, tid, xid, null, ts, null, null, RollbackReason.ADMIN);
        } else {
            thandler.doCommit(tl, tid, xid, Integer.valueOf(XAResource.TMNOFLAGS), ts, null, false, null, null);
        }
    } catch (Exception e) {
        String opName;
        if (rollback) {
            opName = TransactionOperations.ROLLBACK;
        } else {
            opName = TransactionOperations.COMMIT;
        }
        handleOperationException(opName, e);
    }
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) PacketRouter(com.sun.messaging.jmq.jmsserver.data.PacketRouter) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) JMQXid(com.sun.messaging.jmq.util.JMQXid) MBeanException(javax.management.MBeanException)

Example 70 with TransactionUID

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

the class Destination method txnByteSize.

public long txnByteSize(Set<PacketReference> msgset) {
    Set<PacketReference> msgs = msgset;
    if (msgs == null) {
        synchronized (destMessages) {
            msgs = new HashSet<>(destMessages.values());
        }
    }
    Iterator<PacketReference> itr = msgs.iterator();
    long sz = 0L;
    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;
        }
        sz += ref.getSize();
    }
    return sz;
}
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)

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