Search in sources :

Example 16 with TransactionBroker

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

the class TransactionInfo method updateBrokerState.

public void updateBrokerState(TransactionBroker bkr) throws BrokerException {
    TransactionBroker txnBkr = (TransactionBroker) bkrMap.get(bkr.getBrokerAddress());
    if (txnBkr == null) {
        throw new BrokerException("TransactionBroker " + bkr + " could not be found in the store", Status.NOT_FOUND);
    }
    // Just update the state
    txnBkr.copyState(bkr);
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker)

Example 17 with TransactionBroker

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

the class TransactionInfo method setTransactionBrokers.

public void setTransactionBrokers(TransactionBroker[] bkrs) {
    if (!bkrMap.isEmpty()) {
        bkrMap.clear();
    }
    if (bkrs == null) {
        txnBkrs = null;
    } else {
        // TransactionBroker is mutable, so we must store a copy
        int size = bkrs.length;
        txnBkrs = new TransactionBroker[size];
        StringBuilder debugBuf = null;
        for (int i = 0; i < size; i++) {
            TransactionBroker txnBkr = (TransactionBroker) bkrs[i].clone();
            txnBkrs[i] = txnBkr;
            if (DEBUG) {
                if (debugBuf == null) {
                    debugBuf = new StringBuilder();
                }
                if (i > 0) {
                    debugBuf.append(',');
                }
                debugBuf.append(txnBkr);
            }
            // Create a lookup map (BrokerAddress -> TransactionBroker)
            bkrMap.put(txnBkr.getBrokerAddress(), txnBkr);
        }
        // Verify that there are no duplicate
        if (bkrMap.size() != size) {
            String emsg = "Unexpected Error: duplicate TransactionBroker object found " + size + " size in database, mapped to size " + bkrMap.size() + (debugBuf == null ? "" : ", bkrs=" + debugBuf.toString() + ", bkrMap=" + bkrMap);
            throw new IllegalArgumentException(emsg);
        }
    }
}
Also used : TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker)

Example 18 with TransactionBroker

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

the class GetTransactionsHandler method getTransactionInfo.

private static Hashtable getTransactionInfo(TransactionList tl, TransactionUID id, int type, boolean showpartition) {
    Logger logger = Globals.getLogger();
    TransactionState ts = tl.retrieveState(id);
    if (type == LOCAL) {
        ts = tl.retrieveState(id, true);
    } else if (type == CLUSTER) {
        ts = tl.retrieveState(id, true);
    } else if (type == REMOTE) {
        ts = tl.getRemoteTransactionState(id);
    }
    if (ts == null) {
        return null;
    }
    JMQXid xid = tl.UIDToXid(id);
    Hashtable table = new Hashtable();
    table.put("type", Integer.valueOf(type));
    if (xid != null) {
        table.put("xid", xid.toString());
    }
    PartitionedStore pstore = tl.getPartitionedStore();
    table.put("txnid", Long.valueOf(id.longValue()) + (showpartition ? "[" + pstore.getPartitionID() + (pstore.isPrimaryPartition() ? "*]" : "]") : ""));
    if (ts.getUser() != null) {
        table.put("user", ts.getUser());
    }
    if (ts.getClientID() != null) {
        table.put("clientid", ts.getClientID());
    }
    table.put("timestamp", Long.valueOf(System.currentTimeMillis() - id.age()));
    table.put("connection", ts.getConnectionString());
    table.put("nmsgs", Integer.valueOf(tl.retrieveNSentMessages(id)));
    if (type != REMOTE) {
        table.put("nacks", Integer.valueOf(tl.retrieveNConsumedMessages(id)));
    } else {
        table.put("nacks", Integer.valueOf(tl.retrieveNRemoteConsumedMessages(id)));
    }
    table.put("state", Integer.valueOf(ts.getState()));
    ConnectionUID cuid = ts.getConnectionUID();
    if (cuid != null) {
        table.put("connectionid", Long.valueOf(cuid.longValue()));
    }
    TransactionBroker homeBroker = tl.getRemoteTransactionHomeBroker(id);
    String homeBrokerStr = "";
    if (homeBroker != null) {
        homeBrokerStr = homeBroker.getBrokerAddress().toString();
    }
    table.put("homebroker", homeBrokerStr);
    TransactionBroker[] brokers = null;
    if (type != REMOTE) {
        try {
            brokers = tl.getClusterTransactionBrokers(id);
        } catch (BrokerException be) {
            logger.log(Logger.WARNING, "Exception caught while obtaining list of brokers in transaction", be);
        }
    }
    StringBuilder allBrokers = new StringBuilder();
    StringBuilder pendingBrokers = new StringBuilder();
    if (brokers != null) {
        for (int i = 0; i < brokers.length; ++i) {
            TransactionBroker oneBroker = brokers[i];
            BrokerAddress addr = oneBroker.getBrokerAddress();
            if (allBrokers.length() != 0) {
                allBrokers.append(", ");
            }
            allBrokers.append(addr);
            if (oneBroker.isCompleted()) {
                continue;
            }
            if (pendingBrokers.length() != 0) {
                pendingBrokers.append(", ");
            }
            pendingBrokers.append(addr);
        }
    }
    table.put("allbrokers", allBrokers.toString());
    table.put("pendingbrokers", pendingBrokers.toString());
    return table;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) Hashtable(java.util.Hashtable) Logger(com.sun.messaging.jmq.util.log.Logger) JMQXid(com.sun.messaging.jmq.util.JMQXid) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 19 with TransactionBroker

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

