Search in sources :

Example 1 with TransactionHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.

the class CoreLifecycleImpl method initHandlers.

@Override
public void initHandlers(PacketRouter pktrtr, ConnectionManager cmgr, PacketRouter admin_pktrtr, AdminDataHandler admin_datahdrl) throws BrokerException {
    this.pktr = pktrtr;
    HelloHandler hello = new HelloHandler(cmgr);
    hello.setCoreLifecycle(this);
    GetLicenseHandler getLicense = new GetLicenseHandler();
    getLicense.setCoreLifecycle(this);
    GoodbyeHandler goodbye = new GoodbyeHandler();
    goodbye.setCoreLifecycle(this);
    StartStopHandler startstop = new StartStopHandler();
    startstop.setCoreLifecycle(this);
    ConsumerHandler conhdlr = new ConsumerHandler();
    conhdlr.setCoreLifecycle(this);
    ProducerHandler prodhandler = new ProducerHandler();
    prodhandler.setCoreLifecycle(this);
    DestinationHandler desthandler = new DestinationHandler();
    desthandler.setCoreLifecycle(this);
    QBrowseHandler qbrowserhdlr = new QBrowseHandler();
    qbrowserhdlr.setCoreLifecycle(this);
    AuthHandler authenticate = new AuthHandler();
    authenticate.setCoreLifecycle(this);
    SessionHandler sessionhdlr = new SessionHandler();
    sessionhdlr.setCoreLifecycle(this);
    PingHandler pinghandler = new PingHandler();
    pinghandler.setCoreLifecycle(this);
    DataHandler datahdrl = new DataHandler();
    datahdrl.setCoreLifecycle(this);
    AckHandler ackhandler = new AckHandler();
    ackhandler.setCoreLifecycle(this);
    RedeliverHandler redeliverhdlr = new RedeliverHandler();
    redeliverhdlr.setCoreLifecycle(this);
    DeliverHandler deliverhdlr = new DeliverHandler();
    deliverhdlr.setCoreLifecycle(this);
    TransactionHandler thandler = new TransactionHandler();
    thandler.setCoreLifecycle(this);
    VerifyDestinationHandler vdhandler = new VerifyDestinationHandler();
    vdhandler.setCoreLifecycle(this);
    ClientIDHandler clienthandler = new ClientIDHandler();
    clienthandler.setCoreLifecycle(this);
    FlowHandler flowhdlr = new FlowHandler();
    flowhdlr.setCoreLifecycle(this);
    FlowPausedHandler fphandler = new FlowPausedHandler();
    fphandler.setCoreLifecycle(this);
    GenerateUIDHandler genUIDhandler = new GenerateUIDHandler();
    genUIDhandler.setCoreLifecycle(this);
    InfoRequestHandler infohandler = new InfoRequestHandler();
    infohandler.setCoreLifecycle(this);
    VerifyTransactionHandler vthandler = new VerifyTransactionHandler();
    vthandler.setCoreLifecycle(this);
    pktrtr.addHandler(PacketType.HELLO, hello);
    pktrtr.addHandler(PacketType.AUTHENTICATE, authenticate);
    pktrtr.addHandler(PacketType.GET_LICENSE, getLicense);
    pktrtr.addHandler(PacketType.ADD_CONSUMER, conhdlr);
    pktrtr.addHandler(PacketType.DELETE_CONSUMER, conhdlr);
    pktrtr.addHandler(PacketType.ADD_PRODUCER, prodhandler);
    pktrtr.addHandler(PacketType.START, startstop);
    pktrtr.addHandler(PacketType.STOP, startstop);
    pktrtr.addHandler(PacketType.ACKNOWLEDGE, ackhandler);
    pktrtr.addHandler(PacketType.BROWSE, qbrowserhdlr);
    pktrtr.addHandler(PacketType.GOODBYE, goodbye);
    pktrtr.addHandler(PacketType.REDELIVER, redeliverhdlr);
    pktrtr.addHandler(PacketType.CREATE_DESTINATION, desthandler);
    pktrtr.addHandler(PacketType.DESTROY_DESTINATION, desthandler);
    pktrtr.addHandler(PacketType.VERIFY_DESTINATION, vdhandler);
    pktrtr.addHandler(PacketType.DELIVER, deliverhdlr);
    pktrtr.addHandler(PacketType.START_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.COMMIT_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.ROLLBACK_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.PREPARE_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.END_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.RECOVER_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.SET_CLIENTID, clienthandler);
    pktrtr.addHandler(PacketType.GENERATE_UID, genUIDhandler);
    pktrtr.addHandler(PacketType.MAP_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.BYTES_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.MESSAGE_SET, datahdrl);
    pktrtr.addHandler(PacketType.OBJECT_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.STREAM_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.TEXT_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.RESUME_FLOW, flowhdlr);
    pktrtr.addHandler(PacketType.FLOW_PAUSED, fphandler);
    pktrtr.addHandler(PacketType.CREATE_SESSION, sessionhdlr);
    pktrtr.addHandler(PacketType.DELETE_PRODUCER, prodhandler);
    pktrtr.addHandler(PacketType.DESTROY_SESSION, sessionhdlr);
    pktrtr.addHandler(PacketType.PING, pinghandler);
    pktrtr.addHandler(PacketType.INFO_REQUEST, infohandler);
    pktrtr.addHandler(PacketType.VERIFY_TRANSACTION, vthandler);
    // Map message handles -> messages. For the admin service this
    // is just like the regular JMS service except we have a specialized
    // data handler
    admin_pktrtr.addHandler(PacketType.HELLO, hello);
    admin_pktrtr.addHandler(PacketType.AUTHENTICATE, authenticate);
    admin_pktrtr.addHandler(PacketType.GET_LICENSE, getLicense);
    admin_pktrtr.addHandler(PacketType.ADD_CONSUMER, conhdlr);
    admin_pktrtr.addHandler(PacketType.DELETE_CONSUMER, conhdlr);
    admin_pktrtr.addHandler(PacketType.ADD_PRODUCER, prodhandler);
    admin_pktrtr.addHandler(PacketType.START, startstop);
    admin_pktrtr.addHandler(PacketType.STOP, startstop);
    admin_pktrtr.addHandler(PacketType.ACKNOWLEDGE, ackhandler);
    admin_pktrtr.addHandler(PacketType.BROWSE, qbrowserhdlr);
    admin_pktrtr.addHandler(PacketType.GOODBYE, goodbye);
    admin_pktrtr.addHandler(PacketType.REDELIVER, redeliverhdlr);
    admin_pktrtr.addHandler(PacketType.CREATE_DESTINATION, desthandler);
    admin_pktrtr.addHandler(PacketType.DESTROY_DESTINATION, desthandler);
    admin_pktrtr.addHandler(PacketType.VERIFY_DESTINATION, vdhandler);
    admin_pktrtr.addHandler(PacketType.DELIVER, deliverhdlr);
    admin_pktrtr.addHandler(PacketType.START_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.COMMIT_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.ROLLBACK_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.PREPARE_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.END_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.RECOVER_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.SET_CLIENTID, clienthandler);
    admin_pktrtr.addHandler(PacketType.GENERATE_UID, genUIDhandler);
    admin_pktrtr.addHandler(PacketType.MAP_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.BYTES_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.MESSAGE_SET, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.OBJECT_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.STREAM_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.TEXT_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.RESUME_FLOW, flowhdlr);
    admin_pktrtr.addHandler(PacketType.FLOW_PAUSED, fphandler);
    admin_pktrtr.addHandler(PacketType.CREATE_SESSION, sessionhdlr);
    admin_pktrtr.addHandler(PacketType.DELETE_PRODUCER, prodhandler);
    admin_pktrtr.addHandler(PacketType.DESTROY_SESSION, sessionhdlr);
}
Also used : GetLicenseHandler(com.sun.messaging.jmq.jmsserver.common.handlers.GetLicenseHandler) AuthHandler(com.sun.messaging.jmq.jmsserver.common.handlers.AuthHandler) SessionHandler(com.sun.messaging.jmq.jmsserver.common.handlers.SessionHandler) VerifyDestinationHandler(com.sun.messaging.jmq.jmsserver.common.handlers.VerifyDestinationHandler) DestinationHandler(com.sun.messaging.jmq.jmsserver.data.handlers.DestinationHandler) PingHandler(com.sun.messaging.jmq.jmsserver.common.handlers.PingHandler) VerifyTransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.VerifyTransactionHandler) GoodbyeHandler(com.sun.messaging.jmq.jmsserver.common.handlers.GoodbyeHandler) ProducerHandler(com.sun.messaging.jmq.jmsserver.data.handlers.ProducerHandler) HelloHandler(com.sun.messaging.jmq.jmsserver.common.handlers.HelloHandler) DataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.DataHandler) AdminDataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler) InfoRequestHandler(com.sun.messaging.jmq.jmsserver.common.handlers.InfoRequestHandler) ConsumerHandler(com.sun.messaging.jmq.jmsserver.data.handlers.ConsumerHandler) ClientIDHandler(com.sun.messaging.jmq.jmsserver.common.handlers.ClientIDHandler) VerifyTransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.VerifyTransactionHandler) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) VerifyDestinationHandler(com.sun.messaging.jmq.jmsserver.common.handlers.VerifyDestinationHandler) FlowPausedHandler(com.sun.messaging.jmq.jmsserver.common.handlers.FlowPausedHandler) RedeliverHandler(com.sun.messaging.jmq.jmsserver.data.handlers.RedeliverHandler) QBrowseHandler(com.sun.messaging.jmq.jmsserver.data.handlers.QBrowseHandler) GenerateUIDHandler(com.sun.messaging.jmq.jmsserver.common.handlers.GenerateUIDHandler) DeliverHandler(com.sun.messaging.jmq.jmsserver.data.handlers.DeliverHandler) FlowHandler(com.sun.messaging.jmq.jmsserver.common.handlers.FlowHandler) StartStopHandler(com.sun.messaging.jmq.jmsserver.common.handlers.StartStopHandler) AckHandler(com.sun.messaging.jmq.jmsserver.data.handlers.AckHandler)

