Search in sources :

Example 11 with TransactionBroker

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

the class ClusterTxnInfoInfo method isWaitedfor.

public boolean isWaitedfor(BrokerAddress me) throws Exception {
    List waitfor = getWaitfor();
    if (waitfor == null) {
        return false;
    }
    TransactionBroker tb = null;
    Iterator itr = waitfor.iterator();
    while (itr.hasNext()) {
        tb = new TransactionBroker((BrokerAddress) itr.next());
        if (tb.getCurrentBrokerAddress().equals(me)) {
            return true;
        }
    }
    return false;
}
Also used : TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress)

Example 12 with TransactionBroker

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

the class TidList method getClusterTransactionBrokers.

/**
 * Return transaction's participant brokers for the specified transaction.
 *
 * @param id id of the transaction whose participant brokers are to be returned
 * @exception BrokerException if the transaction id is not in the store
 */
TransactionBroker[] getClusterTransactionBrokers(TransactionUID id) throws BrokerException {
    TransactionInfo txnInfo = (TransactionInfo) tidMap.get(id);
    if (txnInfo == null) {
        logger.log(Logger.ERROR, BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id);
        throw new BrokerException(br.getString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id), Status.NOT_FOUND);
    }
    TransactionBroker[] txnBrokers = txnInfo.getTransactionBrokers();
    if (txnBrokers != null) {
        // Make a copy
        txnBrokers = txnBrokers.clone();
    }
    return txnBrokers;
}
Also used : TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)

Example 13 with TransactionBroker

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

the class TidList method loadClientData.

/**
 * When update optimization is enabled, we'll only write out the modified transaction state as client data instead of
 * the whole record (key and value) to improve I/O performance. So when the broker start up and the persisted
 * transaction states are loaded from file, we need to update the TransactionState object with the modified value that
 * is stored in the client data section of the record.
 *
 * @throws PHashMapLoadException if an error occurs while loading data
 */
private void loadClientData() throws PHashMapLoadException {
    if (!updateOptimization) {
        // nothing to do
        return;
    }
    PHashMapLoadException loadException = null;
    Iterator itr = tidMap.entrySet().iterator();
    while (itr.hasNext()) {
        Throwable ex = null;
        Map.Entry entry = (Map.Entry) itr.next();
        Object key = entry.getKey();
        TransactionInfo value = (TransactionInfo) entry.getValue();
        byte[] cData = null;
        try {
            cData = ((PHashMapMMF) tidMap).getClientData(key);
            if (cData != null && cData.length > 0) {
                // 1st byte is the modified state
                int state = cData[0];
                // update txn state
                value.getTransactionState().setState(state);
                // Now read in modified txn broker states
                TransactionBroker[] bkrs = value.getTransactionBrokers();
                if (bkrs != null) {
                    for (int i = 0, len = bkrs.length; i < len; i++) {
                        TransactionBroker bkr = bkrs[i];
                        // update bkr's state
                        // 1 == true
                        boolean isComplete = (cData[i + 1] == 1);
                        bkr.setCompleted(isComplete);
                    }
                }
            }
        } catch (Throwable e) {
            ex = e;
        }
        if (ex != null) {
            PHashMapLoadException le = new PHashMapLoadException("Failed to load client data [cData=" + Arrays.toString(cData) + "]");
            le.setKey(key);
            le.setValue(value);
            le.setNextException(loadException);
            le.initCause(ex);
            loadException = le;
        }
    }
    if (loadException != null) {
        throw loadException;
    }
}
Also used : TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) PHashMapLoadException(com.sun.messaging.jmq.io.disk.PHashMapLoadException) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo) PHashMap(com.sun.messaging.jmq.io.disk.PHashMap)

Example 14 with TransactionBroker

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

the class TransactionHandler method doRemoteRollback.

