Package com.sun.messaging.jmq.jmsserver.util

Examples of com.sun.messaging.jmq.jmsserver.util.BrokerException


                return ROLLEDBACK;
            }
            break;
        }

        throw new BrokerException("Transaction state "+toString(currState)+
        " can not transit to state "+toString(nextState));
    }
View Full Code Here


            Destination d = Destination.getDestination(destination, DestType.isQueue(destType.intValue()));
            if (d == null) {
                errMsg = Globals.getBrokerResources().getKString(
                          BrokerResources.E_NO_SUCH_DESTINATION,
                          getDestinationType(destType.intValue()), destination);
                Exception e = new BrokerException(errMsg);
                e.fillInStackTrace();
                status = Status.ERROR;
                logger.log(Logger.WARNING, BrokerResources.W_ADMIN_OPERATION_FAILED,
e);
            } else {
View Full Code Here

                    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) &&
View Full Code Here

                          throws BrokerException {

        int status = Status.OK;
        HashMap cmap = null;
        HashMap sToCmap = null;
        BrokerException bex = null;
        List plist = null;
       
        int transactionType=BaseTransaction.UNDEFINED_TRANSACTION_TYPE; //local, or cluster

        // 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);
        }

       
     // new performance enhancement
     // log transactions before we store transaction work in message store
     // and before remote commit       
            
            

             try{
             Globals.getStore().txnLogSharedLock.lock();
             TransactionWork txnWork=null;
             if(Globals.isNewTxnLogEnabled())
             {                     
                txnWork = getTransactionWork2(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(id, xaFlags, ts, s, msg, txnWork);
            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(id, TransactionState.COMMITTED,
                transactionType);
          } else if ((baseTransaction != null && baseTransaction
              .getState() == TransactionState.PREPARED)) {
            transactionType = baseTransaction.getType();
            logTxnCompletion(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(localTxn);
          }
        }
            else {
              //System.out.println("isFastLogTransactions=false ");
              }

            if (fi.FAULT_INJECTION) {
                fi.checkFaultAndThrowBrokerException(
                   FaultInjection.FAULT_TXN_COMMIT_1_1, null);
            }
            ts = 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(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 = Destination.get(sysid);
            if (ref == null) {
                logger.log(Logger.ERROR,BrokerResources.E_INTERNAL_BROKER_ERROR,  "transacted message removed too early "+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 d = Destination.getDestination(ref.getDestinationUID());
                if (fi.FAULT_INJECTION) {
                    fi.checkFaultAndExit(FaultInjection.FAULT_TXN_COMMIT_1_6, null, 2, false);
                }
                Set s = d.routeNewMessage(ref);
                d.forwardMessage(s,ref);

             } catch (Exception ex) {
                 logger.logStack((BrokerStateHandler.shuttingDown? Logger.DEBUG : Logger.ERROR),BrokerResources.E_INTERNAL_BROKER_ERROR, "unable to route/send transaction message " + sysid , ex);
             }

        }

        boolean processDone = true;

        // handle consumer transaction
        int cLogRecordCount = 0;
        ArrayList cLogDstList = null;
        ArrayList cLogMsgList = null;
        ArrayList cLogIntList = null;
        HashMap 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 = Destination.get(sysid);
                if (ref == null || ref.isDestroyed() || ref.isInvalid()) {
                    // already been deleted .. ignore
                    continue;
                }

                Destination dst =
                    Destination.getDestination(ref.getDestinationUID());

                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) {
                            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 =s.ackMessage(intid, sysid, id, remoteNotified, true);
                            if (r1 != null) {
                                if (fi.FAULT_INJECTION) {
                                    fi.checkFaultAndExit(FaultInjection.FAULT_TXN_COMMIT_1_7, null, 2, false);
                                }
                                dst.removeMessage(ref.getSysMessageID(),
                                    RemoveReason.ACKNOWLEDGED);
                            } else {
                                s = Session.getSession(intid);
                            }
                        }
                        if (s == null) {
                            //OK the session has been closed, we need
                            // to retrieve the message and acknowledge it
                            // with the stored UID
                            try {
                                if (ref.acknowledged(intid, sid,
                                    true, true, id, remoteNotified, true)) {
                                    dst.removeMessage(ref.getSysMessageID(),
                                        RemoveReason.ACKNOWLEDGED);
                                }
                            } 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();
                            }

                            // keep track for consumer txn log;
                            // ignore non-durable subscriber
                            if (!dst.isQueue() && !sid.shouldStore()) {
                                continue;
                            }

                            cLogRecordCount++;
                            cLogDstList.add(dst.getUniqueName());
                            cLogMsgList.add(sysid);
                            cLogIntList.add(sid);
                        }
                    } catch (Exception ex) {
                        processDone = false;
                        logger.logStack(Logger.ERROR,BrokerResources.E_INTERNAL_BROKER_ERROR,
                            "-------------------------------------------" +
                            "Processing Acknowledgement during committ [" +
                            sysid + ":" + intid + ":" + con.getConnectionUID()+
                            "]\nReference is " + (ref == null ? null : ref.getSysMessageID())
                            + "\n" + com.sun.messaging.jmq.jmsserver.util.PacketUtil.dumpPacket(msg)
                            + "--------------------------------------------",
                            ex);
                    }
                }
            }
        }

       
        if(Globals.isNewTxnLogEnabled())
        {
          // notify that transaction work has been written to message store
           loggedCommitWrittenToMessageStore(id, transactionType);
        }
              

        // 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.shuttingDown)));
        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);

                dos.writeLong(id.longValue()); // Transaction ID (8 bytes)

                // Msgs produce section
                dos.writeInt(pLogMsgList.size()); // Number of msgs (4 bytes)
                Iterator itr = pLogMsgList.iterator();
                while (itr.hasNext()) {
                    dos.write((byte[])itr.next()); // Message
                }

                // Msgs consume section
                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);
                    sysid.writeID(dos); // SysMessageID
                    ConsumerUID intid = (ConsumerUID)cLogIntList.get(i);
                    dos.writeLong(intid.longValue()); // ConsumerUID
                }

                dos.close();
                bos.close();
                Globals.getStore().logTxn(
                    TransactionLogType.PRODUCE_AND_CONSUME_TRANSACTION,
                    bos.toByteArray());
            } else if (pLogRecordByteCount > 0) {
                // Log all msgs for producing txn
                ByteBuffer bbuf = ByteBuffer.allocate(pLogRecordByteCount + 12);
                bbuf.putLong(id.longValue()); // Transaction ID (8 bytes)
                bbuf.putInt(pLogMsgList.size()); // Number of msgs (4 bytes)
                Iterator itr = pLogMsgList.iterator();
                while (itr.hasNext()) {
                    bbuf.put((byte[])itr.next()); // Message
                }
                Globals.getStore().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);
                dos.writeLong(id.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);
                    sysid.writeID(dos); // SysMessageID
                    ConsumerUID intid = (ConsumerUID)cLogIntList.get(i);
                    dos.writeLong(intid.longValue()); // ConsumerUID
                }
                dos.close();
                bos.close();
                Globals.getStore().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(
                "Internal Error: Got exception while writing to transaction log", ex);
        }
      
       
             }