Example 2 with TransactionHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.

the class RollbackCommitHandler method handle.

/**
 * Handle the incomming administration message.
 *
 * @param con The Connection the message came in on.
 * @param cmd_msg The administration message
 * @param cmd_props The properties from the administration message
 */
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Rollback/Commit transaction " + cmd_props);
    }
    // Get the admin request message type
    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);
    // only applies to rollback request
    Boolean v = (Boolean) cmd_props.get(MessageType.JMQ_PROCESS_ACTIVE_CONSUMERS);
    boolean processActiveConsumers = (v != null && v.booleanValue());
    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) {
        TransactionList[] tls = DL.getTransactionList(null);
        TransactionList tl = null;
        for (int i = 0; i < tls.length; i++) {
            tl = tls[i];
            ts = tl.retrieveState(tid);
            if (ts == null) {
                continue;
            }
            break;
        }
        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 {
                    errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not find Xid for " + tid);
                }
                status = Status.ERROR;
            } else if (thandler == null) {
                errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not locate TransactionHandler");
                status = Status.ERROR;
            } else {
                if (requestType == MessageType.ROLLBACK_TRANSACTION) {
                    if (DEBUG) {
                        logger.log(Logger.DEBUG, "Rolling back " + tid + " in state " + ts);
                    }
                    try {
                        if (processActiveConsumers) {
                            logger.log(logger.INFO, rb.getKString(rb.I_ADMIN_REDELIVER_MSGS_ON_TXN_ROLLBACK, tid));
                            try {
                                thandler.redeliverUnacked(tl, tid, true, true, true, -1, false);
                            } catch (Exception e) {
                                logger.logStack(logger.WARNING, rb.getKString(rb.X_ADMIN_REDELIVER_MSG_ON_TXN_ROLLBACK, tid, e.getMessage()), e);
                            }
                        }
                        thandler.doRollback(tl, tid, xid, null, ts, null, con, RollbackReason.ADMIN);
                    } catch (BrokerException e) {
                        status = Status.ERROR;
                        errMsg = e.getMessage();
                    }
                } else if (requestType == MessageType.COMMIT_TRANSACTION) {
                    if (DEBUG) {
                        logger.log(Logger.DEBUG, "Committing " + tid + " in state " + ts);
                    }
                    try {
                        thandler.doCommit(tl, tid, xid, Integer.valueOf(XAResource.TMNOFLAGS), ts, null, false, con, null);
                    } catch (BrokerException e) {
                        status = Status.ERROR;
                        errMsg = e.getMessage();
                    }
                } else {
                    // Should never happen.
                    return super.handle(con, cmd_msg, cmd_props);
                }
            }
        }
    }
    sendReply(con, cmd_msg, requestType + 1, status, errMsg);
    return true;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) JMQXid(com.sun.messaging.jmq.util.JMQXid) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)

