Search in sources :

Example 1 with CompositeStoreTransaction

use of com.swiftmq.swiftlet.store.CompositeStoreTransaction in project swiftmq-ce by iitsoftware.

the class TopicTransaction method rollback.

protected void rollback() throws Exception {
    if (subscriberTransactions == null)
        return;
    List durPersSubs = new ArrayList(subscriberTransactions.length);
    for (int i = 0; i < subscriberTransactions.length; i++) {
        TopicSubscriberTransaction sub = subscriberTransactions[i];
        if (sub != null) {
            TopicSubscription subscription = sub.getTopicSubscription();
            if (subscription.isRemote() || !subscription.isDurable() || !sub.isPersistentMessageIncluded()) {
                try {
                    sub.rollback();
                } catch (QueueTransactionClosedException ignored) {
                }
            } else
                durPersSubs.add(sub);
        }
    }
    int size = durPersSubs.size();
    if (size > 0) {
        if (size == 1) {
            TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
            try {
                sub.rollback();
            } catch (QueueTransactionClosedException ignored) {
            }
        } else {
            for (int i = 0; i < size; i++) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                sub.getTransaction().lockQueue();
            }
            CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
            for (int i = 0; i < size; i++) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                try {
                    sub.getTransaction().setCompositeStoreTransaction(compositeTx);
                    sub.rollback();
                    sub.getTransaction().setCompositeStoreTransaction(null);
                } catch (QueueTransactionClosedException ignored) {
                }
            }
            compositeTx.commitTransaction();
            for (int i = 0; i < size; i++) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                sub.getTransaction().unlockQueue(false);
            }
        }
    }
    subscriberTransactions = null;
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with CompositeStoreTransaction

use of com.swiftmq.swiftlet.store.CompositeStoreTransaction in project swiftmq-ce by iitsoftware.

the class TopicTransaction method rollback.

protected void rollback(AsyncCompletionCallback callback) {
    final RollbackJoin join = new RollbackJoin(callback);
    if (subscriberTransactions != null) {
        final List durPersSubs = new ArrayList(subscriberTransactions.length);
        for (int i = 0; i < subscriberTransactions.length; i++) {
            TopicSubscriberTransaction sub = subscriberTransactions[i];
            if (sub != null) {
                TopicSubscription subscription = sub.getTopicSubscription();
                if (subscription.isRemote() || !subscription.isDurable() || !sub.isPersistentMessageIncluded()) {
                    join.incNumberCallbacks();
                    sub.rollback(new RollbackCallback(join));
                } else
                    durPersSubs.add(sub);
            }
        }
        final int size = durPersSubs.size();
        if (size > 0) {
            if (size == 1) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
                join.incNumberCallbacks();
                sub.rollback(new RollbackCallback(join));
            } else {
                for (int i = 0; i < size; i++) {
                    TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                    sub.getTransaction().lockQueue();
                }
                CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
                for (int i = 0; i < size; i++) {
                    TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                    try {
                        sub.getTransaction().setCompositeStoreTransaction(compositeTx);
                        sub.rollback();
                        sub.getTransaction().setCompositeStoreTransaction(null);
                        sub.getTransaction().unlockQueue(true);
                    } catch (Exception ignored) {
                    }
                }
                join.incNumberCallbacks();
                compositeTx.commitTransaction(new AsyncCompletionCallback() {

                    public void done(boolean success) {
                        for (int i = 0; i < size; i++) {
                            TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                            sub.getTransaction().unmarkAsyncActive();
                        }
                        join.done(this, success);
                    }
                });
            }
        }
        subscriberTransactions = null;
    }
    join.setBlocked(false);
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) QueueLimitException(com.swiftmq.swiftlet.queue.QueueLimitException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException)

Example 3 with CompositeStoreTransaction

use of com.swiftmq.swiftlet.store.CompositeStoreTransaction in project swiftmq-ce by iitsoftware.

the class TransactionManager method commitWithGlobalLock.

private void commitWithGlobalLock() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, transactions.size=" + transactions.size());
    CompositeStoreTransaction compTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
    compTx.setReferencable(false);
    ctx.queueManager.lockMultiQueue();
    lock();
    try {
        for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
            Pair p = (Pair) iter.next();
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, t=" + p.tx + ", closed=" + p.tx.isClosed());
            try {
                p.tx.setCompositeStoreTransaction(compTx);
                p.tx.commit();
                p.tx.setCompositeStoreTransaction(null);
            } catch (QueueTransactionClosedException e) {
                // Happens when temp queues have been deleted meanwhile
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, t=" + p.tx + ", QueueTransactionClosedException, remove");
                iter.remove();
                p.tx.unlockQueue(false);
            }
        }
        compTx.commitTransaction();
    } finally {
        unlock();
        ctx.queueManager.unlockMultiQueue();
        startTransactions();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock done");
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) Iterator(java.util.Iterator)

Example 4 with CompositeStoreTransaction

use of com.swiftmq.swiftlet.store.CompositeStoreTransaction in project swiftmq-ce by iitsoftware.

the class StreamContext method commitTransactionsGlobalLock.

public void commitTransactionsGlobalLock() throws Exception {
    notifyTransactionFlushListeners();
    CompositeStoreTransaction compTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
    compTx.setReferencable(false);
    try {
        ctx.queueManager.lockMultiQueue();
        lock();
        for (int i = 0; i < queueTransactions.size(); i++) {
            Entry entry = queueTransactions.get(i);
            entry.transaction.setCompositeStoreTransaction(compTx);
            entry.transaction.commit();
            entry.transaction.setCompositeStoreTransaction(null);
        }
        compTx.commitTransaction();
    } finally {
        try {
            unlock();
        } catch (Exception e) {
        }
        ctx.queueManager.unlockMultiQueue();
    }
    for (int i = 0; i < queueTransactions.size(); i++) {
        Entry entry = queueTransactions.get(i);
        if (entry.listener != null)
            entry.listener.transactionFinished();
    }
    queueTransactions.clear();
}
Also used : CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 5 with CompositeStoreTransaction

use of com.swiftmq.swiftlet.store.CompositeStoreTransaction in project swiftmq-ce by iitsoftware.

the class ClusteredTransactionId method getCompositeStoreTransaction.

public CompositeStoreTransaction getCompositeStoreTransaction() {
    CompositeStoreTransaction ct = null;
    if (messageBasedDispatch) {
        for (Iterator iter = queueMap.entrySet().iterator(); iter.hasNext(); ) {
            Entry entry = (Entry) ((Map.Entry) iter.next()).getValue();
            ct = entry.abstractQueue.getCompositeStoreTransaction(entry.transaction);
            break;
        }
    } else {
        if (baseQueue == null)
            return null;
        ct = baseQueue.getCompositeStoreTransaction(baseTx);
    }
    return ct;
}
Also used : CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CompositeStoreTransaction (com.swiftmq.swiftlet.store.CompositeStoreTransaction)7 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 QueueLimitException (com.swiftmq.swiftlet.queue.QueueLimitException)3 AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)2 Iterator (java.util.Iterator)2 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1