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

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


                Iterator itr = txns.iterator();
                while (itr.hasNext()) {
                    TransactionUID tid = (TransactionUID) itr.next();

                    // ok, make sure it really exists
                    TransactionState state = null;
                    try {
                        state = Globals.getStore().getTransactionState(tid);
                        if (state != null &&
                            state.getState() == TransactionState.COMMITTED) {
                            Globals.getTransactionList().reapTakeoverCommittedTransaction(tid);
                            itr.remove();
                            continue;
                        }
                    } catch (BrokerException ex) { // nope, gone
                        Globals.getTransactionList().removeTransactionAck(tid);
                        Globals.getTransactionList().removeTransactionID(tid);
                        itr.remove();
                        continue;
                    }

                    int realstate = state.getState();
                    int msgs = 0;
                    int acks = 0;
                    try {
                        int[] retval = Globals.getStore().getTransactionUsageInfo(tid);
                        msgs = retval[0];
View Full Code Here


                    List openTxns = new ArrayList();
                    Iterator titr = txn.iterator();
                    while (titr.hasNext()) {
                        boolean rollbackTxn = false;
                        TransactionUID tid = (TransactionUID) titr.next();
                        TransactionState ts = Globals.getStore().getTransactionState(tid);
                        if (ts == null) {
                            titr.remove();
                            continue;
                        }
                        AutoRollbackType type = ts.getType();
                        int state = ts.getState();

                        // OK .. first handle loading messages because
                        // that means we have all the refs in order

                        // ok first handle database changes for ANY
                        // committed or rolledback message
                        if (state == TransactionState.ROLLEDBACK) {

                            logger.log(Logger.INFO, "XXX - DEBUG Rolling back "
                                                     + " transaction " + tid);
                            // ok we may not be done with things yet
                            // add to opentxn list
                            openTxns.add(tid);
                       
                        } else if (state == TransactionState.COMMITTED) {
                            logger.log(Logger.INFO, "XXX - DEBUG Committing "
                                                     + " transaction " + tid);
                             // ok we may not be done with things yet
                             // add to opentxn list
                             openTxns.add(tid);

                        } else if (type == AutoRollbackType.ALL) {
                            // rollback
                            String args[] = {
                                 tracker.getBrokerID(),
                                 String.valueOf(tid.longValue()),
                                 ts.toString(ts.getState()) };
                            logger.log(Logger.INFO,
                                BrokerResources.I_TAKEOVER_TXN_A_ROLLBACK,
                                args);
                            ts.setState(TransactionState.ROLLEDBACK);
                            try {
                                Globals.getStore().updateTransactionState(tid, ts,
                                                   Destination.PERSIST_SYNC);
                            } catch (IOException e) {
                                throw new BrokerException(null, e);
                            }

                             // ok we may not be done with things yet
                             // add to opentxn list
                             openTxns.add(tid);
                        } else if (ts.getType() == AutoRollbackType.NOT_PREPARED
                            &&  ts.getState() < TransactionState.PREPARED) {
                            String args[] = {
                                 tracker.getBrokerID(),
                                 String.valueOf(tid.longValue()),
                                 ts.toString(ts.getState()) };
                            logger.log(Logger.INFO,
                                BrokerResources.I_TAKEOVER_TXN_P_ROLLBACK,
                                args);
                            ts.setState(TransactionState.ROLLEDBACK);
                            try {
                                Globals.getStore().updateTransactionState(tid, ts,
                                                   Destination.PERSIST_SYNC);
                            } catch (IOException e) {
                                throw new BrokerException(null, e);
                            }
                             // ok we may not be done with things yet
                             // add to opentxn list
                             openTxns.add(tid);
                        } else {
                            String args[] = {
                                tracker.getBrokerID(),
                                String.valueOf(tid.longValue()),
                                 ts.toString(ts.getState()) };
                            logger.log(Logger.INFO,
                                BrokerResources.I_TAKEOVER_TXN, args);
                        }
                    }

                    TransactionUID tid = null;
                    TransactionState ts = null, myts = null;
                    TransactionList translist = Globals.getTransactionList();
                    titr = remoteTxn.iterator();
                    while (titr.hasNext()) {
                        tid = (TransactionUID) titr.next();
                        try {
                            ts = Globals.getStore().getTransactionState(tid);
                        } catch (Exception e) {
                            logger.log(logger.WARNING,
                            "Unable to get transaction state "+tid+
                            " for takenover broker "+tracker.getBrokerID());
                            continue;
                        }
                        if (ts == null) continue;
                        try {
                            if (ts.getState() < TransactionState.PREPARED &&
                                translist.retrieveState(tid) != null) { // auto-rollback type
                                if (!translist.isClusterTransactionBroker(tid,
                                    tracker.getStoreSessionUID())) {
                                    continue;
                                }
                                myts = translist.retrieveState(tid);
                                if (myts == null) continue;
                                myts = new TransactionState(myts);
                                translist.updateState(tid,
                                  myts.nextState(PacketType.ROLLBACK_TRANSACTION, null),
                                  myts.getState(), true);
                                logger.log(logger.INFO,
                                "Remote transaction "+tid+"("+
                                 TransactionState.toString(ts.getState())+
                                 ") from takenover broker "+tracker+" will be rolledback");
                            }
                        } catch (Exception e) {
                            logger.log(logger.WARNING,
                            "Unable to set ROLLBACK state to transaction "+tid+":"+
View Full Code Here

    public static Hashtable getTransactionInfo(TransactionList tl,
                                               TransactionUID id,
                 int type) {
                                              
  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", new Integer(type));

        if (xid != null) {
            table.put("xid", xid.toString());
        }

        table.put("txnid", new Long(id.longValue()));
        if (ts.getUser() != null)
            table.put("user", ts.getUser());

        if (ts.getClientID() != null) {
            table.put("clientid", ts.getClientID());
        }
        table.put("timestamp",
                new Long(System.currentTimeMillis() - id.age()));
        table.put("connection", ts.getConnectionString());

        table.put("nmsgs", new Integer(tl.retrieveNSentMessages(id)));
        if (type != REMOTE) {
            table.put("nacks", new Integer(tl.retrieveNConsumedMessages(id)));
        } else {
            table.put("nacks", new Integer(tl.retrieveNRemoteConsumedMessages(id)));
        }
        table.put("state", new Integer(ts.getState()));

  ConnectionUID cuid = ts.getConnectionUID();
  if (cuid != null)  {
      table.put("connectionid", new Long(cuid.longValue()));
  }

  TransactionBroker homeBroker = tl.getRemoteTransactionHomeBroker(id);
View Full Code Here

                            Globals.getTransactionList().addOrphanAck(
                                    tid, e.getSysMessageID(), storeduid, cuid);
                            itr.remove();
                            continue;
                        }
                        TransactionState ts = Globals.getTransactionList().retrieveState(tid, true);
                        if (ts != null && ts.getState() == TransactionState.PREPARED) {
                            Globals.getTransactionList().addOrphanAck(
                                    tid, e.getSysMessageID(), storeduid, cuid);
                            itr.remove();
                            continue;
                        }
                        if (ts != null && ts.getState() == TransactionState.COMMITTED) {
                            itr.remove();
                            continue;
                        }
                        if (ts != null && conn != null &&
                            ts.getState() == TransactionState.COMPLETE &&
                            conn.getConnectionState() >= Connection.STATE_CLOSED) {
                            String[] args = { ""+tid,
                                              TransactionState.toString(ts.getState()),
                                              getConnectionUID().toString() };
                            logger.log(Logger.INFO, Globals.getBrokerResources().getKString(
                                       BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                            Globals.getTransactionList().addOrphanAck(
                                    tid, e.getSysMessageID(), storeduid, cuid);
View Full Code Here

        int requestType =
            ((Integer)cmd_props.get(MessageType.JMQ_MESSAGE_TYPE)).intValue();
        int status = Status.OK;
  String errMsg = null;
        TransactionUID tid = null;
        TransactionState ts = null;
        TransactionHandler thandler = null;

        // Get the packet handler that handles transaction packets
        if (parent.adminPktRtr != null) {
            thandler = (TransactionHandler)
            parent.adminPktRtr.getHandler(PacketType.ROLLBACK_TRANSACTION);
        }

  Long id = (Long)cmd_props.get(MessageType.JMQ_TRANSACTION_ID);

        HAMonitorService hamonitor = Globals.getHAMonitorService();
        if (hamonitor != null && hamonitor.inTakeover()) {
            status = Status.ERROR;
            errMsg =  rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);

            logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
  }

        if (id != null) {
            tid = new TransactionUID(id.longValue());
        } else {
            status = Status.BAD_REQUEST;
        }

        if (status == Status.OK) {
            ts = tl.retrieveState(tid);
            if (ts == null) {
                // Specified transaction did not exist
                status = Status.NOT_FOUND;
          errMsg = rb.getString(rb.E_NO_SUCH_TRANSACTION, tid);
            } else if (requestType == MessageType.COMMIT_TRANSACTION &&
                        ts.getState() != TransactionState.PREPARED) {
                status = Status.PRECONDITION_FAILED;
          errMsg = rb.getString(rb.E_TRANSACTION_NOT_PREPARED, tid);
            } else if (requestType == MessageType.ROLLBACK_TRANSACTION &&
                        (ts.getState() < TransactionState.STARTED ||
                         ts.getState() > TransactionState.PREPARED)) {
                status = Status.PRECONDITION_FAILED;
          errMsg = rb.getString(rb.E_INVALID_TXN_STATE_FOR_ROLLBACK, tid);
            } else {
                JMQXid xid = tl.UIDToXid(tid);

                if (xid == null &&
                    (!(Globals.getHAEnabled() &&
                       ts.getState() == TransactionState.PREPARED))) {
        /*
         * Need to pick the right error message:
         * If (action is ROLLBACK and state is one of {STARTED, FAILED,
         *      INCOMPLETE, COMPLETE})
         *  "Rollback of non-XA transaction 123456789 in non-PREPARED state
         *   is not supported."
         * else
                     *  "Could not find Xid for 123456789"
         */
                    if (requestType == MessageType.ROLLBACK_TRANSACTION &&
                        (ts.getState() >= TransactionState.STARTED &&
                         ts.getState() < TransactionState.PREPARED)) {
                        errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR,
                            "Rollback of non-XA transaction "
        + tid
        + " in non-PREPARED state is not supported.") ;
                } else {
View Full Code Here

        throws BrokerException
    {

        long    messagetid = 0;
        TransactionUID id = null;
        TransactionState ts = null;
        JMQXid xid = null;
        Integer xaFlags = null;
        
        boolean redeliverMsgs = false;
       
        boolean startNextTransaction = false;
       
        boolean setRedeliverFlag = true;
        boolean isIndemp = msg.getIndempotent();
        boolean replay = false;
        boolean jmqonephase = false;
        Boolean jmqonephaseFlag = null;

        Hashtable props = null;
        String reason = null;

        try {
            props = msg.getProperties();
            if (props == null)
                props = new Hashtable();
        } catch (Exception ex) {
            logger.log(Logger.INFO,"Internal Error: unable to retrieve "+
                " properties from transaction message " + msg, ex);
            props = new Hashtable();

        }
       
        // performance optimisation:
        // start a new transaction immediately after commit or rollback and return
        // transactionID in message ack.
        // The client then does not need to make a separate call to startTransaction.
       
        Boolean startNextTransactionBool = (Boolean)props.get("JMQStartNextTransaction");
        startNextTransaction = (startNextTransactionBool == null ? false :
          startNextTransactionBool.booleanValue());       
       
        Boolean redeliverMsgBool = (Boolean)props.get("JMQRedeliver");
        redeliverMsgs = (redeliverMsgBool == null ? false :
                      redeliverMsgBool.booleanValue());
  
        Boolean redeliverFlag = (Boolean)props.get("JMQSetRedelivered");
        setRedeliverFlag = (redeliverFlag == null ? true :
                         redeliverFlag.booleanValue());
        jmqonephaseFlag = (Boolean)props.get("JMQXAOnePhase");
        jmqonephase = (jmqonephaseFlag == null ? false:jmqonephaseFlag.booleanValue());

        if (DEBUG) {
            logger.log(Logger.DEBUG, PacketType.getString(msg.getPacketType())+": "+
                       "TUID=" + id + ", JMQRedeliver=" + redeliverMsgBool+
                       (jmqonephaseFlag == null ? "":", JMQXAOnePhase="+jmqonephase));
        }

        List conlist = (List)con.getClientData(IMQConnection.TRANSACTION_LIST);
        if (conlist == null) {
            conlist = new ArrayList();
             con.addClientData(IMQConnection.TRANSACTION_LIST, conlist);
        }

        // If there is a message body, then it should contain an Xid.
        ByteBuffer body = msg.getMessageBodyByteBuffer();
        if (body != null) {
            JMQByteBufferInputStream  bbis = new JMQByteBufferInputStream(body);
            try {
                xid = JMQXid.read(new DataInputStream(bbis));
                startNextTransaction=false;
            } catch (IOException e) {
                logger.log(Logger.ERROR,
                        BrokerResources.E_INTERNAL_BROKER_ERROR,
                        "Could not decode xid from packet: " +  e +
                        " Ignoring " +
                        PacketType.getString(msg.getPacketType()));
                reason = e.getMessage();
                sendReply(con, msg, msg.getPacketType() + 1,
                          Status.BAD_REQUEST, 0, reason);
                return true;
            }
        }

        // Get XAFlags. Note, not all packets will have this -- that's OK.
        if (props != null) {
            xaFlags = (Integer)props.get("JMQXAFlags");
        }

        // tidMap maps an old style transaction identifier to a TransactionUID.
        // In iMQ2.0 the transaction identifier in the packet was an int
        // generated by the client and only unique on the connection.
        // In Falcon it is a long that is unique accross the cluster.
        // So for 2.0 clients we allocate a TransactionUID and map the old
        // style identifier to it.
        //
        // Get tidMap
        HashMap tidMap = null;
        synchronized(con) {
            tidMap = (HashMap)con.getClientData(IMQConnection.TRANSACTION_IDMAP);
            if (tidMap == null) {
                tidMap = new HashMap();
                con.addClientData(IMQConnection.TRANSACTION_IDMAP, tidMap);
            }
        }

        // Go ahead and get the value of "JMQTransactionID" from the packet.
        // may not be used in all cases.
        messagetid = getJMQTransactionID(props);


        // handle initial fault injections

        if (fi.FAULT_INJECTION)
            checkFIBeforeProcess(msg.getPacketType());

        // If it is a new transaction then create a new transaction id.
        // else wrap the one specified in the packet
        if (msg.getPacketType() == PacketType.START_TRANSACTION &&
            (xaFlags == null ||
            TransactionState.isFlagSet(XAResource.TMNOFLAGS, xaFlags) )) {

            // It's a START_TRANSACTION that is not a Join, or Resume.
            // Allocate a new TransactionUID


            if (isIndemp) { // deal with indemp flag
                id = translist.getTransaction(msg.getSysMessageID().toString());
                if (id != null) {
                    replay = true;
                } else {
                    id = new TransactionUID();
                }
            } else {
                id = new TransactionUID();
            }
        } else if (msg.getPacketType() == PacketType.RECOVER_TRANSACTION) {
            if (messagetid != 0) {
                // Recovering a specific transaction.
                id = new TransactionUID(messagetid);
            }
            xid = null;
        } else {
            // Operation on an existing transaction
            // Get TransactionUID out of packet
            // If only Xid was specified need to lookup TransactionUID
            if (messagetid == 0 && xid != null) {
                id = translist.xidToUID(xid);

                if (id != null) {
                    messagetid = id.longValue();
                } else {
                    // Hmmm...haven't seen this Xid before.
                    // XXX I18N
                    logger.log(Logger.WARNING,
                        PacketType.getString(msg.getPacketType()) +
                        ": Ignoring unknown XID=" + xid +
                         " broker will "
                         + (msg.getSendAcknowledge() ?
                               "notify the client" :
                               " not notify the client" ));
                    if (msg.getSendAcknowledge()) {
                        reason = "Uknown XID " + xid;
                        sendReply(con, msg, msg.getPacketType() + 1,
                            Status.NOT_FOUND, 0, reason);
                    }
                    return true;
                }
            } else if (messagetid != 0) {
                if (con.getClientProtocolVersion() == PacketType.VERSION1) {
                    // Map old style to new
                    synchronized(tidMap) {
                        id = (TransactionUID)tidMap.get(new Long(messagetid));
                    }
                } else {
                    // Wrap new style
                    id = new TransactionUID(messagetid);
                }
            }

            // Get the state of the transaction
            if (id == null) {
                logger.log(Logger.INFO,"InternalError: "
                         + "Transaction ID was not passed by "
                         +"the jms api on a method that reqires an "
                         + "existing transaction ");
                sendReply(con, msg, msg.getPacketType() + 1,
                          Status.ERROR, 0, "Internal Error: bad MQ protocol,"
                               + " missing TransactionID");
                return true;

               
            } else {
                ts = translist.retrieveState(id);
            }

            if (ts == null) {
                // Check if we've recently operated on this transaction

                if (isIndemp && ( msg.getPacketType() ==
                          PacketType.ROLLBACK_TRANSACTION ||
                       msg.getPacketType() ==
                          PacketType.COMMIT_TRANSACTION  )) {
                    if (msg.getSendAcknowledge()) {
                        sendReply(con, msg, msg.getPacketType() + 1,
                            Status.OK, id.longValue(), reason);
                        return true;
                    } else {
                        if (fi.FAULT_INJECTION) {
                            checkFIAfterProcess(msg.getPacketType());
                            checkFIAfterReply(msg.getPacketType());
                        }
                    }

                } else {
                    ts = cacheGetState(id, con);
                    if (ts != null) {
                        // XXX l10n
                        logger.log(Logger.ERROR,
                            "Transaction ID " + id +
                            " has already been resolved. Ignoring request: " +
                            PacketType.getString(msg.getPacketType()) +
                            ". Last state of this transaction: " +
                            ts.toString() +
                             " broker will "
                             + (msg.getSendAcknowledge() ?
                                   "notify the client" :
                                  " not notify the client" ));
                    } else {
                    logger.log((BrokerStateHandler.shuttingDown? Logger.DEBUG : Logger.WARNING),
                               Globals.getBrokerResources().getKString(
                               (msg.getSendAcknowledge() ? BrokerResources.W_UNKNOWN_TRANSACTIONID_NOTIFY_CLIENT :
                                                           BrokerResources.W_UNKNOWN_TRANSACTIONID_NONOTIFY_CLIENT),
                               ""+id+ "(" + messagetid + ")"+ (xid == null ? "":"XID="+xid),
                               PacketType.getString(msg.getPacketType())) + "\n" +
                               com.sun.messaging.jmq.jmsserver.util.PacketUtil.dumpPacket(msg));
                    }

                    // Only send reply if A bit is set
                    if (msg.getSendAcknowledge()) {
                        reason = "Unknown transaction " + id;
                        sendReply(con, msg, msg.getPacketType() + 1,
                        Status.NOT_FOUND, id.longValue(), reason);
                    }
                    return true;
                }
            }
        }


        if (DEBUG) {
            logger.log(Logger.INFO, this.getClass().getName() + ": " +
                PacketType.getString(msg.getPacketType()) + ": " +
                "TUID=" + id +
                " XAFLAGS=" + TransactionState.xaFlagToString(xaFlags) +
                (jmqonephaseFlag == null ? "":" JMQXAOnePhase="+jmqonephase)+
                " State=" + ts + " Xid=" + xid);
        }

        // If a packet came with an Xid, make sure it matches what
        // we have in the transaction table.
        if (xid != null && ts != null) {
            if (ts.getXid() == null || !xid.equals(ts.getXid())) {
                // This should never happen
                logger.log(Logger.ERROR,
                        BrokerResources.E_INTERNAL_BROKER_ERROR,
                        "Transaction Xid mismatch. " +
                        PacketType.getString(msg.getPacketType()) +
                        " Packet has tuid=" +
                        id + " xid=" + xid + ", transaction table has tuid=" +
                        id + " xid=" + ts.getXid() +
                        ". Using values from table.");
                xid = ts.getXid();
            }
        }

        if (xid == null && ts != null && ts.getXid() != null &&
            msg.getPacketType() != PacketType.RECOVER_TRANSACTION) {
            // Client forgot to put Xid in packet.
            xid = ts.getXid();
            logger.log(Logger.WARNING,
                        BrokerResources.E_INTERNAL_BROKER_ERROR,
                        "Transaction Xid "+xid+" not found in " +
                        PacketType.getString(msg.getPacketType()) +
                        " packet for tuid " +
                        id + ". Will use " + xid);
        }


        int status = Status.OK;

        // retrieve new 4.0 properties
        AutoRollbackType type = null;
        long lifetime = 0;
        boolean sessionLess = false;
        Integer typeValue = (Integer)props.get("JMQAutoRollback");
        Long lifetimeValue = (Long)props.get("JMQLifetime");
        Boolean sessionLessValue = (Boolean)props.get("JMQSessionLess");

        if (typeValue != null) {
            type = AutoRollbackType.getType(typeValue.intValue());
        }

        if (lifetimeValue != null) {
            lifetime = lifetimeValue.longValue();
        }

        if (sessionLessValue != null) {
            sessionLess = sessionLessValue.booleanValue();
        } else {
            sessionLess = xid != null;
        }


        switch (msg.getPacketType())  {
            case PacketType.START_TRANSACTION:
            {
                try {
                    SessionUID suid = null;
                    Long sessionID = (Long)props.get("JMQSessionID");
                    if (sessionID != null) {
                        suid = new SessionUID(sessionID.longValue());
                    }
                    doStart(id, conlist, con,
                        type, xid, sessionLess, lifetime, messagetid,
                        xaFlags, msg.getPacketType(), replay, msg.getSysMessageID().toString());
                } catch (Exception ex) {
                    status = Status.ERROR;
                    logger.logStack(Logger.ERROR,
                           BrokerResources.E_INTERNAL_BROKER_ERROR,
                           ex.toString() + ": TUID=" + id + " Xid=" + xid, ex);
                    reason = ex.getMessage();
                    if (ex instanceof BrokerException) {
                        status = ((BrokerException)ex).getStatusCode();
                    }
                }
                sendReply(con, msg, PacketType.START_TRANSACTION_REPLY,
                            status, id.longValue(), reason);
                break;
            }

            case PacketType.END_TRANSACTION:
                try {
                    doEnd(msg.getPacketType(), xid, xaFlags, ts, id);
                } catch (Exception ex) {
                    status = Status.ERROR;
                    reason = ex.getMessage();
                    if (ex instanceof BrokerException) status = ((BrokerException)ex).getStatusCode();
                }
                sendReply(con, msg,  msg.getPacketType() + 1, status, id.longValue(), reason);
                break;
            case PacketType.PREPARE_TRANSACTION:
                BrokerException bex = null;
                try {
                    doPrepare(id, xaFlags, ts, msg.getPacketType(), jmqonephase, null);
                } catch (Exception ex) {
                    status = Status.ERROR;
                    if ((!(ex instanceof BrokerDownException) &&
                         !(ex instanceof AckEntryNotFoundException)) || DEBUG_CLUSTER_TXN) {
                    logger.logStack(Logger.ERROR,
                            ex.toString() + ": TUID=" + id + " Xid=" + xid, ex);
                    } else {
                    logger.log(((ex instanceof AckEntryNotFoundException) ? Logger.WARNING:Logger.ERROR),
                               ex.toString() + ": TUID=" + id + " Xid=" + xid);
                    }
                    reason = ex.getMessage();
                    if (ex instanceof BrokerException) {
                        status = ((BrokerException)ex).getStatusCode();
                        bex = (BrokerException)ex;
                    }
                }
                sendReply(con, msg,  msg.getPacketType() + 1, status,
                          id.longValue(), reason, bex);
                break;
            case PacketType.RECOVER_TRANSACTION:

                Vector v = null;

                if (id != null) {
                    // Check if specified transaction is in PREPARED state
                    v = new Vector();
                    ts = translist.retrieveState(id);
                    if (ts.getState() == TransactionState.PREPARED) {
                        v.add(id);
                    }
                } else {
                    // XA Transaction only. We return all Xids on a STARTRSCAN
                    // and nothing on ENDRSCAN or NOFLAGS
                    if (xaFlags == null ||
                        !TransactionState.isFlagSet(XAResource.TMSTARTRSCAN,
                                                                    xaFlags)) {
                        Hashtable hash = new Hashtable();
                        hash.put("JMQQuantity", new Integer(0));
   
                        sendReplyBody(con, msg,
                            PacketType.RECOVER_TRANSACTION_REPLY,
                            Status.OK, hash, null);
                        break;
                    }
                    // Get list of transactions in PENDING state and marshal
                    // the Xid's to a byte array.
                    v = translist.getTransactions(TransactionState.PREPARED);
                }

                int nIDs = v.size();
                int nWritten = 0;
                ByteArrayOutputStream bos =
                            new ByteArrayOutputStream(nIDs * JMQXid.size());
                DataOutputStream dos = new DataOutputStream(bos);
                for (int n = 0; n < nIDs; n++) {
                    TransactionUID tuid = (TransactionUID)v.get(n);
                    TransactionState _ts = translist.retrieveState(tuid);
                    if (_ts == null) {
                        // Should never happen
                        logger.log(Logger.ERROR,
                                BrokerResources.E_INTERNAL_BROKER_ERROR,
                                "Could not find state for TUID " + tuid);
                        continue;
                    }
                    JMQXid _xid = _ts.getXid();
                    if (_xid != null) {
                        try {
                            _xid.write(dos);
                            nWritten++;
                        } catch (Exception e) {
View Full Code Here

    }

    private TransactionState cacheGetState(TransactionUID id,
                                           IMQConnection con) {

        TransactionState ts = null;

        // Do this only if transaction debug is enabled!
        if (GlobalProperties.getGlobalProperties().TRANSACTION_DEBUG) {
            CacheHashMap cache = (CacheHashMap)con.getClientData(
                IMQConnection.TRANSACTION_CACHE);
View Full Code Here

    }
     
        boolean prepared = false;
        int s = ts.nextState(pktType, xaFlags);
        try {
            TransactionState nextState = new TransactionState(ts);
            nextState.setState(s);
            baseTransaction = doRemotePrepare(id, ts, nextState, txnWork);
            if(baseTransaction==null)
            {
              // work not logged yet, so this must be a local broker transaction
              // (there are no remote acknowledgements) 
View Full Code Here

        HashMap tidMap =
            (HashMap)con.getClientData(IMQConnection.TRANSACTION_IDMAP);

        int status  =0;
        String reason = null;
        TransactionState ts = null;
        ts = translist.retrieveState(id);

        if (type == AutoRollbackType.NEVER || lifetime > 0) {
            // not supported
            status = Status.NOT_IMPLEMENTED;
            reason = "AutoRollbackType of NEVER not supported";
            throw new BrokerException(reason, status);
        } else if (xid != null && !sessionLess) {
            // not supported yet
            status = Status.NOT_IMPLEMENTED;
            reason = "XA transactions only supported on sessionless "
                      + "connections";
            throw new BrokerException(reason, status);
        } else if (xid == null && sessionLess) {
            // not supported yet
            status = Status.ERROR;
            reason = "non-XA transactions only supported on "
                              + " non-sessionless connections";
            throw new BrokerException(reason, status);

        } else {
    
            if (replay) {
                // do nothing it already happened
            } else if (xaFlags != null &&
                !TransactionState.isFlagSet(XAResource.TMNOFLAGS, xaFlags))
            {
                // This is either a TMJOIN or TMRESUME. We just need to
                // update the transaction state
                int s = ts.nextState(pktType, xaFlags);
                translist.updateState(id, s, true);
            } else {
              // Brand new transaction
                try {
                    if (con.getClientProtocolVersion() ==
                                                PacketType.VERSION1) {
                        // If 2.0 client Map old style ID to new
                        tidMap.put(new Long(messagetid), id);
                    }

                    if (xid != null && type == null) {
                        type = translist.AUTO_ROLLBACK ? AutoRollbackType.ALL:AutoRollbackType.NOT_PREPARED;
                    }
                    ts = new TransactionState(type, lifetime, sessionLess);
                    ts.setState(TransactionState.STARTED);
                    ts.setUser(con.getUserName());
                    ts.setCreator(creatorID);
                    ts.setClientID(
                        (String)con.getClientData(IMQConnection.CLIENT_ID));
                    ts.setXid(xid);

                    if (con instanceof IMQConnection) {
                        ts.setConnectionString(
                            ((IMQConnection)con).userReadableString());
                        ts.setConnectionUID(
                            ((IMQConnection)con).getConnectionUID());
                    }
                    translist.addTransactionID(id, ts);

                    conlist.add(id);
View Full Code Here

                        if (interests != null && interests.size() > 0) {
                            boolean found = false;
                            for (int j = 0; j < interests.size(); j++) {
                                ConsumerUID intid = (ConsumerUID)interests.get(j);
                                if (intid.equals(id)) {
                                    TransactionState ts = translist.retrieveState(tid);
                                    if (ts != null && ts.getState() == TransactionState.FAILED) {
                                        found = true;
                                        break;
                                    }
                                }
                            }
View Full Code Here

TOP

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

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.