Search in sources :

Example 1 with Status

use of com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status in project openmq by eclipse-ee4j.

the class DirectXAResource method rollback.

private synchronized void rollback(Xid foreignXid, int maxRollbacks, boolean dmqOnMaxRollbacks) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Rollback  " + printXid(foreignXid) + "), connectionId=" + connectionId);
    }
    // convert to XidImpl
    // XidImpl mqxid = new XidImpl(foreignXid);
    String methodName = "rollback()";
    if (_logFINE) {
        // +
        _loggerJX.fine(// +
        _lgrMID_INF + methodName + ":transactionId=" + this.mTransactionId);
    }
    // JMSServiceReply reply = null;
    JMSServiceReply.Status status;
    try {
        // reply = jmsservice.rollbackTransaction(this.connectionId,
        jmsservice.rollbackTransaction(this.connectionId, this.mTransactionId, foreignXid, true, true, maxRollbacks, dmqOnMaxRollbacks);
        this.setEnlisted(false);
        if (_logFINE) {
            _loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":rolled back transactionId=" + this.mTransactionId);
        }
    } catch (JMSServiceException jse) {
        status = jse.getJMSServiceReply().getStatus();
        String failure_cause = getFailureCauseAsString(status, jse);
        // XXX:tharakan:This message should be in the JMSServiceException
        String exerrmsg = "rollbackTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + ":transactionId=" + this.mTransactionId + // "and Xid:" + mqxid.toString() +
        " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(jse);
        throw xae;
    } finally {
        // finish up this resource and any others joined to it in this transaction
        boolean throwExceptionIfNotFound = false;
        DirectXAResource[] resources = DirectXAResourceMap.getXAResources(this.mXid, throwExceptionIfNotFound);
        XidImpl savedXid = this.mXid;
        for (int i = 0; i < resources.length; i++) {
            DirectXAResource xari = resources[i];
            try {
                xari.clearTransactionInfo();
            } catch (JMSException jmse) {
                _loggerJX.log(Level.SEVERE, "MQRA:DXAR:rollback:XAException-Exception=" + jmse.getMessage(), jmse);
                Debug.printStackTrace(jmse);
                XAException xae = new XAException(XAException.XAER_RMFAIL);
                xae.initCause(jmse);
                throw xae;
            }
        }
        DirectXAResourceMap.unregister(savedXid);
    }
}
Also used : XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) XidImpl(com.sun.messaging.jmq.util.XidImpl) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

Example 2 with Status

use of com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status in project openmq by eclipse-ee4j.

the class DirectXAResource method commit.

/**
 * Commit 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.
 *
 * @throws 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 + "DirectXAResource (" + this.hashCode() + ") Commit  " + printXid(foreignXid) + " (onePhase=" + onePhase + "), connectionId=" + connectionId);
    }
    // convert to XidImpl
    // XidImpl mqxid = new XidImpl(foreignXid);
    String methodName = "commit()";
    if (_logFINE) {
        // +"Xid="+mqxid.toString()
        _loggerJX.fine(// +"Xid="+mqxid.toString()
        _lgrMID_INF + methodName + ":onePhase=" + onePhase + ":transactionId=" + this.mTransactionId);
    }
    boolean rbrollback = false;
    Exception rbrollbackex = null;
    // JMSServiceReply reply = null;
    JMSServiceReply.Status status;
    try {
        // reply = jmsservice.commitTransaction(this.connectionId,
        jmsservice.commitTransaction(this.connectionId, this.mTransactionId, foreignXid, (onePhase ? XAResource.TMONEPHASE : XAResource.TMNOFLAGS));
        this.setEnlisted(false);
        if (_logFINE) {
            _loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":committed transactionId=" + this.mTransactionId);
        }
    } catch (JMSServiceException jse) {
        status = jse.getJMSServiceReply().getStatus();
        String failure_cause = getFailureCauseAsString(status, jse);
        // XXX:tharakan:This message should be in the JMSServiceException
        String exerrmsg = "commitTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and onePhase:" + onePhase + // "and Xid:" + mqxid.toString() +
        " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        if (onePhase) {
            rbrollback = true;
            rbrollbackex = jse;
        }
        if (!rbrollback) {
            XAException xae = new XAException(XAException.XAER_RMFAIL);
            xae.initCause(jse);
            throw xae;
        }
    } finally {
        if (!rbrollback) {
            // finish up this resource and any others joined to it in this transaction
            boolean throwExceptionIfNotFound = false;
            XidImpl savedXid = this.mXid;
            DirectXAResource[] resources = DirectXAResourceMap.getXAResources(this.mXid, throwExceptionIfNotFound);
            for (int i = 0; i < resources.length; i++) {
                DirectXAResource xari = resources[i];
                try {
                    xari.clearTransactionInfo();
                } catch (JMSException jmse) {
                    _loggerJX.log(Level.SEVERE, "MQRA:DXAR:commit:XAException-Exception=" + jmse.getMessage(), jmse);
                    Debug.printStackTrace(jmse);
                    XAException xae = new XAException(XAException.XAER_RMFAIL);
                    xae.initCause(jmse);
                    throw xae;
                }
            }
            DirectXAResourceMap.unregister(savedXid);
        }
    }
    if (rbrollback) {
        XAException xae;
        try {
            rollback(foreignXid, DirectXAResourceMap.MAXROLLBACKS, DirectXAResourceMap.DMQ_ON_MAXROLLBACKS);
            xae = new XAException(XAException.XA_RBROLLBACK);
            xae.initCause(rbrollbackex);
        } catch (Exception e) {
            _loggerJX.log(Level.SEVERE, "Exception on rollback transaction " + foreignXid + "[" + mTransactionId + "] after 1-phase-commit failure", e);
            xae = new XAException(XAException.XAER_RMFAIL);
            xae.initCause(rbrollbackex);
        }
        throw xae;
    }
}
Also used : XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) XidImpl(com.sun.messaging.jmq.util.XidImpl) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException) JMSException(jakarta.jms.JMSException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) XAException(javax.transaction.xa.XAException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

Example 3 with Status

use of com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status in project openmq by eclipse-ee4j.

the class DirectXAResource method recover.

/**
 * Obtain a list of prepared transaction branches from a resource manager. The transaction manager calls this method
 * during recovery to obtain the list of transaction branches that are currently in prepared or heuristically completed
 * states.
 *
 * @param flags One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be used when no other flags are set in the
 * parameter.
 *
 * @return The resource manager returns zero or more XIDs of the transaction branches that are currently in a prepared
 * or heuristically completed state. If an error occurs during the operation, the resource manager should throw the
 * appropriate XAException.
 *
 * @throws XAException If an error has occurred. Possible values are XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and
 * XAER_PROTO.
 */