Example 3 with TransactionHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.

the class ProtocolImpl method startTransaction.

/**
 * Start a transaction.
 *
 * @param xid The Xid of the transaction to start. Required if transaction is an XA transaction. Must be null if it is
 * not an XA transaction.
 * @param xaFlags xaFlags passed on START operation. Used only if an XA transaction.
 * @param con Connection client start packet came in on (or null if internal)
 * @param type how rollback should be handled (e.g. only not prepared)
 * @param lifetime how long the transaction should live (0 == forever)
 * @return The TransactionUID started
 */
@Override
public TransactionUID startTransaction(JMQXid xid, Integer xaFlags, AutoRollbackType type, long lifetime, IMQConnection con) throws BrokerException {
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.START TRANSACTION:XID=" + xid + ", xaFlags=" + TransactionState.xaFlagToString(xaFlags) + ", type=" + type + ", lifetime=" + lifetime + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "]");
    }
    List conlist = con.getTransactionListThreadSafe();
    TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
    // allocated a TID
    TransactionUID id = null;
    TransactionList tl = null;
    if (xaFlags == null || TransactionState.isFlagSet(XAResource.TMNOFLAGS, xaFlags)) {
        id = new TransactionUID();
        TransactionList[] tls = DL.getTransactionList(con.getPartitionedStore());
        tl = tls[0];
        if (tl == null) {
            throw new BrokerException("No transaction List for connection " + con + " to start new transaction " + id + (xid == null ? "" : " XID=" + xid));
        }
    } else if (xid != null) {
        Object[] oo = TransactionList.mapXidToTid(xid, con);
        if (oo == null) {
            throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
        } else {
            tl = (TransactionList) oo[0];
            id = (TransactionUID) oo[1];
        }
    } else {
        // XID is null, something is wrong
        throw new BrokerException("Invalid xid");
    }
    if (tl == null) {
        Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
        if (oo != null) {
            tl = (TransactionList) oo[0];
        }
    }
    if (tl == null) {
        throw new BrokerException("No Transaction List found for connection " + con + " to start transaction " + id + (xid == null ? "" : " XID=" + xid));
    }
    Object o = new Object();
    handler.doStart(tl, id, conlist, con, type, xid, xid != null, lifetime, 0, xaFlags, PacketType.START_TRANSACTION, false, o.toString());
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.STARTED TRANSACTION:TID=" + id + ", XID=" + xid + ", type=" + type + ", con=" + con);
    }
    return id;
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 4 with TransactionHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.

