Search in sources :

Example 1 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class TransactionHandler method doEnd.

public void doEnd(TransactionList translist, int pktType, JMQXid xid, Integer xaFlags, TransactionState ts, TransactionUID id) throws BrokerException {
    String reason = null;
    boolean elogged = false;
    try {
        int s;
        try {
            s = ts.nextState(pktType, xaFlags);
        } catch (BrokerException e) {
            if (e.getStatusCode() == Status.NOT_MODIFIED) {
                elogged = true;
                logger.log(Logger.WARNING, e.getMessage() + ": TUID=" + id + " Xid=" + xid);
            }
            throw e;
        }
        if ((ts.getType() != AutoRollbackType.NEVER && Globals.isMinimumPersist()) || Globals.isNewTxnLogEnabled()) {
            // don't persist end state change
            translist.updateState(id, s, false);
        } else {
            translist.updateState(id, s, true);
        }
    } catch (Exception ex) {
        int status = Status.ERROR;
        if (!elogged) {
            logger.logStack(Logger.ERROR, ex.toString() + ": TUID=" + id + " Xid=" + xid, ex);
        }
        reason = ex.getMessage();
        if (ex instanceof BrokerException) {
            status = ((BrokerException) ex).getStatusCode();
        }
        throw new BrokerException(reason, status);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) 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)

Example 2 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class TransactionHandler method startTxnAndSendReply.

void startTxnAndSendReply(TransactionList translist, IMQConnection con, Packet msg, int status, boolean startNextTransaction, List conlist, JMQXid xid, TransactionUID id, Integer xaFlags, boolean sendReply) {
    // performance optimisation
    long nextTxnID = 0;
    String reason = null;
    if (startNextTransaction) {
        try {
            TransactionUID nextid = new TransactionUID();
            doStart(translist, nextid, conlist, con, AutoRollbackType.NOT_PREPARED, xid, false, 0, 0, xaFlags, PacketType.START_TRANSACTION, false, msg.getSysMessageID().toString());
            nextTxnID = nextid.longValue();
        } 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();
            }
        }
    }
    if (sendReply) {
        // chiaming
        sendReply(con, msg, PacketType.COMMIT_TRANSACTION_REPLY, status, id.longValue(), reason, null, null, nextTxnID);
    }
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) 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)

Example 3 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class TransactionHandler method retrieveConsumedRemoteMessages.

