Search in sources :

Example 1 with XAContextException

use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.

the class XALiveContextImpl method rollback.

public synchronized void rollback() throws XAContextException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/rollback...");
    if (wasTimeout)
        throw new XAContextException(XAException.XA_RBTIMEOUT, "transaction timeout occured");
    if (closed)
        throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
    _rollback(true);
    if (registeredUsageList)
        removeUsageEntity();
    closed = true;
    rolledBack = true;
    transactions.clear();
    recoveryTransactions.clear();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/rollback done");
}
Also used : XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 2 with XAContextException

use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.

the class XARecoveryContextImpl method rollback.

public synchronized void rollback() throws XAContextException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/rollback...");
    if (closed)
        throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
    for (int i = 0; i < transactions.size(); i++) {
        Object[] wrapper = (Object[]) transactions.get(i);
        try {
            ((AbstractQueue) wrapper[0]).rollback(wrapper[1], xid, true);
            ctx.logSwiftlet.logInformation(ctx.xaSwiftlet.getName(), toString() + "rollback xid=" + signature);
        } catch (Exception e) {
            if (!ctx.queueManager.isTemporaryQueue(((AbstractQueue) wrapper[0]).getQueueName()))
                ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "rollback (two phase) xid=" + signature + ", failed for queue: " + ((AbstractQueue) wrapper[0]).getQueueName());
        }
    }
    if (liveContext != null)
        liveContext.rollback();
    removeUsageEntity();
    close();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/rollback done");
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) XAException(javax.transaction.xa.XAException) EntityAddException(com.swiftmq.mgmt.EntityAddException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 3 with XAContextException

use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.

the class XAResourceManagerSwiftletImpl method addPreparedTransaction.

/* @deprecated these are deprecated methods to ensure backward compatibility with SwiftMQ 4.x */
public synchronized void addPreparedTransaction(XidImpl xid, String queueName, QueueTransaction queueTransaction) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "addPreparedTransaction, xid=" + xid + ", queueName=" + queueName + ", queueTransaction=" + queueTransaction + " ...");
    XAContext xac = (XAContext) contexts.get(xid);
    if (xac == null) {
        xac = new XALiveContextImpl(ctx, xid, true);
        contexts.put(xid, xac);
    }
    try {
        xac.setPrepared(false);
        int id = xac.register(toString());
        xac.addTransaction(id, queueName, queueTransaction);
        xac.unregister(id, false);
        xac.setPrepared(true);
    } catch (XAContextException e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "addPreparedTransaction, exception: " + e);
        ctx.logSwiftlet.logError(getName(), "addPreparedTransaction, xid=" + xid + ", exception: " + e);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "addPreparedTransaction, xid=" + xid + ", queueName=" + queueName + ", queueTransaction=" + queueTransaction + " done");
}
Also used : XAContext(com.swiftmq.swiftlet.xa.XAContext) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 4 with XAContextException

use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.

the class XADeliveryStage method close.

public void close() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close ...");
    super.close();
    closed = true;
    if (notificationList.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify ...");
        for (Iterator iter = notificationList.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            DeliveryRequest dr = (DeliveryRequest) entry.getValue();
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify: " + dr);
            dr.callback.delivered(dr);
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify done");
        notificationList.clear();
    }
    if (outboundTransactions.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager ...");
        for (Iterator iter = outboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
            try {
                Map.Entry entry = (Map.Entry) iter.next();
                XidImpl xid = (XidImpl) entry.getKey();
                XAContext xac = ctx.xaResourceManagerSwiftlet.createXAContext(xid);
                int id = xac.register(toString());
                QueuePullTransaction t = (QueuePullTransaction) entry.getValue();
                xac.addTransaction(id, t.getQueueName(), t);
                xac.unregister(id, false);
                xac.setPrepared(true);
            } catch (XAContextException e) {
                ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager, exception: " + e);
            }
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager done");
        outboundTransactions.clear();
    }
    if (inboundTransactions.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager ...");
        for (Iterator iter = inboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
            ((Tx) ((Map.Entry) iter.next()).getValue()).handOver();
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager done");
    }
    for (Iterator iter = producers.entrySet().iterator(); iter.hasNext(); ) {
        QueueSender sender = (QueueSender) ((Map.Entry) iter.next()).getValue();
        try {
            sender.close();
        } catch (Exception e) {
        }
    }
    producers.clear();
    for (Iterator iter = consumers.entrySet().iterator(); iter.hasNext(); ) {
        QueueReceiver receiver = (QueueReceiver) ((Map.Entry) iter.next()).getValue();
        try {
            receiver.close();
        } catch (Exception e) {
        }
    }
    consumers.clear();
    if (throttleQueue != null)
        throttleQueue.close();
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.SEND_ROUTE_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.DELIVERY_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.ROUTE_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.ADJUST_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.TRANSACTION_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.COMMIT_REQ, null);
    visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.COMMIT_REPREQ, null);
}
Also used : XAContext(com.swiftmq.swiftlet.xa.XAContext) XidImpl(com.swiftmq.jms.XidImpl) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction) JMSException(javax.jms.JMSException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) QueueSender(com.swiftmq.swiftlet.queue.QueueSender) QueueReceiver(com.swiftmq.swiftlet.queue.QueueReceiver) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 5 with XAContextException