private void doRemoteRollback(TransactionList translist, TransactionUID id, int nextState) throws BrokerException {
    if (nextState != TransactionState.ROLLEDBACK) {
        throw new BrokerException("Unexpected state " + nextState + " for transactionUID:" + id);
    }
    if (!translist.hasRemoteBroker(id)) {
        return;
    }
    if (Globals.getClusterBroadcast().getClusterVersion() < ClusterBroadcast.VERSION_410) {
        return;
    }
    TransactionBroker[] bas = null;
    try {
        bas = translist.getClusterTransactionBrokers(id);
        if (DEBUG_CLUSTER_TXN) {
            StringBuilder buf = new StringBuilder();
            buf.append("Rollback transaction ").append(id).append(", remote brokers");
            for (TransactionBroker ba : bas) {
                buf.append("\n\t").append(ba);
            }
            logger.log(logger.INFO, buf.toString());
        }
        BrokerAddress addr = null;
        UID tranpid = null;
        if (Globals.getDestinationList().isPartitionMode()) {
            tranpid = translist.getPartitionedStore().getPartitionID();
        }
        for (int i = 0; i < bas.length; i++) {
            if (Globals.getDestinationList().isPartitionMode()) {
                if (tranpid.equals(bas[i].getBrokerAddress().getStoreSessionUID())) {
                    continue;
                }
            } else if (bas[i].getBrokerAddress() == Globals.getMyAddress()) {
                continue;
            }
            addr = bas[i].getCurrentBrokerAddress();
            if (addr == Globals.getMyAddress()) {
                if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO, "Transaction remote broker current address " + bas[i].toString() + " is my address, TUID=" + id);
                }
            } else {
                if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO, "Transaction remote broker current address " + addr + ", TUID=" + id);
                }
            }
            try {
                if (addr != null) {
                    Globals.getClusterBroadcast().acknowledgeMessage2P(addr, (SysMessageID[]) null, (ConsumerUID[]) null, ClusterBroadcast.MSG_ROLLEDBACK, null, Long.valueOf(id.longValue()), tranpid, false, false);
                } else {
                    throw new BrokerDownException(br.getKString(br.X_CLUSTER_UNICAST_UNREACHABLE, bas[i]), Status.GONE);
                }
            } catch (BrokerException e) {
                String emsg = br.getKString(br.W_ROLLBACK_TXN_NOTIFY_REMOTE_BKR_FAIL, bas[i], id);
                if (e.getStatusCode() == Status.GONE || e.getStatusCode() == Status.TIMEOUT || e instanceof BrokerDownException) {
                    logger.log(logger.WARNING, emsg + ": " + e.getMessage());
                } else {
                    logger.logStack(logger.WARNING, emsg, e);
                }
            }
        }
    } catch (Exception e) {
        StringBuilder buf = new StringBuilder();
        if (bas != null) {
            for (TransactionBroker ba : bas) {
                buf.append("\n\t").append(ba);
            }
        }
        String emsg = br.getKString(br.W_ROLLBACK_TXN_NOTIFY_RMEOTE_BKRS_FAIL, buf.toString(), id);
        logger.logStack(logger.WARNING, emsg, e);
    }
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) UID(com.sun.messaging.jmq.util.UID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) 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) BrokerDownException(com.sun.messaging.jmq.jmsserver.util.BrokerDownException)

Example 15 with TransactionBroker

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

the class TransactionHandler method doCommit.

/**
 * Commit a transaction. This method is invoked from two places: 1) From TransactionHandler.handle() when handling a
 * client COMMIT packet. This is the common case. 2) From the admin handler when an admin commit request has been issued
 * on a PREPARED XA transaction.
 *
 * @param id The TransactionUID to commit
 * @param xid The Xid of the transaction to commit. Required if transaction is an XA transaction. Must be null if it is
 * not an XA transaction.
 * @param xaFlags xaFlags passed on COMMIT operation. Used only if an XA transaction.
 * @param ts Current TransactionState of this transaction.
 * @param conlist List of transactions on this connection. Will be null if commit is trigger by an admin request.
 * @param sendReply True to have method send a Status.OK reply while processing transaction. This should be "true" for
 * client initiated commits, "false" for admin initiated commits.
 * @param con Connection client commit packet came in on or, for admin, the connection the admin request came in on.
 * @param msg Client commit packet. Should be "null" for admin initiated commits.
 *
 * @throws BrokerException on an error. The method will have logged a message to the broker log.
 */
