Search in sources :

Example 1 with TransactionWorkMessage

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

the class TransactionHandler method calculateStoredRouting.

private boolean calculateStoredRouting(PartitionedStore pstore, BaseTransaction baseTxn) throws BrokerException {
    boolean sentMessagesNeedLogging = false;
    // only need to log if message is persistent
    TransactionWork txnWork = baseTxn.getTransactionWork();
    List<TransactionWorkMessage> sentMessages = txnWork.getSentMessages();
    if (sentMessages != null) {
        Iterator<TransactionWorkMessage> iter = sentMessages.iterator();
        while (iter.hasNext()) {
            TransactionWorkMessage twm = iter.next();
            sentMessagesNeedLogging |= calculateStoredRouting(pstore, twm);
        }
    }
    boolean ackedMessagesNeedLogging = false;
    List<TransactionWorkMessageAck> ackedMessages = txnWork.getMessageAcknowledgments();
    if (ackedMessages != null) {
        Iterator<TransactionWorkMessageAck> ackIter = ackedMessages.iterator();
        while (ackIter.hasNext()) {
            ackIter.next();
            // TODO, check if ack needs logging
            ackedMessagesNeedLogging |= true;
        }
    }
    return ackedMessagesNeedLogging || sentMessagesNeedLogging;
}
Also used : TransactionWorkMessage(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessage) TransactionWork(com.sun.messaging.jmq.jmsserver.data.TransactionWork) TransactionWorkMessageAck(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessageAck)

Example 2 with TransactionWorkMessage

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

the class TransactionLogReplayer method replaySentMessages.

private void replaySentMessages(List<TransactionWorkMessage> sentMessages, Set dstLoadedSet) throws IOException, BrokerException {
    if (Store.getDEBUG()) {
        logger.log(Logger.INFO, getPrefix() + " replaySentMessages");
    }
    for (int i = 0; i < sentMessages.size(); i++) {
        TransactionWorkMessage workMessage = sentMessages.get(i);
        replaySentMessage(workMessage, dstLoadedSet);
    }
}
Also used : TransactionWorkMessage(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessage)

Example 3 with TransactionWorkMessage

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

the class LoggedMessageHelper method messageListLogged.

void messageListLogged(List<TransactionWorkMessage> twms) {
    Iterator<TransactionWorkMessage> iter = twms.iterator();
    while (iter.hasNext()) {
        TransactionWorkMessage twm = iter.next();
        messageLogged(twm);
    }
}
Also used : TransactionWorkMessage(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessage)

Example 4 with TransactionWorkMessage

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

the class JDBCStore method updateTransactionStateWithWorkInternal.

public void updateTransactionStateWithWorkInternal(TransactionUID tid, TransactionState ts, TransactionWork txnwork, long storeSessionID, boolean sync) throws BrokerException {
    if (tid == null || ts == null || txnwork == null) {
        throw new NullPointerException();
    }
    if (DEBUG) {
        logger.log(Logger.INFO, "JDBCStore.updateTransactionStateInternal(" + tid + ", " + ts + ", " + ", " + txnwork + ", " + sync + ")");
    }
    Connection conn = null;
    Exception myex = null;
    try {
        conn = dbmgr.getConnection(false);
        Util.RetryStrategy retry = null;
        do {
            boolean inside = false;
            try {
                Iterator<TransactionWorkMessage> itr1 = txnwork.getSentMessages().iterator();
                while (itr1.hasNext()) {
                    TransactionWorkMessage txnmsg = itr1.next();
                    Packet m = txnmsg.getMessage();
                    if (m == null) {
                        continue;
                    }
                    inside = true;
                    daoFactory.getMessageDAO().insert(conn, txnmsg.getDestUID(), m, null, null, storeSessionID, m.getTimestamp(), true, false);
                    inside = false;
                }
                if (FI.FAULT_INJECTION) {
                    try {
                        FI.checkFaultAndThrowBrokerException(FaultInjection.FAULT_TXN_PERSIST_WORK_1_5, null);
                    } catch (BrokerException e) {
                        FI.unsetFault(FI.FAULT_TXN_PERSIST_WORK_1_5);
                        throw e;
                    }
                }
                List<TransactionWorkMessageAck> txnacks = txnwork.getMessageAcknowledgments();
                if (txnacks != null) {
                    Iterator<TransactionWorkMessageAck> itr2 = txnacks.iterator();
                    while (itr2.hasNext()) {
                        TransactionWorkMessageAck txnack = itr2.next();
                        TransactionAcknowledgement ta = txnack.getTransactionAcknowledgement();
                        if (ta != null) {
                            inside = true;
                            daoFactory.getConsumerStateDAO().updateTransaction(conn, ta.getSysMessageID(), ta.getStoredConsumerUID(), tid);
                            inside = false;
                        }
                    }
                }
                inside = true;
                daoFactory.getTransactionDAO().updateTransactionState(conn, tid, ts, false);
                inside = false;
                conn.commit();
                return;
            } catch (Exception e) {
                if (!inside) {
                    try {
                        conn.rollback();
                    } catch (SQLException rbe) {
                        logger.logStack(Logger.WARNING, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
                    }
                }
                if (retry == null) {
                    retry = new Util.RetryStrategy();
                }
                try {
                    retry.assertShouldRetry(e, conn);
                } catch (RetrySQLRecoverableException ee) {
                    try {
                        Util.close(null, null, conn, ee);
                        conn = dbmgr.getConnection(false);
                    } catch (Exception eee) {
                        logger.logStack(Logger.WARNING, eee.getMessage(), eee);
                        conn = null;
                        if (e instanceof BrokerException) {
                            throw (BrokerException) e;
                        }
                        throw new BrokerException(e.getMessage(), e);
                    }
                }
            }
        } while (true);
    } catch (BrokerException e) {
        myex = e;
        throw e;
    } finally {
        Util.close(null, null, conn, myex);
    }
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) TransactionWorkMessageAck(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessageAck) TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException) TransactionWorkMessage(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessage)