private HashMap[] retrieveConsumedRemoteMessages(TransactionList translist, TransactionUID id, boolean checkOnly) throws BrokerException {
    HashMap mcmap = translist.retrieveConsumedMessages(id);
    HashMap sToCmap = translist.retrieveStoredConsumerUIDs(id);
    if (DEBUG_CLUSTER_TXN) {
        logger.log(logger.INFO, "retrieveConsumedRemoteMessages(" + translist + ",TID=" + id + ") retrieveConsumedMessages: " + mcmap);
    }
    if (mcmap == null || mcmap.size() == 0) {
        return null;
    }
    HashMap[] rets = new HashMap[2];
    HashMap<BrokerAddress, ArrayList[]> bmmap = new HashMap<>();
    HashMap<TransactionBroker, ArrayList<TransactionAcknowledgement>> tbmmap = new HashMap<>();
    ArrayList[] bmcll = null;
    ArrayList<TransactionAcknowledgement> tbmcl = null;
    boolean hasRemote = false;
    BrokerAddress myba = Globals.getMyAddress();
    UID tranpid = translist.getPartitionedStore().getPartitionID();
    UID refpid = null;
    ConsumerUID cuid = null, scuid = null;
    TransactionAcknowledgement ta = null;
    Iterator<Map.Entry> itr = mcmap.entrySet().iterator();
    Map.Entry pair = null;
    while (itr.hasNext()) {
        pair = itr.next();
        SysMessageID sysid = (SysMessageID) pair.getKey();
        if (sysid == null) {
            continue;
        }
        PacketReference ref = DL.get(null, sysid, false);
        if (checkRefRequeued(translist, id, ref, sysid)) {
            BrokerException bex = new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_MESSAGE_MAYBE_REROUTED, sysid) + ", TUID=" + id, Status.GONE);
            bex.setRemote(true);
            StringBuilder buf = new StringBuilder();
            List interests = (List) pair.getValue();
            for (int i = 0; i < interests.size(); i++) {
                buf.append(String.valueOf(((ConsumerUID) interests.get(i)).longValue()));
                buf.append(' ');
            }
            bex.setRemoteConsumerUIDs(buf.toString());
            throw bex;
        }
        if (ref == null) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_MESSAGE_REF_GONE, sysid) + ", TUID=" + id, Status.CONFLICT);
        }
        BrokerAddress ba = ref.getBrokerAddress();
        if (ba == null) {
            if (!DL.isPartitionMode()) {
                ba = myba;
            } else {
                refpid = ref.getPartitionedStore().getPartitionID();
                ba = (BrokerAddress) myba.clone();
                ba.setStoreSessionUID(refpid);
                if (!refpid.equals(tranpid)) {
                    hasRemote = true;
                }
            }
        } else if (!hasRemote) {
            hasRemote = true;
        }
        if (hasRemote && checkOnly) {
            return rets;
        }
        TransactionBroker tba = new TransactionBroker(ba);
        bmcll = bmmap.get(tba.getBrokerAddress());
        tbmcl = tbmmap.get(tba);
        if (bmcll == null) {
            bmcll = new ArrayList[2];
            bmcll[0] = new ArrayList();
            bmcll[1] = new ArrayList();
            bmmap.put(tba.getBrokerAddress(), bmcll);
        }
        if (tbmcl == null) {
            tbmcl = new ArrayList<>();
            tbmmap.put(tba, tbmcl);
        }
        List interests = (List) mcmap.get(sysid);
        for (int i = 0; i < interests.size(); i++) {
            cuid = (ConsumerUID) interests.get(i);
            bmcll[0].add(sysid);
            bmcll[1].add(cuid);
            scuid = (ConsumerUID) sToCmap.get(cuid);
            ta = new TransactionAcknowledgement(sysid, cuid, scuid);
            if (!scuid.shouldStore() || !ref.isPersistent()) {
                ta.setShouldStore(false);
            }
            tbmcl.add(ta);
        }
        if (DEBUG_CLUSTER_TXN) {
            logger.log(logger.INFO, "retrieveConsumedRemoteMessages() for broker " + tba + ": " + Arrays.toString(bmcll) + ", " + tbmcl);
        }
    }
    if (!hasRemote) {
        return null;
    }
    rets[0] = bmmap;
    rets[1] = tbmmap;
    return rets;
}
Also used : TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) ArrayList(java.util.ArrayList) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) 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) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) Map(java.util.Map) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap)

Example 4 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class TransactionHandler method doRemotePrepare.

