Package com.sun.messaging.jmq.jmsserver.data

Examples of com.sun.messaging.jmq.jmsserver.data.TransactionUID


             return getDBInfo();
        } else if (arg.equals("trans")) {
            if (target == null) {
                return getTransactionInfo(null);
            } else {
                TransactionUID uid = new TransactionUID(
                      Long.parseLong(target));
                return getTransactionInfo(uid);
            }
        } else if (arg.equals("pool")) {
            if (target == null) {
View Full Code Here


        if (conlist != null) {
            boolean xaretainall = Globals.getConfig().getBooleanProperty(
                    TransactionList.XA_TXN_DETACHED_RETAINALL_PROP, false);
            ArrayList timeoutTIDs = new ArrayList();
            TransactionList tl = Globals.getTransactionList();
            TransactionUID tid = null;
            boolean xaretainallLogged = false;
            TransactionHandler rollbackHandler = (TransactionHandler)
                                   Globals.getPacketRouter(0).getHandler(
                                          PacketType.ROLLBACK_TRANSACTION);
            TransactionUID[] tuids = (TransactionUID[])conlist.toArray(new TransactionUID[0]);
View Full Code Here

        Iterator itr = tidMap.entrySet().iterator();
        while (itr.hasNext()) {
            try {
                Map.Entry entry = (Map.Entry)itr.next();
                TransactionUID tid = (TransactionUID)entry.getKey();
                TransactionState ts = (TransactionState)entry.getValue();
                // Remove if not in prepared state
                if (ts.getState() != state) {
                    itr.remove();
                    removeTransactionAck(tid);
                }
            } catch (RuntimeException e) {
                error = true;
                exception = e;
                logger.log(Logger.ERROR, BrokerResources.X_CLEAR_TXN_NOTIN_STATE_FAILED,
                    new Integer(state), e);
            }
        }

        if (!error) {
            // We may have transactions left in the ackMap that did not
            // have an entry in the tidMap (maybe it was removed by a commit
            // that never had a chance to complete processing the acks).
            // Check for those "orphaned" ack transactions here. We check
            // state here too just to be anal.
            itr = ackMap.keySet().iterator();
            while (itr.hasNext()) {
                TransactionUID tid = (TransactionUID)itr.next();
                TransactionInfo txnInfo = (TransactionInfo)tidMap.get(tid);
                if (txnInfo == null || txnInfo.getTransactionStateValue() != state) {
                    // Orphan. Remove from txnList
                    removeTransactionAck(tid);
                }
View Full Code Here

    }
    Iterator<BaseTransaction> iter = committed.iterator();
    while (iter.hasNext()) {
      BaseTransaction baseTxn = iter.next();
      TransactionUID tid = baseTxn.getTid();
      preparedTxnStore.removeTransaction(tid, true);
      if (Store.getDEBUG()) {
        String msg = getPrefix()
            + " removed committed transaction from preparedTxnStore. Tid="
            + tid;
View Full Code Here

        }

        //handle 2-phase remote ack

        TransactionList translist = Globals.getTransactionList();
        TransactionUID tid = new TransactionUID(txnID.longValue());
        if (ackType == ClusterBroadcast.MSG_PREPARE) {

            TransactionAcknowledgement[] tas = new TransactionAcknowledgement[sysids.length];
            ackEntry entry = null, value = null;
            StringBuffer dbuf = new StringBuffer();
            AckEntryNotFoundException ae = null;
            synchronized(deliveredMessages) {
                for (int i = 0; i < sysids.length; i++) {
                    entry =  new ackEntry(sysids[i], cuids[i], null);
                    value = (ackEntry)deliveredMessages.get(entry);
                    if (value == null) { //XXX
                        String emsg = "["+sysids[i]+":"+cuids[i]+"]TID="+tid+" not found, maybe rerouted";
                        if (ae == null) ae = new AckEntryNotFoundException(emsg);
                        ae.addAckEntry(sysids[i], cuids[i]);
                        logger.log(logger.WARNING,
                        "["+sysids[i]+":"+cuids[i]+"] not found for preparing remote transaction "+tid+", maybe rerouted");
                        continue;
                    }
                    if (value.getTUID() != null) {
                        String emsg = "["+sysids[i]+":"+cuids[i]+"]TID="+tid+"  has been rerouted";
                        if (ae == null) ae = new AckEntryNotFoundException(emsg);
                        ae.addAckEntry(sysids[i], cuids[i]);
                        logger.log(logger.WARNING, "["+sysids[i]+":"+cuids[i] + "] for preparing remote transaction "
                        +tid + " conflict with transaction "+value.getTUID());
                        continue;
                    }
                    com.sun.messaging.jmq.jmsserver.core.ConsumerUID scuid = value.getStoredConsumerUID();
                    tas[i] = new TransactionAcknowledgement(sysids[i], cuids[i], scuid);
                    PacketReference ref = value.getReference();
                    if (!scuid.shouldStore() || (ref != null && !ref.isPersistent())) {
                        tas[i].setShouldStore(false);
                    }
                    if (DEBUG_CLUSTER_TXN) {
                    dbuf.append("\n\t"+tas[i]);
                    }
                }
                if (ae != null) throw ae;

                TransactionState ts = new TransactionState();
                ts.setState(TransactionState.PREPARED);
                if (DEBUG_CLUSTER_TXN) {
                logger.log(logger.INFO, "Preparing remote transaction "+tid + " from "+txnHomeBroker+dbuf.toString());
                }
                Globals.getTransactionList().logRemoteTransaction(tid, ts, tas,
                                       txnHomeBroker, false, true, true);
                for (int i = 0; i < sysids.length; i++) {
                    entry =  new ackEntry(sysids[i], cuids[i], null);
                    value = (ackEntry)deliveredMessages.get(entry);
                    value.setTUID(tid);
                }
            }
            if (DEBUG_CLUSTER_TXN) {
                logger.log(logger.INFO, "Prepared remote transaction "+tid + " from "+txnHomeBroker+dbuf.toString());
            }
            return;
        }

        if (ackType == ClusterBroadcast.MSG_ROLLEDBACK) {
            if (DEBUG_CLUSTER_TXN) {
            logger.log(logger.INFO, "Rolling back remote transaction "+tid + " from "+txnHomeBroker);
            }
            if (translist.getRemoteTransactionState(tid) == null) {
                if (DEBUG_CLUSTER_TXN) {
                logger.log(logger.INFO, "Unknown remote transaction "+tid+ ", ignore");
                }
                return;
            }
            if (!translist.updateRemoteTransactionState(tid,
                           TransactionState.ROLLEDBACK, false, false, true)) {
                return;
            }

            if (translist.getRecoveryRemoteTransactionAcks(tid) != null) {
                rollbackRecoveryRemoteTransaction(tid, txnHomeBroker);
            }

            RemoteTransactionAckEntry tae =  translist.getRemoteTransactionAcks(tid);
            if (tae == null) {
            logger.log(logger.INFO, Globals.getBrokerResources().getKString(
                       BrokerResources.I_NO_NONRECOVERY_TXNACK_TO_ROLLBACK, tid));
            } else if (tae.processed()) {
            logger.log(logger.INFO, Globals.getBrokerResources().getKString(
                       BrokerResources.I_NO_MORE_TXNACK_TO_ROLLBACK, tid));
            } else {

            TransactionAcknowledgement[] tas = tae.getAcks();
            Set s = new LinkedHashSet();
            ackEntry entry = null, value = null;
            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;
                synchronized(deliveredMessages) {
                        entry =  new ackEntry(sysid, uid, null);
                        value = (ackEntry)deliveredMessages.get(entry);
                        if (value == null) {
                            if (DEBUG_CLUSTER_TXN) {
                            logger.log(logger.INFO,
                            "["+sysid+":"+uid+"] not found in rolling back remote transaction "+tid);
                            }
                            continue;
                        }
                        if (value.getTUID() == null || !value.getTUID().equals(tid)) {
                            if (DEBUG_CLUSTER_TXN) {
                            logger.log(logger.INFO,
                            "["+sysid+":"+uid+"] with TUID="+value.getTUID()+
                            ", in rolling back remote transaction "+tid);
                            }
                            continue;
                        }
                        if (consumers.get(uid) == null) {
                            deliveredMessages.remove(entry);
                            cleanupPendingConsumerUID(uid, sysid);
                            s.add(tas[i]);
                        } else {
                            value.setTUID(null);
                        }
                }
            }
            Iterator itr = s.iterator();
            while (itr.hasNext()) {
                TransactionAcknowledgement ta = (TransactionAcknowledgement)itr.next();
                SysMessageID sysid = ta.getSysMessageID();
                com.sun.messaging.jmq.jmsserver.core.ConsumerUID cuid = ta.getConsumerUID();
                com.sun.messaging.jmq.jmsserver.core.ConsumerUID suid = ta.getStoredConsumerUID();
                if (suid == null) suid = cuid;
                PacketReference ref = Destination.get(sysid);
                if (ref == null) {
                    if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO,
                    "["+sysid+":"+cuid+"] reference not found in rolling back remote transaction "+tid);
                    }
                    continue;
                }
                ref.removeInDelivery(suid);
                ref.getDestination().forwardOrphanMessage(ref, suid);
            }

            } //tas != null

            try {
            Globals.getTransactionList().removeRemoteTransactionAck(tid);
            } catch (Exception e) {
            logger.log(logger.WARNING,
            "Unable to remove transaction ack for rolledback transaction "+tid+": "+e.getMessage());
            }
            try {
            Globals.getTransactionList().removeRemoteTransactionID(tid, true);
            } catch (Exception e ) {
            logger.log(logger.WARNING,
            "Unable to remove rolledback remote transaction "+tid+": "+e.getMessage());
            }
            return;
        }

        int cLogRecordCount = 0;
        ArrayList cLogDstList = null;
        ArrayList cLogMsgList = null;
        ArrayList cLogIntList = null;

        if (ackType == ClusterBroadcast.MSG_ACKNOWLEDGED) {
            if (DEBUG_CLUSTER_TXN) {
            logger.log(logger.INFO, "Committing remote transaction "+tid + " from "+txnHomeBroker);
            }
            if (!Globals.getTransactionList().updateRemoteTransactionState(tid,
                         TransactionState.COMMITTED, (sysids == null), true, true)) {
                if (DEBUG_CLUSTER_TXN) {
                logger.log(logger.INFO, "Remote transaction "+tid + " already committed, from "+txnHomeBroker);
                }
                return;
            }
            boolean done = true;
            if (translist.getRecoveryRemoteTransactionAcks(tid) != null) {
                done = commitRecoveryRemoteTransaction(tid, txnHomeBroker);
            }
            RemoteTransactionAckEntry tae = translist.getRemoteTransactionAcks(tid);
            if (tae == null) {
                logger.log(logger.INFO,
                "No non-recovery transaction acks to process for committing remote transaction "+tid);
            } else if (tae.processed()) {
                logger.log(logger.INFO,
                "No more transaction acks to process for committing remote transaction "+tid);
            } else {

            boolean found = false;
            TransactionAcknowledgement[] tas = tae.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();
                if (sysids != null && !found) {
                    if (sysid.equals(sysids[0]) && cuid.equals(cuids[0])) {
                        found = true;
                    }
                }

                String dstName = null;
                if (Globals.txnLogEnabled()) {
                    if (cLogDstList == null) {
                        cLogDstList = new ArrayList();
                        cLogMsgList = new ArrayList();
                        cLogIntList = new ArrayList();
                    }

                    PacketReference ref = Destination.get(sysid);
                    if (ref != null && !ref.isDestroyed() && !ref.isInvalid()) {
                        Destination dst = Destination.getDestination(ref.getDestinationUID());
                        dstName = dst.getUniqueName();
                    }
                }

                if (acknowledgeMessageFromRemote(ackType, sysid, cuid, optionalProps)) {
                    if (dstName != null) {
                        // keep track for consumer txn log
                        com.sun.messaging.jmq.jmsserver.core.ConsumerUID suid = tas[i].getStoredConsumerUID();
                        if (suid == null) suid = cuid;
                        cLogRecordCount++;
                        cLogDstList.add(dstName);
                        cLogMsgList.add(sysid);
                        cLogIntList.add(suid);
                    }
                } else {
                    done = false;
                }
            }
           
            // notify that message acks have been written to store
            if(Globals.isNewTxnLogEnabled())
            {
              Globals.getStore().loggedCommitWrittenToMessageStore(tid, BaseTransaction.REMOTE_TRANSACTION_TYPE);
            }
           
            if (sysids != null && !found) {
                logger.log(logger.ERROR,
                "Internal Error: ["+sysids[0]+":"+cuids[0]+"] not found in remote transaction " +tid);
                done = false;
            }

            } //tae != null
            if (done) {
                try {
                Globals.getTransactionList().removeRemoteTransactionAck(tid);
                } catch (Exception e) {
                logger.logStack(logger.WARNING,
                "Unable to remove transaction ack for committed remote transaction "+tid, e);
                }
                try {
                Globals.getTransactionList().removeRemoteTransactionID(tid, true);
                } catch (Exception e ) {
                logger.logStack(logger.WARNING,
                "Unable to remove committed remote transaction "+tid, e);
                }
            } else if (Globals.getHAEnabled()) {
                throw new BrokerException(
                "Remote transaction processing incomplete, TUID="+tid);
            }

            // log to txn log if enabled
            try {
                if (Globals.txnLogEnabled() && (cLogRecordCount > 0) ) {
                    // Log all acks for consuming txn
                    ByteArrayOutputStream bos = new ByteArrayOutputStream(
                        (cLogRecordCount * (32 + SysMessageID.ID_SIZE + 8)) + 12);
                    DataOutputStream dos = new DataOutputStream(bos);
                    dos.writeLong(tid.longValue()); // Transaction ID (8 bytes)
                    dos.writeInt(cLogRecordCount); // Number of acks (4 bytes)
                    for (int i = 0; i < cLogRecordCount; i++) {
                        String dst = (String)cLogDstList.get(i);
                        dos.writeUTF(dst); // Destination
                        SysMessageID sysid = (SysMessageID)cLogMsgList.get(i);
View Full Code Here

  void processStoredTxnOnStartup(BaseTransaction baseTxn) {
    if (Store.getDEBUG()) {
      String msg = getPrefix() + " processStoredTxnOnStartup " + baseTxn;
      logger.log(Logger.DEBUG, msg);
    }
    TransactionUID tid = baseTxn.getTid();
    int state = baseTxn.getState();
    if (state == TransactionState.COMMITTED
        || state == TransactionState.ROLLEDBACK) {
      addToCompleteStored(baseTxn);
View Full Code Here

    }
    ClusterTransactionEvent clusterTxnEvent = (ClusterTransactionEvent) txnEvent;
    // replay to store on commit
    ClusterTransaction clusterTxn = clusterTxnEvent.clusterTransaction;
    int state = clusterTxn.getState();
    TransactionUID tid = clusterTxn.getTid();
    if (clusterTxnEvent.getSubType() == ClusterTransactionEvent.Type2PPrepareEvent) {
      // 2-phase prepare
      // check if it is stored
      // (this should only be the case if a failure occurred between saving
      // in prepared txn store and resetting the transaction log
View Full Code Here

        long tid = pkt.getTransactionID();
        synchronized(this) {
            setPacketObject(false, pkt);
        }
        if (tid != 0) {
            transactionid = new TransactionUID(tid);
        } else {
            transactionid = null;
        }
    }
View Full Code Here

  void processStoredTxnOnStartup(BaseTransaction baseTxn) {
    if (Store.getDEBUG()) {
      String msg = getPrefix() + " processStoredTxnOnStartup " + baseTxn;
      logger.log(Logger.DEBUG, msg);
    }
    TransactionUID tid = baseTxn.getTid();
    int state = baseTxn.getState();
    if (state == TransactionState.COMMITTED
        || state == TransactionState.ROLLEDBACK) {
      addToCompleteStored(baseTxn);
View Full Code Here

    }
    RemoteTransactionEvent remoteTxnEvent = (RemoteTransactionEvent) txnEvent;
    // replay to store on commit
    RemoteTransaction remoteTxn = remoteTxnEvent.remoteTransaction;
    int state = remoteTxn.getState();
    TransactionUID tid = remoteTxn.getTid();
    if (remoteTxnEvent.getSubType() == RemoteTransactionEvent.Type2PPrepareEvent) {
      // 2-phase prepare
      // check if it is stored
      // (this should only be the case if a failure occurred between saving
      // in prepared txn store and resetting the transaction log
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.data.TransactionUID

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.