the class ProtocolImpl method commitTransaction.

/**
 * Commit a transaction.
 *
 * @param id The TransactionUID to commit
 * @param xid The Xid of the transaction to commit. Required if transaction is an XA transaction. Must be null if it is
 * not an XA transaction.
 * @param xaFlags xaFlags passed on COMMIT operation. Used only if an XA transaction.
 * @param con Connection client commit packet came in on (or null if internal)
 */
@Override
public void commitTransaction(TransactionUID id, JMQXid xid, Integer xaFlags, IMQConnection con) throws BrokerException {
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.COMMIT TRANSACTION:TID=" + id + ", XID=" + xid + ", xaFlags=" + TransactionState.xaFlagToString(xaFlags) + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "]");
    }
    List conlist = con.getTransactionListThreadSafe();
    TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
    TransactionList tl = null;
    if (0L == id.longValue()) {
        if (xid == null) {
            throw new BrokerException("Unexpected TransactionUID  " + id);
        }
        Object[] oo = TransactionList.mapXidToTid(xid, con);
        if (oo == null) {
            id = null;
        } else {
            tl = (TransactionList) oo[0];
            id = (TransactionUID) oo[1];
        }
        if (id == null) {
            throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
        }
    }
    TransactionState ts = null;
    if (tl == null) {
        Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
        if (oo != null) {
            tl = (TransactionList) oo[0];
            ts = (TransactionState) oo[1];
        }
    }
    if (tl == null) {
        throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
    }
    if (ts == null) {
        ts = tl.retrieveState(id);
        if (ts == null) {
            throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
        }
    }
    if (xid != null) {
        if (ts.getXid() == null || !xid.equals(ts.getXid())) {
            throw new BrokerException("Transaction XID mismatch " + xid + ", expected " + ts.getXid() + " for transaction " + id);
        }
    }
    handler.doCommit(tl, id, xid, xaFlags, ts, conlist, false, con, null);
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 5 with TransactionHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.

