Search in sources :

Example 1 with JMSRASessionAdapter

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

the class XAResourceForMC method commit.

/**
 * Commits the global transaction specified by xid.
 *
 * @param foreignXid A global transaction identifier
 *
 * @param onePhase If true, the resource manager should use a one-phase commit protocol to commit the work done on
 * behalf of xid.
 *
 * @exception XAException An error has occurred. Possible XAExceptions are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB,
 * XA_HEURMIX, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 *
 * <P>
 * If the resource manager did not commit the transaction and the parameter onePhase is set to true, the resource
 * manager may throw one of the XA_RB* exceptions. Upon return, the resource manager has rolled back the branch's work
 * and has released all held resources.
 */
@Override
public synchronized void commit(Xid foreignXid, boolean onePhase) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "XAResourceForMC (" + this.hashCode() + ") Commit  " + printXid(foreignXid) + " (onePhase=" + onePhase + ")");
    }
    // convert to jmq xid
    JMQXid jmqXid = new JMQXid(foreignXid);
    // System.out.println("MQRA:XAR4MC:commit():mcId="+mc.getMCId()+":onePhase="+onePhase+" tid="+transactionID+"
    // xid="+jmqXid.toString());
    // Debug.println("MQRA:XAR4RA:commit():onePhase="+onePhase+" tid="+transactionID+" xid="+jmqXid.toString());
    boolean checkrollback = false;
    boolean rbrollback = false;
    Exception rbrollbackex = null;
    try {
        if (!epConnection._isClosed()) {
            if (onePhase) {
                if (epConnection.isConnectedToHABroker()) {
                    HAOnePhaseCommit(foreignXid, jmqXid);
                } else {
                    try {
                        epConnection.getProtocolHandler().commit(0L, XAResource.TMONEPHASE, jmqXid);
                    } catch (JMSException e) {
                        checkrollback = true;
                        throw e;
                    }
                }
            } else {
                if (epConnection.isConnectedToHABroker()) {
                    this.HATwoPhaseCommit(jmqXid);
                } else {
                    epConnection.getProtocolHandler().commit(0L, XAResource.TMNOFLAGS, jmqXid);
                }
            }
            JMSRASessionAdapter sa = mc.getConnectionAdapter().getJMSRASessionAdapter();
            if (sa != null) {
                // System.out.println("MQRA:XAR4MC:commit:sa!=null");
                sa.getJMSRAXASession().finishXATransactionForMC();
            }
            active = false;
        } else {
            System.err.println("MQRA:XARFMC:commit:ConnectionClosed:throw XAExc txn:1p=" + onePhase + ":xid=" + jmqXid.toString());
            // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:commit:XAException");
            XAException xae = new XAException(XAException.XAER_RMFAIL);
            throw xae;
        }
    } catch (XAException xaexception) {
        throw xaexception;
    } catch (Exception jmse) {
        System.err.println("MQRA:XARFMC:commit:XAException-Exception=" + jmse.getMessage());
        Debug.printStackTrace(jmse);
        if (jmse instanceof RemoteAcknowledgeException) {
            if (checkrollback) {
                rbrollbackex = jmse;
                rbrollback = true;
            }
        }
        if (!rbrollback && checkrollback && (jmse instanceof JMSException)) {
            if (((JMSException) jmse).getErrorCode().equals(ClientResources.X_SERVER_ERROR)) {
                Exception e1 = ((JMSException) jmse).getLinkedException();
                if (e1 instanceof JMSException && !((JMSException) e1).getErrorCode().equals(Status.getString(Status.NOT_FOUND))) {
                    SessionImpl.sessionLogger.log(Level.WARNING, "Exception on 1-phase commit transaction " + jmqXid + ", will rollback", jmse);
                    rbrollbackex = jmse;
                    rbrollback = true;
                }
            }
        }
        if (!rbrollback) {
            XAException xae = new XAException(XAException.XAER_RMFAIL);
            xae.initCause(jmse);
            throw xae;
        }
    } finally {
        if (!rbrollback) {
            // 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:commit:XAException-Exception=" + jmse.getMessage());
                    Debug.printStackTrace(jmse);
                    XAException xae = new XAException(XAException.XAER_RMFAIL);
                    xae.initCause(jmse);
                    throw xae;
                }
            }
            XAResourceMapForRAMC.unregister(savedXid);
        }
    }
    if (!rbrollback) {
        this.removeXid(jmqXid);
        return;
    }
    XAException xae;
    try {
        rollback(foreignXid, XAResourceMap.MAXROLLBACKS, XAResourceMap.DMQ_ON_MAXROLLBACKS);
        xae = new XAException(XAException.XA_RBROLLBACK);
        xae.initCause(rbrollbackex);
    } catch (Exception e) {
        SessionImpl.sessionLogger.log(Level.SEVERE, "Exception on rollback transaction " + jmqXid + " after 1-phase-commit failure", e);
        xae = new XAException(XAException.XAER_RMFAIL);
        xae.initCause(rbrollbackex);
    }
    throw xae;
}
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) JMSException(jakarta.jms.JMSException) XAException(javax.transaction.xa.XAException)