Example 5 with TransactionWorkMessage

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

the class TransactionHandler method getTransactionWork2.

private TransactionWork getTransactionWork2(PartitionedStore pstore, List plist, HashMap cmap, HashMap sToCmap) {
    TransactionWork txnWork = new TransactionWork();
    // NB should we be checking for persistent messages?
    for (int i = 0; plist != null && i < plist.size(); i++) {
        SysMessageID sysid = (SysMessageID) plist.get(i);
        PacketReference ref = DL.get(pstore, sysid);
        if (ref == null) {
            logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_MSG_REMOVED_BEFORE_SENDER_COMMIT, sysid));
            continue;
        }
        try {
            if (ref.isPersistent()) {
                TransactionWorkMessage txnWorkMessage = new TransactionWorkMessage();
                Destination dest = ref.getDestination();
                txnWorkMessage.setDestUID(dest.getDestinationUID());
                txnWorkMessage.setPacketReference(ref);
                txnWork.addMessage(txnWorkMessage);
            }
        } catch (Exception ex) {
            logger.logStack((BrokerStateHandler.isShuttingDown() ? Logger.DEBUG : Logger.ERROR), BrokerResources.E_INTERNAL_BROKER_ERROR, "unable to log transaction message " + sysid, ex);
        }
    }
    // iterate over messages consumed in this transaction
    if (cmap != null && cmap.size() > 0) {
        Iterator itr = cmap.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry entry = (Map.Entry) itr.next();
            SysMessageID sysid = (SysMessageID) entry.getKey();
            List interests = (List) entry.getValue();
            if (sysid == null) {
                continue;
            }
            PacketReference ref = DL.get(null, sysid);
            if (ref == null || ref.isDestroyed() || ref.isInvalid()) {
                // already been deleted .. ignore
                continue;
            }
            // The cluster txn should only need op store the addresses of the brokers involved.
            if (!ref.isLocal()) {
                continue;
            }
            Destination[] ds = DL.getDestination(ref.getPartitionedStore(), ref.getDestinationUID());
            Destination dst = ds[0];
            // - hence the list.
            for (int i = 0; i < interests.size(); i++) {
                ConsumerUID intid = (ConsumerUID) interests.get(i);
                ConsumerUID sid = (ConsumerUID) sToCmap.get(intid);
                if (sid == null) {
                    sid = intid;
                }
                try {
                    // ignore non-durable subscriber
                    if (!dst.isQueue() && !sid.shouldStore()) {
                        continue;
                    }
                    if (ref.isPersistent()) {
                        TransactionWorkMessageAck ack = new TransactionWorkMessageAck();
                        ack.setConsumerID(sid);
                        ack.setDest(dst.getDestinationUID());
                        ack.setSysMessageID(sysid);
                        txnWork.addMessageAcknowledgement(ack);
                    }
                } catch (Exception ex) {
                    logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, " unable to log transaction message acknowledgement " + sysid + ":" + intid, ex);
                }
            }
        }
    }
    return txnWork;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) TransactionWorkMessageAck(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessageAck) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) BrokerDownException(com.sun.messaging.jmq.jmsserver.util.BrokerDownException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) IOException(java.io.IOException) AckEntryNotFoundException(com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException) MaxConsecutiveRollbackException(com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionWorkMessage(com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessage) TransactionWork(com.sun.messaging.jmq.jmsserver.data.TransactionWork) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Iterator(java.util.Iterator) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) Map(java.util.Map) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap)

Aggregations

TransactionWorkMessage (com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessage)7 TransactionWorkMessageAck (com.sun.messaging.jmq.jmsserver.data.TransactionWorkMessageAck)3 TransactionWork (com.sun.messaging.jmq.jmsserver.data.TransactionWork)2 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)1 KeyNotFoundException (com.sun.messaging.bridge.api.KeyNotFoundException)1 Packet (com.sun.messaging.jmq.io.Packet)1 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)1 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)1 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)1 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)1 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)1 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)1 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)1 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)1 BrokerDownException (com.sun.messaging.jmq.jmsserver.util.BrokerDownException)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 MaxConsecutiveRollbackException (com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException)1 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)1 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1