the class ProtocolImpl method rollbackTransaction.

/**
 * Rollback a transaction
 *
 * @param id The TransactionUID to rollback
 * @param xid The Xid of the transaction to rollback. Required if transaction is an XA transaction. Must be null if it
 * is not an XA transaction.
 * @param redeliver should messages be redelivered
 * @param setRedeliver if the messages are redelivered, should the redeliver flag be set on all messages or not
 * @param con Connection client rollback packet came in on (or null if internal)
 */
@Override
public void rollbackTransaction(TransactionUID id, JMQXid xid, IMQConnection con, boolean redeliver, boolean setRedeliver, int maxRollbacks, boolean dmqOnMaxRollbacks) throws BrokerException {
    if (maxRollbacks <= 0) {
        dmqOnMaxRollbacks = !(Consumer.MSG_MAX_CONSECUTIVE_ROLLBACKS <= 0);
    }
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.ROLLBACK TRANSACTION:TID=" + id + ", XID=" + xid + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "], redeliver=" + redeliver + ", setRedeliver=" + setRedeliver);
    }
    List conlist = con.getTransactionListThreadSafe();
    TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
    TransactionList tl = null;
    if (0L == id.longValue()) {
        if (xid == null) {
            throw new BrokerException("Unexpected TransactionUID  " + id);
        }
        Object[] oo = TransactionList.mapXidToTid(xid, con);
        if (oo == null) {
            id = null;
        } else {
            tl = (TransactionList) oo[0];
            id = (TransactionUID) oo[1];
        }
        if (id == null) {
            throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
        }
    }
    TransactionState ts = null;
    if (tl == null) {
        Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
        if (oo != null) {
            tl = (TransactionList) oo[0];
            ts = (TransactionState) oo[1];
        }
    }
    if (tl == null) {
        throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
    }
    if (ts == null) {
        ts = tl.retrieveState(id);
        if (ts == null) {
            throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
        }
    }
    if (xid != null) {
        if (ts.getXid() == null || !xid.equals(ts.getXid())) {
            throw new BrokerException("Transaction XID mismatch " + xid + ", expected " + ts.getXid() + " for transaction " + id);
        }
    }
    handler.preRollback(tl, id, xid, null, /* xaFlags */
    ts);
    BrokerException bex = null;
    if (redeliver) {
        try {
            handler.redeliverUnacked(tl, id, true, setRedeliver, false, maxRollbacks, dmqOnMaxRollbacks);
        } catch (MaxConsecutiveRollbackException e) {
            bex = e;
            if (!dmqOnMaxRollbacks) {
                throw bex;
            }
        }
    }
    try {
        handler.doRollback(tl, id, xid, null, /* xaFlags */
        ts, conlist, con, RollbackReason.APPLICATION);
    } catch (BrokerException e) {
        if (bex != null) {
            throw bex;
        }
        throw e;
    }
    if (bex != null) {
        throw bex;
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) MaxConsecutiveRollbackException(com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Aggregations

TransactionHandler (com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)9 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)8 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)7 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)7 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)4 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JMQXid (com.sun.messaging.jmq.util.JMQXid)2 HAMonitorService (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)1 AuthHandler (com.sun.messaging.jmq.jmsserver.common.handlers.AuthHandler)1 ClientIDHandler (com.sun.messaging.jmq.jmsserver.common.handlers.ClientIDHandler)1 FlowHandler (com.sun.messaging.jmq.jmsserver.common.handlers.FlowHandler)1 FlowPausedHandler (com.sun.messaging.jmq.jmsserver.common.handlers.FlowPausedHandler)1 GenerateUIDHandler (com.sun.messaging.jmq.jmsserver.common.handlers.GenerateUIDHandler)1 GetLicenseHandler (com.sun.messaging.jmq.jmsserver.common.handlers.GetLicenseHandler)1 GoodbyeHandler (com.sun.messaging.jmq.jmsserver.common.handlers.GoodbyeHandler)1 HelloHandler (com.sun.messaging.jmq.jmsserver.common.handlers.HelloHandler)1 InfoRequestHandler (com.sun.messaging.jmq.jmsserver.common.handlers.InfoRequestHandler)1 PingHandler (com.sun.messaging.jmq.jmsserver.common.handlers.PingHandler)1