Search in sources :

Example 11 with QueueTransaction

use of com.swiftmq.swiftlet.queue.QueueTransaction in project swiftmq-ce by iitsoftware.

the class TransactionManager method rollback.

synchronized void rollback(boolean start) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/rollback");
    for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
        QueueTransaction t = (QueueTransaction) iter.next();
        t.rollback();
    }
    if (start)
        startTransactions();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/rollback done");
}
Also used : Iterator(java.util.Iterator) QueueTransaction(com.swiftmq.swiftlet.queue.QueueTransaction)

Example 12 with QueueTransaction

use of com.swiftmq.swiftlet.queue.QueueTransaction in project swiftmq-ce by iitsoftware.

the class XALiveContextImpl method commit.

public synchronized long commit(boolean onePhase) throws XAContextException {
    long fcDelay = 0;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " ...");
    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");
    if (rollbackOnly)
        throw new XAContextException(XAException.XA_RBROLLBACK, "XA transaction is marked as rollback-only");
    for (int i = 0; i < recoveryTransactions.size(); i++) {
        Object[] wrapper = (Object[]) recoveryTransactions.get(i);
        try {
            ((AbstractQueue) wrapper[0]).commit(wrapper[1], xid);
            ctx.logSwiftlet.logInformation(ctx.xaSwiftlet.getName(), toString() + "commit xid=" + signature);
        } catch (Exception e) {
            if (!ctx.queueManager.isTemporaryQueue(((AbstractQueue) wrapper[0]).getQueueName()))
                ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (two phase) xid=" + signature + ", failed for queue: " + ((AbstractQueue) wrapper[0]).getQueueName());
        }
    }
    if (onePhase) {
        if (prepared)
            throw new XAContextException(XAException.XAER_PROTO, "can't use one phase commit, XA transaction is in prepared state");
        for (int i = 0; i < transactions.size(); i++) {
            QueueTransaction t = (QueueTransaction) transactions.get(i);
            try {
                t.commit();
                if (t instanceof QueuePushTransaction)
                    fcDelay = Math.max(fcDelay, ((QueuePushTransaction) t).getFlowControlDelay());
            } catch (Exception e) {
                if (!ctx.queueManager.isTemporaryQueue(t.getQueueName()))
                    ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (one phase) xid=" + signature + ", failed for queue: " + t.getQueueName());
            }
        }
    } else {
        if (!prepared)
            throw new XAContextException(XAException.XAER_PROTO, "can't use two phase commit, XA transaction is not in prepared state");
        for (int i = 0; i < transactions.size(); i++) {
            QueueTransaction t = (QueueTransaction) transactions.get(i);
            try {
                t.commit(xid);
                if (t instanceof QueuePushTransaction)
                    fcDelay = Math.max(fcDelay, ((QueuePushTransaction) t).getFlowControlDelay());
            } catch (Exception e) {
                if (!ctx.queueManager.isTemporaryQueue(t.getQueueName()))
                    ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (two phase) xid=" + signature + ", failed for queue: " + t.getQueueName() + ", exception: " + e);
            }
        }
        if (registeredUsageList)
            removeUsageEntity();
    }
    closed = true;
    transactions.clear();
    recoveryTransactions.clear();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " done");
    return fcDelay;
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) XAException(javax.transaction.xa.XAException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) QueueTransaction(com.swiftmq.swiftlet.queue.QueueTransaction)

Example 13 with QueueTransaction

use of com.swiftmq.swiftlet.queue.QueueTransaction in project swiftmq-ce by iitsoftware.

the class XALiveContextImpl method _rollback.

private void _rollback(boolean reportException) {
    for (int i = 0; i < recoveryTransactions.size(); i++) {
        Object[] wrapper = (Object[]) recoveryTransactions.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());
        }
    }
    for (int i = 0; i < transactions.size(); i++) {
        QueueTransaction t = (QueueTransaction) transactions.get(i);
        try {
            if (prepared)
                t.rollback(xid, true);
            else
                t.rollback();
        } catch (Exception e) {
            if (reportException && !ctx.queueManager.isTemporaryQueue(t.getQueueName()))
                ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "rollback xid=" + signature + ", failed for queue: " + t.getQueueName() + ", exception: " + e);
        }
    }
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) XAException(javax.transaction.xa.XAException) QueueTransaction(com.swiftmq.swiftlet.queue.QueueTransaction)

Example 14 with QueueTransaction

use of com.swiftmq.swiftlet.queue.QueueTransaction in project swiftmq-ce by iitsoftware.

the class TransactionManager method commit.

synchronized void commit() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commit");
    for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
        QueueTransaction t = (QueueTransaction) iter.next();
        t.commit();
    }
    startTransactions();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commit done");
}
Also used : Iterator(java.util.Iterator) QueueTransaction(com.swiftmq.swiftlet.queue.QueueTransaction)

Example 15 with QueueTransaction

use of com.swiftmq.swiftlet.queue.QueueTransaction in project swiftmq-ce by iitsoftware.

the class TransactionManager method rollback.

synchronized void rollback(boolean start) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/rollback");
    for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
        QueueTransaction t = (QueueTransaction) iter.next();
        t.rollback();
    }
    if (start)
        startTransactions();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/rollback done");
}
Also used : Iterator(java.util.Iterator) QueueTransaction(com.swiftmq.swiftlet.queue.QueueTransaction)

Aggregations

QueueTransaction (com.swiftmq.swiftlet.queue.QueueTransaction)15 Iterator (java.util.Iterator)13 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)2 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)2 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)2 XAException (javax.transaction.xa.XAException)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)1