View Full Code Here

    ConsumerUID[] storedInterests = null;
    if(dest==null)
    {
      String msg = "Could not find destination for "+twm.getDestUID() + " refDest= "+ref.getDestinationName();
      logger.log(Logger.ERROR,msg);
      throw new BrokerException(msg);
     
    }
    try {
      storedInterests = dest.calculateStoredInterests(ref);
      twm.setStoredInterests(storedInterests);

    } catch (SelectorFormatException sfe) {
      throw new BrokerException(
          "Could not route transacted message on commit", sfe);
    }
    if (storedInterests != null)
    {
      if (DEBUG_CLUSTER_TXN)
View Full Code Here

                          Integer xaFlags, TransactionState ts)
                          throws BrokerException {

        if (xid != null && ts.getState() == TransactionState.STARTED) {
            int oldstate = TransactionState.STARTED;
            BrokerException ex;
            try {
                ts.nextState(PacketType.ROLLBACK_TRANSACTION, xaFlags);
                return;

            } catch (BrokerException e) {
View Full Code Here

        throws BrokerException
    {
        List plist = null;
        HashMap cmap = null;
        HashMap sToCmap = null;
        BrokerException bex = null;
        cmap = translist.retrieveConsumedMessages(tid, true);
        sToCmap = translist.retrieveStoredConsumerUIDs(tid);
        /* OK .. we've retrieved the messages .. now go through
           them and get References and order them
         */
 
View Full Code Here

    private ClusterTransaction doRemotePrepare(TransactionUID id, TransactionState ts,
                     TransactionState nextState,
                     TransactionWork txnWork) throws BrokerException {
        if (nextState.getState() != TransactionState.PREPARED) {
            throw new BrokerException("Unexpected state "+nextState+" for transactionID:"+id);
        }
        HashMap bmmap =  retrieveConsumedRemoteMessages(id, false);
        if (bmmap == null) return null;
        if (Globals.getClusterBroadcast().getClusterVersion() <
            ClusterBroadcast.VERSION_410) {
View Full Code Here

        return clusterTransaction;
    }
   
    private void doRemoteRollback(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) {
View Full Code Here

    private BaseTransaction doRemoteCommit(TransactionUID id, Integer xaFlags,
                                TransactionState ts, int nextState, Packet msg,
                                TransactionWork txnWork)
                                throws BrokerException {
        if (nextState != TransactionState.COMMITTED) {
            throw new BrokerException("Unexpected next state: "+nextState+" for transaction "+id);
        }
        BaseTransaction baseTransaction = null;
        if (ts.getState() != TransactionState.PREPARED) {
            if (retrieveConsumedRemoteMessages(id, true) != null) {
              // In this transaction messages that belong to a remote broker
              // have been acknowledged. These messages must be
              // acknowledged in the remote broker as part of the same transaction.
              // We therefore need to make this a 2-phase commit.
             
                if (Globals.getClusterBroadcast().getClusterVersion() <
                                            ClusterBroadcast.VERSION_410) {
                    return null;
                }
                Packet p = new Packet();
                try {
                p.fill(msg);
                } catch (IOException e) {
                logger.logStack(Logger.INFO,"Internal Exception processing packet ", e);
                throw new BrokerException(e.getMessage(), e);
                }
                p.setPacketType(PacketType.PREPARE_TRANSACTION);
                if (ts.getState() == TransactionState.STARTED && ts.getXid() == null) {
                    ts.setState(TransactionState.COMPLETE);
                    xaFlags = new Integer(XAResource.TMNOFLAGS);
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.util.BrokerException

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.