Search in sources :

Example 1 with XidImpl

use of com.sun.messaging.jmq.util.XidImpl 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 XidImpl

use of com.sun.messaging.jmq.util.XidImpl 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 XidImpl

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

the class XAResourceForRA method forget.

/**
 * Tells the resource manager to forget about a heuristically completed transaction branch.
 *
 * @param foreignXid A global transaction identifier.
 *
 * @exception XAException An error has occurred. Possible exception values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA,
 * XAER_INVAL, or XAER_PROTO.
 */
@Override
public void forget(Xid foreignXid) throws XAException {
    // MQ does not support heuristically completed transaction branches
    // This is a NOP
    // convert to jmq xid
    // //// JMQXid jmqXid = new JMQXid(foreignXid);
    // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:forget:txid=\n"+jmqXid.toString());
    XidImpl xidToForget = new XidImpl(foreignXid);
    XAResourceMapForRAMC.unregister(xidToForget);
    if (jmqXid != null) {
        if (jmqXid.equals(xidToForget)) {
            clearTransactionInfo();
        }
    }
}
Also used : XidImpl(com.sun.messaging.jmq.util.XidImpl)

Example 4 with XidImpl

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

the class XAResourceForRA 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);
    // Debug.println("MQRA:XAR4RA:rollback():tid="+transactionID+" xid="+jmqXid.toString());
    try {
        // send rollback w/redeliver
        if (!epConnection._isClosed()) {
            if (epConnection.isConnectedToHABroker()) {
                // handle fail-over for HA connection
                HARollback(jmqXid, maxRollbacks, dmqOnMaxRollbacks);
            } else {
                epConnection.getProtocolHandler().rollbackXA(0L, jmqXid, true, false, maxRollbacks, dmqOnMaxRollbacks);
            }
        } else {
            XAException xae = new XAException(XAException.XAER_RMFAIL);
            throw xae;
        }
    } catch (JMSException jmse) {
        // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:rollbackXAException");
        Debug.printStackTrace(jmse);
        XAException xae = new XAException(XAException.XAER_RMFAIL);
        xae.initCause(jmse);
        throw xae;
    } finally {
        // 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) {
                Debug.printStackTrace(jmse);
                XAException xae = new XAException(XAException.XAER_RMFAIL);
                xae.initCause(jmse);
                throw xae;
            }
        }
        XAResourceMapForRAMC.unregister(savedXid);
    }
    // if (this.isXATracking()) {
    // xaTable.remove(jmqXid);
    // }
    this.removeXid(jmqXid);
}
Also used : XidImpl(com.sun.messaging.jmq.util.XidImpl) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Example 5 with XidImpl

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

the class XAResourceForRA 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);
    // Debug.println("MQRA:XAR4RA:commit():onePhase="+onePhase+" tid="+transactionID+" xid="+jmqXid.toString());
    if (onePhase && setRollback) {
        // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:commit1p:forcing Rollback due to:" + rollbackCause.getMessage());
        Debug.printStackTrace(rollbackCause);
        XAException xae = new XAException(XAException.XAER_RMFAIL);
        xae.initCause(rollbackCause);
        throw xae;
    }
    boolean checkrollback = false;
    boolean rbrollback = false;
    Exception rbrollbackex = null;
    try {
        if (!epConnection._isClosed()) {
            if (onePhase) {
                // one phase commit
                if (epConnection.isConnectedToHABroker()) {
                    // use two phase protocol for HA
                    HAOnePhaseCommit(foreignXid, jmqXid);
                } else {
                    try {
                        epConnection.getProtocolHandler().commit(0L, XAResource.TMONEPHASE, jmqXid);
                    } catch (JMSException e) {
                        checkrollback = true;
                        throw e;
                    }
                }
            } else {
                // two phase commit
                if (epConnection.isConnectedToHABroker()) {
                    // HA case
                    this.HATwoPhaseCommit(jmqXid);
                } else {
                    // non-HA
                    epConnection.getProtocolHandler().commit(0L, XAResource.TMNOFLAGS, jmqXid);
                }
            }
        } else {
            System.err.println("MQRA:XARFRA: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 (Exception jmse) {
        // check remote exception.
        if (jmse instanceof RemoteAcknowledgeException) {
            // notify session that re-create consumer is required.
            RemoteAcknowledgeException rae = (RemoteAcknowledgeException) jmse;
            XASessionImpl session = (XASessionImpl) omr.getEndpointConsumer().getXASession();
            session.notifyRemoteAcknowledgeException(rae);
            if (checkrollback) {
                rbrollbackex = jmse;
                rbrollback = true;
            }
        }
        this.epConnection.waitForReconnecting(jmse);
        // Debug.println("*=*=*=*=*=*=*=*=*=*=XAR:commitXAException");
        Debug.printStackTrace(jmse);
        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) {
                    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 : XidImpl(com.sun.messaging.jmq.util.XidImpl) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Aggregations

XidImpl (com.sun.messaging.jmq.util.XidImpl)10 JMSException (jakarta.jms.JMSException)6 XAException (javax.transaction.xa.XAException)6 JMQXid (com.sun.messaging.jmq.util.JMQXid)4 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)2 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)2 Status (com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)2 JMSRASessionAdapter (com.sun.messaging.jms.ra.api.JMSRASessionAdapter)2 JMSRAXASession (com.sun.messaging.jms.ra.api.JMSRAXASession)1