Search in sources :

Example 1 with JMSRAXASession

use of com.sun.messaging.jms.ra.api.JMSRAXASession in project openmq by eclipse-ee4j.

the class XAResourceForMC method rollback.

/**
 * @param maxRollbacks maximum number of consecutive rollbacks allowed for active consumers
 * @param dmqOnMaxRollbacks if true, place the consumed message on DMQ if maxRollbacks reached
 */
private synchronized void rollback(Xid foreignXid, int maxRollbacks, boolean dmqOnMaxRollbacks) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "XAResourceForMC (" + this.hashCode() + ") Rollback  " + printXid(foreignXid) + ")");
    }
    // convert to jmq xid
    JMQXid jmqXid = new JMQXid(foreignXid);
    // System.out.println("MQRA:XAR4MC:rollback():mcId="+mc.getMCId()+":xid="+jmqXid.toString());
    // Debug.println("MQRA:XAR4RA:rollback():tid="+transactionID+" xid="+jmqXid.toString());
    JMSRAXASession xas = null;
    JMSRASessionAdapter sa = null;
    try {
        // send rollback w/redeliver
        if (!epConnection._isClosed()) {
            // System.out.println("MQRA:XAR4MC:rollback:Using epCon");
            sa = mc.getConnectionAdapter().getJMSRASessionAdapter();
            if (epConnection.isConnectedToHABroker()) {
                // handle fail-over for HA connection
                HARollback(jmqXid, maxRollbacks, dmqOnMaxRollbacks);
            } else {
                epConnection.getProtocolHandler().rollbackXA(0L, jmqXid, true, false, maxRollbacks, dmqOnMaxRollbacks);
            }
            if (sa != null) {
                // System.out.println("MQRA:XAR4MC:rollback:sa!=null");
                // sa.getXASession().finishXATransactionForMC();
                sa.getJMSRAXASession().finishXATransactionForMC();
            }
            active = false;
        } else {
            System.err.println("MQRA:XARFMC:rollback:ConnectionClosed:Rollback txn:xid=" + jmqXid.toString());
            // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:prepare:XAException:RMFAIL");
            XAException xae = new XAException(XAException.XAER_RMFAIL);
            throw xae;
        }
    } catch (Exception jmse) {
        System.err.println("MQRA:XARFMC:rollback:XAException-Exception=" + jmse.getMessage());
        // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:rollbackXAException");
        Debug.printStackTrace(jmse);
        XAException xae = new XAException(XAException.XAER_RMFAIL);
        xae.initCause(jmse);
        throw xae;
    } finally {
        if (sa != null) {
            xas = sa.getJMSRAXASession();
            if (xas != null) {
                xas.setFailoverOccurred(false);
            }
        }
        // finish up this resource and any others joined to it in this transaction
        boolean throwExceptionIfNotFound = false;
        XidImpl savedXid = this.jmqXid;
        XAResourceForJMQ[] resources = XAResourceMapForRAMC.getXAResources(this.jmqXid, throwExceptionIfNotFound);
        for (int i = 0; i < resources.length; i++) {
            XAResourceForJMQ xari = resources[i];
            try {
                xari.clearTransactionInfo();
            } catch (JMSException jmse) {
                System.err.println("MQRA:XARFMC:rollback:XAException-Exception=" + jmse.getMessage());
                Debug.printStackTrace(jmse);
                XAException xae = new XAException(XAException.XAER_RMFAIL);
                xae.initCause(jmse);
                throw xae;
            }
        }
        XAResourceMapForRAMC.unregister(savedXid);
    }
    this.removeXid(jmqXid);
}
Also used : JMSRASessionAdapter(com.sun.messaging.jms.ra.api.JMSRASessionAdapter) XAException(javax.transaction.xa.XAException) XidImpl(com.sun.messaging.jmq.util.XidImpl) JMSException(jakarta.jms.JMSException) JMQXid(com.sun.messaging.jmq.util.JMQXid) JMSRAXASession(com.sun.messaging.jms.ra.api.JMSRAXASession) JMSException(jakarta.jms.JMSException) XAException(javax.transaction.xa.XAException)

Aggregations

JMQXid (com.sun.messaging.jmq.util.JMQXid)1 XidImpl (com.sun.messaging.jmq.util.XidImpl)1 JMSRASessionAdapter (com.sun.messaging.jms.ra.api.JMSRASessionAdapter)1 JMSRAXASession (com.sun.messaging.jms.ra.api.JMSRAXASession)1 JMSException (jakarta.jms.JMSException)1 XAException (javax.transaction.xa.XAException)1