the class BrokerConsumers method commitRecoveryRemoteTransaction.

private boolean commitRecoveryRemoteTransaction(TransactionList translist, TransactionUID tid, com.sun.messaging.jmq.jmsserver.core.BrokerAddress from) throws BrokerException {
    logger.log(logger.INFO, "Committing recovery remote transaction " + tid + " from " + from);
    TransactionBroker ba = translist.getRemoteTransactionHomeBroker(tid);
    BrokerAddress currba = (ba == null) ? null : ba.getCurrentBrokerAddress();
    if (currba == null || !currba.equals(from)) {
        logger.log(logger.WARNING, "Committed remote transaction " + tid + " home broker " + ba + " not " + from);
    }
    RemoteTransactionAckEntry[] tae = translist.getRecoveryRemoteTransactionAcks(tid);
    if (tae == null) {
        logger.log(logger.WARNING, "No recovery transaction acks to process for committing remote transaction " + tid);
        return true;
    }
    boolean done = true;
    for (int j = 0; j < tae.length; j++) {
        if (tae[j].processed()) {
            continue;
        }
        TransactionAcknowledgement[] tas = tae[j].getAcks();
        for (int i = 0; i < tas.length; i++) {
            SysMessageID sysid = tas[i].getSysMessageID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID uid = tas[i].getConsumerUID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID suid = tas[i].getStoredConsumerUID();
            if (suid == null) {
                suid = uid;
            }
            // PART
            PacketReference ref = DL.get(null, sysid);
            if (ref == null || ref.isDestroyed() || ref.isInvalid()) {
                continue;
            }
            try {
                if (ref.acknowledged(uid, suid, true, true)) {
                    ref.getDestination().removeMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED);
                }
            } catch (Exception ex) {
                done = false;
                logger.logStack(Logger.ERROR, Globals.getBrokerResources().E_INTERNAL_BROKER_ERROR, ex.getMessage(), ex);
            }
        }
    }
    return done;
}
Also used : TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) IOException(java.io.IOException) AckEntryNotFoundException(com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 20 with TransactionBroker

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

the class BrokerConsumers method rollbackRecoveryRemoteTransaction.

private void rollbackRecoveryRemoteTransaction(TransactionList translist, TransactionUID tid, com.sun.messaging.jmq.jmsserver.core.BrokerAddress from) throws BrokerException {
    logger.log(logger.INFO, "Rolling back recovery remote transaction " + tid + " from " + from);
    TransactionState ts = translist.getRemoteTransactionState(tid);
    if (ts == null || ts.getState() != TransactionState.ROLLEDBACK) {
        throw new BrokerException(Globals.getBrokerResources().E_INTERNAL_BROKER_ERROR, "Unexpected broker state " + ts + " for processing Rolledback remote transaction " + tid);
    }
    TransactionBroker ba = translist.getRemoteTransactionHomeBroker(tid);
    BrokerAddress currba = (ba == null) ? null : ba.getCurrentBrokerAddress();
    if (currba == null || !currba.equals(from)) {
        logger.log(logger.WARNING, "Rolledback remote transaction " + tid + " home broker " + ba + " not " + from);
    }
    RemoteTransactionAckEntry[] tae = translist.getRecoveryRemoteTransactionAcks(tid);
    if (tae == null) {
        logger.log(logger.WARNING, "No recovery transaction acks to process for rolling back remote transaction " + tid);
        return;
    }
    for (int j = 0; j < tae.length; j++) {
        if (tae[j].processed()) {
            continue;
        }
        TransactionAcknowledgement[] tas = tae[j].getAcks();
        for (int i = 0; i < tas.length; i++) {
            SysMessageID sysid = tas[i].getSysMessageID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID cuid = tas[i].getConsumerUID();
            com.sun.messaging.jmq.jmsserver.core.ConsumerUID suid = tas[i].getStoredConsumerUID();
            if (suid == null) {
                suid = cuid;
            }
            // PART
            PacketReference ref = DL.get(null, sysid);
            if (ref == null) {
                if (getDEBUG()) {
                    logger.log(logger.INFO, "[" + sysid + ":" + cuid + "] reference not found in rolling back recovery remote transaction " + tid);
                }
                continue;
            }
            ref.getDestination().forwardOrphanMessage(ref, suid);
        }
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Aggregations

TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)26 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)10 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)9 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)8 IOException (java.io.IOException)8 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)7 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)6 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)6 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)6 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)5 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)4 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)4 HandshakeInProgressException (com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException)4 TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)4 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)4 UID (com.sun.messaging.jmq.util.UID)4 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)4 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)3 BrokerDownException (com.sun.messaging.jmq.jmsserver.util.BrokerDownException)3 MaxConsecutiveRollbackException (com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException)3