public void doCommit(TransactionList translist, TransactionUID id, JMQXid xid, Integer xaFlags, TransactionState ts, List conlist, boolean sendReply, IMQConnection con, Packet msg, boolean startNextTransaction) throws BrokerException {
    int status = Status.OK;
    HashMap cmap = null;
    HashMap sToCmap = null;
    List plist = null;
    PartitionedStore pstore = translist.getPartitionedStore();
    // local, or cluster
    int transactionType = BaseTransaction.UNDEFINED_TRANSACTION_TYPE;
    if (fi.checkFault(FaultInjection.FAULT_TXN_COMMIT_1_EXCEPTION, null)) {
        fi.unsetFault(FaultInjection.FAULT_TXN_COMMIT_1_EXCEPTION);
        throw new BrokerException(FaultInjection.FAULT_TXN_COMMIT_1_EXCEPTION);
    }
    // let acks get handled at a lower level since the
    // lower level methods assumes only 1 ack per message
    plist = translist.retrieveSentMessages(id);
    cmap = translist.retrieveConsumedMessages(id);
    sToCmap = translist.retrieveStoredConsumerUIDs(id);
    cacheSetState(id, ts, con);
    // remove from our active connection list
    if (conlist != null) {
        conlist.remove(id);
    }
    try {
        Globals.getStore().txnLogSharedLock.lock();
        TransactionWork txnWork = null;
        if (Globals.isNewTxnLogEnabled()) {
            txnWork = getTransactionWork2(translist.getPartitionedStore(), plist, cmap, sToCmap);
        }
        // Update transaction state
        try {
            int s;
            if (xid == null) {
                // Plain JMS transaction.
                s = TransactionState.COMMITTED;
            } else {
                // XA Transaction.
                s = ts.nextState(PacketType.COMMIT_TRANSACTION, xaFlags);
            }
            // After this call, returned base transaction will either be:
            // a) null (for single phase LOCAL transaction)
            // b) a prepared XA LOCAL transaction
            // c) a prepared (XA or not) CLUSTER transaction
            // currently, all cluster transactions are 2 phase
            BaseTransaction baseTransaction = doRemoteCommit(translist, id, xaFlags, ts, s, msg, txnWork, con);
            if (Globals.isNewTxnLogEnabled()) {
                if (ts.getState() == TransactionState.PREPARED) {
                    // commit called (from client) on 2-phase transaction
                    transactionType = BaseTransaction.LOCAL_TRANSACTION_TYPE;
                    if (translist.isClusterTransaction(id)) {
                        transactionType = BaseTransaction.CLUSTER_TRANSACTION_TYPE;
                    }
                    logTxnCompletion(translist.getPartitionedStore(), id, TransactionState.COMMITTED, transactionType);
                } else if ((baseTransaction != null && baseTransaction.getState() == TransactionState.PREPARED)) {
                    transactionType = baseTransaction.getType();
                    logTxnCompletion(translist.getPartitionedStore(), id, TransactionState.COMMITTED, transactionType);
                } else {
                    // one phase commit, log all work here
                    transactionType = BaseTransaction.LOCAL_TRANSACTION_TYPE;
                    LocalTransaction localTxn = new LocalTransaction(id, TransactionState.COMMITTED, xid, txnWork);
                    logTxn(translist.getPartitionedStore(), localTxn);
                }
            } else {
            // System.out.println("isFastLogTransactions=false ");
            }
            if (fi.FAULT_INJECTION) {
                fi.checkFaultAndThrowBrokerException(FaultInjection.FAULT_TXN_COMMIT_1_1, null);
            }
            if (ts.getState() == TransactionState.PREPARED || (baseTransaction != null && baseTransaction.getState() == TransactionState.PREPARED)) {
                translist.updateState(id, s, true);
            } else {
                // 1-phase commit
                if (ts.getType() != AutoRollbackType.NEVER && Globals.isMinimumPersistLevel2()) {
                    translist.updateStateCommitWithWork(id, s, true);
                } else {
                    translist.updateState(id, s, true);
                }
            }
            if (fi.FAULT_INJECTION) {
                checkFIAfterDB(PacketType.COMMIT_TRANSACTION);
                fi.checkFaultAndExit(FaultInjection.FAULT_TXN_COMMIT_1_5, null, 2, false);
            }
            startTxnAndSendReply(translist, con, msg, status, startNextTransaction, conlist, xid, id, xaFlags, sendReply);
        } catch (BrokerException ex) {
            logger.logStack(((ex instanceof AckEntryNotFoundException) ? Logger.WARNING : Logger.ERROR), ex.toString() + ": TUID=" + id + " Xid=" + xid, ex);
            throw ex;
        }
        try {
            /*
                 * Can't really call the JMX notification code at the end of doCommit() because the call to
                 * translist.removeTransactionID(id) removes the MBean.
                 */
            Agent agent = Globals.getAgent();
            if (agent != null) {
                agent.notifyTransactionCommit(id);
            }
        } catch (Exception e) {
            logger.log(Logger.WARNING, "JMX agent notify transaction committed failed:" + e.getMessage());
        }
        // OK .. handle producer transaction
        int pLogRecordByteCount = 0;
        ArrayList pLogMsgList = null;
        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;
            }
            // handle forwarding the message
            try {
                if (Globals.txnLogEnabled()) {
                    if (pLogMsgList == null) {
                        pLogMsgList = new ArrayList();
                    }
                    // keep track for producer txn log
                    pLogRecordByteCount += ref.getSize();
                    pLogMsgList.add(ref.getPacket().getBytes());
                }
                Destination[] ds = DL.getDestination(pstore, ref.getDestinationUID());
                Destination d = ds[0];
                if (fi.FAULT_INJECTION) {
                    fi.checkFaultAndExit(FaultInjection.FAULT_TXN_COMMIT_1_6, null, 2, false);
                }
                MessageDeliveryTimeInfo di = ref.getDeliveryTimeInfo();
                if (di != null) {
                    d.routeCommittedMessageWithDeliveryTime(ref);
                } else {
                    Set s = d.routeNewMessage(ref);
                    d.forwardMessage(s, ref);
                }
            } catch (Exception ex) {
                logger.logStack((BrokerStateHandler.isShuttingDown() ? Logger.DEBUG : Logger.ERROR), ex.getMessage() + "[" + sysid + "]TUID=" + id, ex);
            }
        }
        boolean processDone = true;
        // handle consumer transaction
        int cLogRecordCount = 0;
        ArrayList cLogDstList = null;
        ArrayList cLogMsgList = null;
        ArrayList cLogIntList = null;
        HashMap<TransactionBroker, Object> remoteNotified = new HashMap<>();
        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();
                // CANT just pull from connection
                if (sysid == null) {
                    continue;
                }
                PacketReference ref = DL.get(null, sysid);
                if (ref == null || ref.isDestroyed() || ref.isInvalid()) {
                    // already been deleted .. ignore
                    continue;
                }
                PartitionedStore refpstore = ref.getPartitionedStore();
                Destination[] ds = DL.getDestination(refpstore, ref.getDestinationUID());
                Destination dst = ds[0];
                if (dst == null) {
                    if (ref.isDestroyed() || ref.isInvalid()) {
                        continue;
                    }
                }
                List interests = (List) entry.getValue();
                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 {
                        Session s = Session.getSession(intid);
                        if (s != null) {
                            Consumer c = Consumer.getConsumer(intid);
                            if (c != null) {
                                c.messageCommitted(sysid);
                            }
                            PacketReference r1 = null;
                            if (fi.FAULT_INJECTION && fi.checkFault(FaultInjection.FAULT_TXN_COMMIT_1_7_1, null)) {
                                Globals.getConnectionManager().getConnection(s.getConnectionUID()).destroyConnection(true, GoodbyeReason.OTHER, "Fault injection of closing connection");
                            }
                            r1 = (PacketReference) s.ackMessage(intid, sysid, id, translist, remoteNotified, true);
                            try {
                                s.postAckMessage(intid, sysid, true);
                                if (r1 != null) {
                                    if (fi.FAULT_INJECTION) {
                                        fi.checkFaultAndExit(FaultInjection.FAULT_TXN_COMMIT_1_7, null, 2, false);
                                    }
                                    if (dst != null) {
                                        dst.removeMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED);
                                    }
                                } else {
                                    s = Session.getSession(intid);
                                }
                            } finally {
                                if (r1 != null) {
                                    r1.postAcknowledgedRemoval();
                                }
                            }
                        }
                        if (s == null) {
                            // with the stored UID
                            try {
                                if (ref.acknowledged(intid, sid, true, true, id, translist, remoteNotified, true)) {
                                    try {
                                        if (dst != null) {
                                            dst.removeMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED);
                                        }
                                    } finally {
                                        ref.postAcknowledgedRemoval();
                                    }
                                }
                            } catch (BrokerException ex) {
                                // XXX improve internal error
                                logger.log(Logger.WARNING, "Internal error", ex);
                            }
                        }
                        if (Globals.txnLogEnabled()) {
                            if (cLogDstList == null) {
                                cLogDstList = new ArrayList();
                                cLogMsgList = new ArrayList();
                                cLogIntList = new ArrayList();
                            }
                            // ignore non-durable subscriber
                            if (dst == null || (!dst.isQueue() && !sid.shouldStore())) {
                                continue;
                            }
                            cLogRecordCount++;
                            cLogDstList.add(dst.getUniqueName());
                            cLogMsgList.add(sysid);
                            cLogIntList.add(sid);
                        }
                    } catch (Exception ex) {
                        processDone = false;
                        String[] args = { "[" + sysid + ":" + intid + ", " + dst + "]ref=" + ref.getSysMessageID(), id.toString(), con.getConnectionUID().toString() };
                        String emsg = Globals.getBrokerResources().getKString(BrokerResources.W_PROCCESS_COMMITTED_ACK, args);
                        logger.logStack(Logger.WARNING, emsg + "\n" + com.sun.messaging.jmq.io.PacketUtil.dumpPacket(msg) + "--------------------------------------------", ex);
                    }
                }
            }
        }
        if (Globals.isNewTxnLogEnabled()) {
            // notify that transaction work has been written to message store
            loggedCommitWrittenToMessageStore(translist.getPartitionedStore(), id, transactionType);
        }
        if (fi.FAULT_INJECTION) {
            checkFIAfterDB(PacketType.COMMIT_TRANSACTION);
            fi.checkFaultAndExit(FaultInjection.FAULT_TXN_COMMIT_2_1, null, 2, false);
        }
        // OK .. now remove the acks .. and free up the id for ues
        // XXX Fixed 6383878, memory leaks because txn ack can never be removed
        // from the store if the txn is removed before the ack; this is due
        // to the fack that in 4.0 when removing the ack, the method check
        // to see if the txn still exits in the cache. This temporary fix
        // will probably break some HA functionality and need to be revisited.
        translist.removeTransaction(id, (!processDone || (cmap.size() > 0 && BrokerStateHandler.isShuttingDown())));
        if (conlist == null) {
            // from admin
            logger.log(logger.WARNING, BrokerResources.W_ADMIN_COMMITTED_TXN, id, ((xid == null) ? "null" : xid.toString()));
        }
        // log to txn log if enabled
        try {
            if (pLogRecordByteCount > 0 && cLogRecordCount > 0) {
                // Log all msgs and acks for producing and consuming txn
                ByteArrayOutputStream bos = new ByteArrayOutputStream((pLogRecordByteCount) + (cLogRecordCount * (32 + SysMessageID.ID_SIZE + 8)) + 16);
                DataOutputStream dos = new DataOutputStream(bos);
                // Transaction ID (8 bytes)
                dos.writeLong(id.longValue());
                // Msgs produce section
                // Number of msgs (4 bytes)
                dos.writeInt(pLogMsgList.size());
                Iterator itr = pLogMsgList.iterator();
                while (itr.hasNext()) {
                    // Message
                    dos.write((byte[]) itr.next());
                }
                // Msgs consume section
                // Number of acks (4 bytes)
                dos.writeInt(cLogRecordCount);
                for (int i = 0; i < cLogRecordCount; i++) {
                    String dst = (String) cLogDstList.get(i);
                    // Destination
                    dos.writeUTF(dst);
                    SysMessageID sysid = (SysMessageID) cLogMsgList.get(i);
                    // SysMessageID
                    sysid.writeID(dos);
                    ConsumerUID intid = (ConsumerUID) cLogIntList.get(i);
                    // ConsumerUID
                    dos.writeLong(intid.longValue());
                }
                dos.close();
                bos.close();
                ((TxnLoggingStore) pstore).logTxn(TransactionLogType.PRODUCE_AND_CONSUME_TRANSACTION, bos.toByteArray());
            } else if (pLogRecordByteCount > 0) {
                // Log all msgs for producing txn
                ByteBuffer bbuf = ByteBuffer.allocate(pLogRecordByteCount + 12);
                // Transaction ID (8 bytes)
                bbuf.putLong(id.longValue());
                // Number of msgs (4 bytes)
                bbuf.putInt(pLogMsgList.size());
                Iterator itr = pLogMsgList.iterator();
                while (itr.hasNext()) {
                    // Message
                    bbuf.put((byte[]) itr.next());
                }
                ((TxnLoggingStore) pstore).logTxn(TransactionLogType.PRODUCE_TRANSACTION, bbuf.array());
            } else if (cLogRecordCount > 0) {
                // Log all acks for consuming txn
                ByteArrayOutputStream bos = new ByteArrayOutputStream((cLogRecordCount * (32 + SysMessageID.ID_SIZE + 8)) + 12);
                DataOutputStream dos = new DataOutputStream(bos);
                // Transaction ID (8 bytes)
                dos.writeLong(id.longValue());
                // Number of acks (4 bytes)
                dos.writeInt(cLogRecordCount);
                for (int i = 0; i < cLogRecordCount; i++) {
                    String dst = (String) cLogDstList.get(i);
                    // Destination
                    dos.writeUTF(dst);
                    SysMessageID sysid = (SysMessageID) cLogMsgList.get(i);
                    // SysMessageID
                    sysid.writeID(dos);
                    ConsumerUID intid = (ConsumerUID) cLogIntList.get(i);
                    // ConsumerUID
                    dos.writeLong(intid.longValue());
                }
                dos.close();
                bos.close();
                ((TxnLoggingStore) pstore).logTxn(TransactionLogType.CONSUME_TRANSACTION, bos.toByteArray());
            }
        } catch (IOException ex) {
            logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Got exception while writing to transaction log", ex);
            throw new BrokerException("Got exception while writing to transaction log", ex);
        }
    } finally {
        // release lock
        Globals.getStore().txnLogSharedLock.unlock();
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) LocalTransaction(com.sun.messaging.jmq.jmsserver.data.LocalTransaction) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) AckEntryNotFoundException(com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException) Iterator(java.util.Iterator) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) MessageDeliveryTimeInfo(com.sun.messaging.jmq.jmsserver.core.MessageDeliveryTimeInfo) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore) Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) 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) TransactionWork(com.sun.messaging.jmq.jmsserver.data.TransactionWork) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) BaseTransaction(com.sun.messaging.jmq.jmsserver.data.BaseTransaction) Map(java.util.Map) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) TxnLoggingStore(com.sun.messaging.jmq.jmsserver.persist.api.TxnLoggingStore) Session(com.sun.messaging.jmq.jmsserver.core.Session)

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