@Override
public Xid[] recover(int flags) throws XAException {
    if (_logFINE) {
        // String methodName = "recover()";
        _loggerJX.fine(_lgrMID_INF + "recover():flags=" + flags + ", connectionId=" + connectionId);
    }
    javax.transaction.xa.Xid[] result = null;
    JMSServiceReply.Status status;
    try {
        result = jmsservice.recoverXATransactions(this.connectionId, flags);
    } catch (JMSServiceException jse) {
        status = jse.getJMSServiceReply().getStatus();
        String failure_cause = getFailureCauseAsString(status, jse);
        // XXX:tharakan:This message should be in the JMSServiceException
        String exerrmsg = "recoverXATransactions (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(jse);
        throw xae;
    }
    return result;
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

Example 4 with Status

use of com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status in project openmq by eclipse-ee4j.

the class DirectXAResource method prepare.

/**
 * Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 *
 * @param foreignXid A global transaction identifier.
 *
 * @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values are:
 * XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by raising an
 * appropriate XAException in the prepare method.
 *
 * @throws XAException If an error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
 * XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
@Override
public synchronized int prepare(Xid foreignXid) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Prepare     " + printXid(foreignXid) + ", connectionId=" + connectionId);
    }
    // convert to XidImpl
    // XidImpl mqxid = new XidImpl(foreignXid);
    String methodName = "prepare()";
    if (_logFINE) {
        // +
        _loggerJX.fine(// +
        _lgrMID_INF + methodName + ":transactionId=" + this.mTransactionId);
    }
    // JMS does not do RDONLY transactions
    int result = XA_OK;
    // JMSServiceReply reply = null;
    JMSServiceReply.Status status;
    try {
        // reply = jmsservice.prepareTransaction(this.connectionId,
        jmsservice.prepareTransaction(this.connectionId, this.mTransactionId, foreignXid);
        if (_logFINE) {
            _loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":prepared transactionId=" + this.mTransactionId);
        }
    } catch (JMSServiceException jse) {
        status = jse.getJMSServiceReply().getStatus();
        String failure_cause = getFailureCauseAsString(status, jse);
        // XXX:tharakan:This message should be in the JMSServiceException
        String exerrmsg = "prepareTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + // "and Xid:" + mqxid.toString() +
        " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(jse);
        throw xae;
    }
    // update the resource state
    resourceState = PREPARED;
    return result;
}
Also used : XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

Example 5 with Status

use of com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status in project openmq by eclipse-ee4j.

the class DirectXAResource method sendEndToBroker.

/**
 * Notify the broker than end() has been called
 */
public synchronized void sendEndToBroker(Xid foreignXid, int flags) throws XAException {
    // convert to XidImpl
    // XidImpl mqxid = new XidImpl(foreignXid);
    String methodName = "endToBroker()";
    if (_logFINE) {
        // +
        _loggerJX.fine(// +
        _lgrMID_INF + methodName + ":flags=" + flags + ":transactionId=" + this.mTransactionId);
    }
    // JMSServiceReply reply = null;
    JMSServiceReply.Status status;
    try {
        // reply = jmsservice.endTransaction(this.connectionId,
        jmsservice.endTransaction(this.connectionId, this.mTransactionId, foreignXid, flags);
        if (_logFINE) {
            _loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":ended transactionId=" + this.mTransactionId);
        }
    } catch (JMSServiceException jse) {
        status = jse.getJMSServiceReply().getStatus();
        String failure_cause = getFailureCauseAsString(status, jse);
        // XXX:tharakan:This message should be in the JMSServiceException
        String exerrmsg = "endTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + // "and Xid:" + mqxid.toString() +
        " and flags=" + flags + " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(jse);
        throw xae;
    }
}
Also used : XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

Aggregations

JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)5 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)5 Status (com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)5 XAException (javax.transaction.xa.XAException)5 XidImpl (com.sun.messaging.jmq.util.XidImpl)2 JMSException (jakarta.jms.JMSException)2 Xid (javax.transaction.xa.Xid)1