use of com.swiftmq.swiftlet.xa.XAContextException in project swiftmq-ce by iitsoftware.

the class XARecoveryStage method doRecover.

private void doRecover(List localXids, List remoteXids) {
    // Nothing to recover
    if (localXids == null && remoteXids == null) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, nothing to do");
        return;
    }
    List remoteRecoveryList = new ArrayList();
    // Check local vs remote
    if (localXids != null) {
        for (int i = 0; i < localXids.size(); i++) {
            XidImpl lXid = (XidImpl) localXids.get(i);
            if (containsXid(remoteXids, lXid)) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + lXid + "], local prepared, remote prepared, commit 1:local, 2:remote");
                // local prepared, remote prepared, commit 1:local, 2:remote
                XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(lXid);
                try {
                    xac.commit(false);
                } catch (XAContextException e) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, exception=" + e);
                    ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/doRecover, commit, exception=" + e);
                }
                ctx.xaResourceManagerSwiftlet.removeXAContext(lXid);
                remoteRecoveryList.add(new CommitRequest(lXid));
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + lXid + "], local prepared, remote unknown, rollback local");
                // local prepared, remote unknown, rollback local
                XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(lXid);
                try {
                    xac.rollback();
                } catch (XAContextException e) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, exception=" + e);
                    ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/doRecover, rollback, exception=" + e);
                }
                ctx.xaResourceManagerSwiftlet.removeXAContext(lXid);
            }
        }
    }
    // Check remote Xids not known locally
    if (remoteXids != null) {
        for (int i = 0; i < remoteXids.size(); i++) {
            XidImpl rXid = (XidImpl) remoteXids.get(i);
            if (!containsXid(localXids, rXid)) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + rXid + "], remote prepared, locally already committed, commit remote");
                // remote prepared, locally already committed, commit remote
                remoteRecoveryList.add(new CommitRequest(rXid));
            }
        }
    }
    if (remoteRecoveryList.size() > 0) {
        Collections.sort(remoteRecoveryList, new Comparator() {

            public int compare(Object o1, Object o2) {
                int i1 = ((CommitRequest) o1).getXid().getFormatId();
                int i2 = ((CommitRequest) o2).getXid().getFormatId();
                return i1 == i2 ? 0 : i1 < i2 ? -1 : 1;
            }
        });
        for (int i = 0; i < remoteRecoveryList.size(); i++) {
            CommitRequest r = (CommitRequest) remoteRecoveryList.get(i);
            routingConnection.getOutboundQueue().enqueue(r);
        }
    }
}
Also used : CommitRequest(com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest) XAContext(com.swiftmq.swiftlet.xa.XAContext) XidImpl(com.swiftmq.jms.XidImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) Comparator(java.util.Comparator)

Aggregations

XAContextException (com.swiftmq.swiftlet.xa.XAContextException)13 XAContext (com.swiftmq.swiftlet.xa.XAContext)7 XidImpl (com.swiftmq.jms.XidImpl)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)3 XAException (javax.transaction.xa.XAException)3 RequestHandler (com.swiftmq.impl.routing.single.smqpr.RequestHandler)2 StartStageRequest (com.swiftmq.impl.routing.single.smqpr.StartStageRequest)2 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest)2 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest)2 EntityAddException (com.swiftmq.mgmt.EntityAddException)2 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)2 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)2 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)2 XidFilter (com.swiftmq.swiftlet.xa.XidFilter)2 Request (com.swiftmq.tools.requestreply.Request)2 Comparator (java.util.Comparator)2 JMSException (javax.jms.JMSException)2 RecoveryReplyRequest (com.swiftmq.impl.routing.single.smqpr.v400.RecoveryReplyRequest)1