Search in sources :

Example 1 with UnknownTransactionException

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

the class AckHandler method handleTransaction.

public void handleTransaction(TransactionList translist, IMQConnection con, TransactionUID tid, SysMessageID[] ids, ConsumerUID[] cids, int deliverCnt) throws BrokerException {
    for (int i = 0; i < ids.length; i++) {
        Consumer consumer = null;
        try {
            // lookup the session by consumerUID
            Session s = Session.getSession(cids[i]);
            // look up the consumer by consumerUID
            consumer = Consumer.getConsumer(cids[i]);
            if (consumer == null) {
                throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.I_ACK_FAILED_NO_CONSUMER, cids[i]) + "[TID=" + tid + "]", Status.NOT_FOUND);
            }
            // try and find the stored consumerUID
            ConsumerUID sid = consumer.getStoredConsumerUID();
            // if we still dont have a session, attempt to find one
            if (s == null) {
                SessionUID suid = consumer.getSessionUID();
                s = Session.getSession(suid);
            }
            if (s == null) {
                if (BrokerStateHandler.isShutdownStarted()) {
                    throw new BrokerException(BrokerResources.I_ACK_FAILED_BROKER_SHUTDOWN);
                }
                throw new BrokerException(br.getKString(br.I_ACK_FAILED_NO_SESSION, "[" + ids[i] + ", " + cids[i] + "]TID=" + tid));
            }
            if (DEBUG) {
                logger.log(logger.INFO, "handleTransaction.addAck[" + i + ", " + ids.length + "]:tid=" + tid + ", sysid=" + ids[i] + ", cid=" + cids[i] + ", sid=" + sid + " on connection " + con);
            }
            boolean isxa = translist.addAcknowledgement(tid, ids[i], cids[i], sid);
            BrokerAddress addr = (BrokerAddress) s.ackInTransaction(cids[i], ids[i], tid, isxa, deliverCnt);
            if (addr != null && addr != Globals.getMyAddress()) {
                translist.setAckBrokerAddress(tid, ids[i], cids[i], addr);
            }
            if (fi.FAULT_INJECTION) {
                if (fi.checkFault(fi.FAULT_TXN_ACK_1_5, null)) {
                    fi.unsetFault(fi.FAULT_TXN_ACK_1_5);
                    TransactionAckExistException tae = new TransactionAckExistException("FAULT:" + fi.FAULT_TXN_ACK_1_5, Status.GONE);
                    tae.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
                    tae.setRemote(true);
                    consumer.recreationRequested();
                    throw tae;
                }
            }
        } catch (Exception ex) {
            String emsg = "[" + ids[i] + ", " + cids[i] + "]TUID=" + tid;
            if ((ex instanceof BrokerException) && ((BrokerException) ex).getStatusCode() != Status.ERROR) {
                logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
            } else {
                logger.log(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
            }
            int state = -1;
            JMQXid xid = null;
            try {
                TransactionState ts = translist.retrieveState(tid);
                if (ts != null) {
                    state = ts.getState();
                    xid = ts.getXid();
                }
                translist.updateState(tid, TransactionState.FAILED, true);
            } catch (Exception e) {
                if (!(e instanceof UnknownTransactionException)) {
                    String[] args = { TransactionState.toString(state), TransactionState.toString(TransactionState.FAILED), tid.toString(), (xid == null ? "null" : xid.toString()) };
                    logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_UPDATE_TRAN_STATE_FAIL, args));
                }
            }
            if (ex instanceof TransactionAckExistException) {
                PacketReference ref = DL.get(null, ids[i]);
                if (ref != null && (ref.isOverrided() || ref.isOverriding())) {
                    ((BrokerException) ex).overrideStatusCode(Status.GONE);
                    ((BrokerException) ex).setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
                    ((BrokerException) ex).setRemote(true);
                    consumer.recreationRequested();
                }
            }
            if (ex instanceof BrokerException) {
                throw (BrokerException) ex;
            }
            throw new BrokerException("Internal Error: Unable to " + " complete processing acknowledgements in a tranaction: " + ex, ex);
        }
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) SessionUID(com.sun.messaging.jmq.jmsserver.core.SessionUID) JMQXid(com.sun.messaging.jmq.util.JMQXid) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionAckExistException(com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionAckExistException(com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 2 with UnknownTransactionException

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

the class TransactionList method updateState.

public TransactionState updateState(TransactionUID id, int state, int oldstate, boolean onephasePrepare, int failToState, boolean persist, TransactionWork txnwork) throws BrokerException {
    TransactionInformation ti = null;
    shareLock.lock();
    try {
        ti = (TransactionInformation) translist.get(id);
    } finally {
        shareLock.unlock();
    }
    if (ti == null) {
        throw new UnknownTransactionException("Update state " + TransactionState.toString(state) + " for unknown transaction: " + id);
    }
    if (ti.isTakeoverLocked()) {
        throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_TXN_LOCKED, id), Status.NOT_FOUND);
    }
    TransactionState ts = null;
    // lock TransactionInformation object
    synchronized (ti) {
        ts = ti.getState();
        if (ts == null) {
            throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "updateState(): No state for transaction: " + id), Status.GONE);
        }
        // timed out
        if (ts.getState() == TransactionState.TIMED_OUT) {
            // bad state
            throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "Transaction " + id + ": is has timed out"), Status.TIMEOUT);
        }
        int currstate = ts.getState();
        if (oldstate != TransactionState.NULL && currstate != oldstate) {
            String[] args = { id.toString(), TransactionState.toString(state), TransactionState.toString(ts.getState()), TransactionState.toString(oldstate) };
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_UPDATE_TXN_STATE_CONFLICT, args), Status.CONFLICT);
        }
        ts.setState(state);
        if (state == TransactionState.PREPARED) {
            ts.setOnephasePrepare(onephasePrepare);
        }
        if (state == TransactionState.FAILED && currstate != TransactionState.FAILED) {
            ts.setFailFromState(currstate);
            if (failToState != TransactionState.NULL) {
                ts.setFailToState(failToState);
            }
        }
    }
    // Update state in persistent store
    if (persist) {
        if (fi.FAULT_INJECTION && (state == TransactionState.COMPLETE || state == TransactionState.PREPARED)) {
            String fault = FaultInjection.FAULT_TXN_UPDATE_1_3_END;
            if (state == TransactionState.PREPARED) {
                fault = FaultInjection.FAULT_TXN_UPDATE_1_3_PREPARE;
            }
            try {
                fi.checkFaultAndThrowBrokerException(fault, null);
            } catch (BrokerException e) {
                fi.unsetFault(fault);
                throw e;
            }
        }
        try {
            if (txnwork == null) {
                pstore.updateTransactionState(id, ts, Destination.PERSIST_SYNC);
            } else {
                pstore.updateTransactionStateWithWork(id, ts, txnwork, Destination.PERSIST_SYNC);
            }
        } catch (IOException e) {
            throw new BrokerException(null, e);
        }
    }
    return ts;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) UnknownTransactionException(com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException) IOException(java.io.IOException)

Aggregations

BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)2 UnknownTransactionException (com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException)2 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)1 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)1 Session (com.sun.messaging.jmq.jmsserver.core.Session)1 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)1 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)1 TransactionAckExistException (com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException)1 JMQXid (com.sun.messaging.jmq.util.JMQXid)1 IOException (java.io.IOException)1