Example 2 with JMSRASessionAdapter

use of com.sun.messaging.jms.ra.api.JMSRASessionAdapter 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)

Example 3 with JMSRASessionAdapter

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

the class XAResourceForMC method start.

/**
 * Starts work on behalf of a transaction branch specified in <code>foreignXid</code>.
 *
 * If TMJOIN is specified, the start applies to joining a transaction previously seen by the resource manager. If
 * TMRESUME is specified, the start applies to resuming a suspended transaction specified in the parameter
 * <code>foreignXid</code>.
 *
 * If neither TMJOIN nor TMRESUME is specified and the transaction specified by <code>foreignXid</code> has previously
 * been seen by the resource manager, the resource manager throws the XAException exception with XAER_DUPID error code.
 *
 * @param foreignXid A global transaction identifier to be associated with the resource.
 *
 * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME.
 *
 * @exception XAException An error has occurred. Possible exceptions are XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_DUPID,
 * XAER_OUTSIDE, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
@Override
public synchronized void start(Xid foreignXid, int flags) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "XAResourceForMC (" + this.hashCode() + ") Start   " + printXid(foreignXid) + printFlags(flags));
    }
    // convert to jmq xid
    JMQXid jmqXid = new JMQXid(foreignXid);
    // otherwise send the START to the broker only if this is not a TMRESUME
    if (!isResume(flags) || JMSRAResourceAdapter.isRevert6882044()) {
        try {
            transactionID = epConnection.protocolHandler.startTransaction(transactionID, flags, jmqXid);
            this.jmqXid = jmqXid;
            // System.out.println("MQRA:XAR4MC:start:transactionID="+transactionID+" xid="+jmqXid.toString());
            JMSRASessionAdapter sa = mc.getConnectionAdapter().getJMSRASessionAdapter();
            if (sa != null) {
                // System.out.println("MQRA:XAR4MC:start():sa!=null");
                sa.getJMSRAXASession().initXATransactionForMC(transactionID);
            }
        } catch (Exception jmse) {
            System.err.println("MQRA:XARFMC:start:XAException-Exception=" + jmse.getMessage());
            Debug.printStackTrace(jmse);
            XAException xae = new XAException(XAException.XAER_RMFAIL);
            xae.initCause(jmse);
            throw xae;
        }
        XAResourceMapForRAMC.register(jmqXid, this, isJoin(flags));
    }
    started = true;
    active = true;
    // update the resource state
    resourceState = STARTED;
    // add xa state to table
    if (isXATracking()) {
        xaTable.put(jmqXid, XAResourceForRA.XA_START);
    }
}
Also used : JMSRASessionAdapter(com.sun.messaging.jms.ra.api.JMSRASessionAdapter) XAException(javax.transaction.xa.XAException) JMQXid(com.sun.messaging.jmq.util.JMQXid) JMSException(jakarta.jms.JMSException) XAException(javax.transaction.xa.XAException)

Example 4 with JMSRASessionAdapter

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

the class XAResourceForMC method sendEndToBroker.

private void sendEndToBroker(int flags, boolean jmqnoop, JMQXid jmqXid) throws XAException {
    try {
        // System.out.println("MQRA:XAR4RA:end:sending 0L:tid="+transactionID+" xid="+jmqXid.toString());
        epConnection.protocolHandler.endTransaction(0L, jmqnoop, flags, jmqXid);
        JMSRASessionAdapter sa = mc.getConnectionAdapter().getJMSRASessionAdapter();
        if (sa != null) {
            // System.out.println("MQRA:XAR4MC:end:sa!=null");
            sa.getJMSRAXASession().finishXATransactionForMC();
        }
    } catch (Exception jmse) {
        System.err.println("MQRA:XARFMC:end:XAException-Exception=" + jmse.getMessage());
        // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:end:XAException");
        Debug.printStackTrace(jmse);
        XAException xae = new XAException(XAException.XAER_RMFAIL);
        xae.initCause(jmse);
        throw xae;
    }
}
Also used : JMSRASessionAdapter(com.sun.messaging.jms.ra.api.JMSRASessionAdapter) XAException(javax.transaction.xa.XAException) JMSException(jakarta.jms.JMSException) XAException(javax.transaction.xa.XAException)

Aggregations

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