private ClusterTransaction doRemotePrepare(TransactionList translist, TransactionUID id, TransactionState nextState, TransactionWork txnWork) throws BrokerException {
    if (nextState.getState() != TransactionState.PREPARED) {
        throw new BrokerException("Unexpected state " + nextState + " for transactionID:" + id);
    }
    HashMap[] rets = retrieveConsumedRemoteMessages(translist, id, false);
    if (DEBUG_CLUSTER_TXN) {
        logger.log(logger.INFO, "doRemotePrepare(" + translist + ", " + id + "): retrievedConsumedRemoteMsgs:" + (rets == null ? "null" : rets[0] + ", " + rets[1]));
    }
    if (fi.FAULT_INJECTION) {
        if (fi.checkFault(fi.FAULT_MSG_REMOTE_ACK_C_TXNPREPARE_0_5, null)) {
            fi.unsetFault(fi.FAULT_MSG_REMOTE_ACK_C_TXNPREPARE_0_5);
            throw new BrokerException(fi.FAULT_MSG_REMOTE_ACK_C_TXNPREPARE_0_5);
        }
    }
    if (rets == null) {
        return null;
    }
    if (Globals.getClusterBroadcast().getClusterVersion() < ClusterBroadcast.VERSION_410) {
        return null;
    }
    HashMap<BrokerAddress, ArrayList[]> bmmap = rets[0];
    TransactionBroker[] tranbas = (TransactionBroker[]) rets[1].keySet().toArray(new TransactionBroker[rets[1].size()]);
    BrokerAddress[] bas = bmmap.keySet().toArray(new BrokerAddress[bmmap.size()]);
    boolean persist = true;
    ClusterTransaction clusterTransaction = null;
    if (Globals.isNewTxnLogEnabled()) {
        // create a cluster transaction which will be logged
        clusterTransaction = new ClusterTransaction(id, nextState, txnWork, tranbas);
        translist.logClusterTransaction(id, nextState, tranbas, true, persist, clusterTransaction);
    } else {
        translist.logClusterTransaction(id, nextState, tranbas, true, persist);
    }
    if (DEBUG_CLUSTER_TXN) {
        StringBuilder buf = new StringBuilder();
        buf.append("Preparing transaction ").append(id).append(", brokers");
        for (TransactionBroker tranba : tranbas) {
            buf.append("\n\t").append(tranba);
        }
        logger.log(logger.INFO, buf.toString());
    }
    UID tranpid = null;
    if (Globals.getDestinationList().isPartitionMode()) {
        tranpid = translist.getPartitionedStore().getPartitionID();
        ArrayList<TransactionAcknowledgement> mcl = null;
        TransactionBroker tba = null;
        UID tbapid = null;
        TransactionAcknowledgement[] tas = null;
        TransactionList tl = null;
        for (int i = 0; i < tranbas.length; i++) {
            tba = tranbas[i];
            if (!tba.getBrokerAddress().equals(Globals.getMyAddress())) {
                continue;
            }
            tbapid = tba.getBrokerAddress().getStoreSessionUID();
            if (tbapid.equals(tranpid)) {
                continue;
            }
            mcl = (ArrayList<TransactionAcknowledgement>) rets[1].get(tba);
            tas = mcl.toArray(new TransactionAcknowledgement[mcl.size()]);
            tl = TransactionList.getTransListByPartitionID(tbapid);
            if (tl == null) {
                throw new BrokerException("Can't prepare transaction " + id + " because " + "transaction list for partition " + tbapid + " not found");
            }
            BrokerAddress home = (BrokerAddress) Globals.getMyAddress().clone();
            home.setStoreSessionUID(tranpid);
            tl.logLocalRemoteTransaction(id, nextState, tas, home, false, true, persist);
        }
    }
    // handle remote brokers
    ArrayList[] mcll = null;
    BrokerAddress ba = null;
    for (int i = 0; i < bas.length; i++) {
        ba = bas[i];
        if (ba == Globals.getMyAddress() || ba.equals(Globals.getMyAddress())) {
            continue;
        }
        mcll = bmmap.get(ba);
        try {
            Globals.getClusterBroadcast().acknowledgeMessage2P(ba, (SysMessageID[]) mcll[0].toArray(new SysMessageID[mcll[0].size()]), (ConsumerUID[]) mcll[1].toArray(new ConsumerUID[mcll[1].size()]), ClusterBroadcast.MSG_PREPARE, null, Long.valueOf(id.longValue()), tranpid, true, false);
        } catch (BrokerException e) {
            if (!(e instanceof BrokerDownException) && !(e instanceof AckEntryNotFoundException)) {
                throw e;
            }
            HashMap sToCmap = translist.retrieveStoredConsumerUIDs(id);
            ArrayList remoteConsumerUIDa = new ArrayList();
            StringBuilder remoteConsumerUIDs = new StringBuilder();
            String uidstr = null;
            StringBuilder debugbuf = new StringBuilder();
            for (int j = 0; j < mcll[0].size(); j++) {
                SysMessageID sysid = (SysMessageID) mcll[0].get(j);
                ConsumerUID uid = (ConsumerUID) mcll[1].get(j);
                ConsumerUID suid = (ConsumerUID) sToCmap.get(uid);
                if (suid == null || suid.equals(uid)) {
                    continue;
                }
                if (e.isRemote()) {
                    uidstr = String.valueOf(uid.longValue());
                    if (!remoteConsumerUIDa.contains(uidstr)) {
                        remoteConsumerUIDa.add(uidstr);
                        remoteConsumerUIDs.append(uidstr);
                        remoteConsumerUIDs.append(' ');
                        Consumer c = Consumer.getConsumer(uid);
                        if (c != null) {
                            c.recreationRequested();
                        } else {
                            logger.log(logger.WARNING, "Consumer " + uid + " not found in processing remote exception on preparing transaction " + id);
                        }
                    }
                }
                debugbuf.append("\n\t[").append(sysid).append(':').append(uid).append(']');
            }
            if (e.isRemote()) {
                e.setRemoteConsumerUIDs(remoteConsumerUIDs.toString());
                if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO, "doRemotePrepare: JMQRemote Exception:remoteConsumerUIDs=" + remoteConsumerUIDs + ", remote broker " + ba);
                }
            }
            try {
                translist.updateState(id, TransactionState.FAILED, false, TransactionState.PREPARED, true);
            } catch (Exception ex) {
                logger.logStack(logger.WARNING, "Unable to update transaction " + id + " state to FAILED on PREPARE failure from " + ba + ": " + ex.getMessage() + debugbuf.toString(), ex);
                throw e;
            }
            if (e instanceof AckEntryNotFoundException) {
                mcll = ((AckEntryNotFoundException) e).getAckEntries();
            }
            for (int j = 0; j < mcll[0].size(); j++) {
                SysMessageID sysid = (SysMessageID) mcll[0].get(j);
                ConsumerUID uid = (ConsumerUID) mcll[1].get(j);
                boolean remove = true;
                if (e instanceof BrokerDownException) {
                    ConsumerUID suid = (ConsumerUID) sToCmap.get(uid);
                    if (suid == null || suid.equals(uid)) {
                        if (DEBUG_CLUSTER_TXN) {
                            logger.log(logger.INFO, "doRemotePrepare: no remove txnack " + sysid + ", " + uid + " for BrokerDownException from " + ba);
                        }
                        remove = false;
                    }
                }
                if (remove) {
                    try {
                        translist.removeAcknowledgement(id, sysid, uid, (e instanceof AckEntryNotFoundException));
                        if (DEBUG_CLUSTER_TXN) {
                            logger.log(logger.INFO, "doRemotePrepare: removed txnack " + sysid + ", " + uid + " for BrokerDownException from " + ba);
                        }
                    } catch (Exception ex) {
                        logger.logStack(logger.WARNING, "Unable to remove transaction " + id + " ack [" + sysid + ":" + uid + "] on PREPARE failure from " + ba + ": " + ex.getMessage(), ex);
                    }
                }
            }
            logger.log(logger.WARNING, "Preparing transaction " + id + " failed from " + ba + ": " + e.getMessage() + debugbuf.toString());
            throw e;
        }
    }
    return clusterTransaction;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap) ArrayList(java.util.ArrayList) ClusterTransaction(com.sun.messaging.jmq.jmsserver.data.ClusterTransaction) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) AckEntryNotFoundException(com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException) BrokerDownException(com.sun.messaging.jmq.jmsserver.util.BrokerDownException) TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) 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) 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) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 5 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class TransactionHandler method doStart.

public void doStart(TransactionList translist, TransactionUID id, List conlist, IMQConnection con, AutoRollbackType type, JMQXid xid, boolean sessionLess, long lifetime, long messagetid, Integer xaFlags, int pktType, boolean replay, String creatorID) throws BrokerException {
    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(Long.valueOf(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);
                ts.setConnectionString(con.userReadableString());
                ts.setConnectionUID(con.getConnectionUID());
                translist.addTransactionID(id, ts);
                conlist.add(id);
            } catch (BrokerException ex) {
                // XXX I18N
                logger.log(Logger.ERROR, "Exception starting new transaction: " + ex.toString(), ex);
                throw ex;
            }
        }
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) CacheHashMap(com.sun.messaging.jmq.util.CacheHashMap)

Aggregations

BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)290 IOException (java.io.IOException)72 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)33 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)31 SizeString (com.sun.messaging.jmq.util.SizeString)31 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)29 Iterator (java.util.Iterator)26 ArrayList (java.util.ArrayList)25 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)24 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)23 HashMap (java.util.HashMap)22 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)21 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)21 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)21 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)18 List (java.util.List)18 Packet (com.sun.messaging.jmq.io.Packet)16 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)16 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)15