Search in sources :

Example 1 with AsyncCompletionCallback

use of com.swiftmq.tools.concurrent.AsyncCompletionCallback 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 2 with AsyncCompletionCallback

use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.

the class StoreReadTransactionImpl method commit.

public void commit(AsyncCompletionCallback callback) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit...");
    AsyncCompletionCallback localCallback = createLocalCallback(callback);
    if (checkClosedAsync(localCallback))
        return;
    txId = ctx.transactionManager.createTxId();
    journal = new ArrayList();
    queueIndex.setJournal(journal);
    try {
        for (int i = 0; i < keys.size(); i++) {
            addMessagePageReference(queueIndex.remove((QueueIndexEntry) keys.get(i)));
        }
    } catch (Exception e) {
        e.printStackTrace();
        localCallback.setException(e);
        localCallback.notifyCallbackStack(false);
        return;
    }
    keys.clear();
    if (journal != null && journal.size() > 0) {
        try {
            ctx.recoveryManager.commit(new CommitLogRecord(txId, null, journal, this, localCallback, messagePageRefs));
        } catch (Exception e) {
            localCallback.setException(new StoreException(e.toString()));
            localCallback.notifyCallbackStack(false);
        }
    } else
        localCallback.notifyCallbackStack(true);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit...done.");
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) QueueIndexEntry(com.swiftmq.impl.store.standard.index.QueueIndexEntry) StoreException(com.swiftmq.swiftlet.store.StoreException) IOException(java.io.IOException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 3 with AsyncCompletionCallback

use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.

the class CompositeStoreTransactionImpl method abortTransaction.

public void abortTransaction(AsyncCompletionCallback callback) {
    AsyncCompletionCallback localCallback = createLocalCallback(callback);
    checkClosedAsync(localCallback);
    if (localCallback.isNotified())
        return;
    boolean doNotify = true;
    if (journal != null && journal.size() > 0) {
        try {
            doNotify = false;
            if (keysRemoved != null && markRedelivered)
                ctx.recoveryManager.abort(new AbortLogRecord(txId, null, journal, this, null));
            else
                ctx.recoveryManager.abort(new AbortLogRecord(txId, null, journal, this, localCallback));
        } catch (Exception e) {
            localCallback.setException(new StoreException(e.toString()));
            localCallback.notifyCallbackStack(false);
            removeTxId();
            return;
        }
    }
    if (keysRemoved != null && markRedelivered) {
        List newJournal = new ArrayList();
        try {
            for (int i = 0; i < keysRemoved.size(); i++) {
                RemovedKeyEntry entry = keysRemoved.get(i);
                entry.queueIndex.setJournal(newJournal);
                entry.queueIndex.incDeliveryCount(entry.key);
            }
            doNotify = false;
            // don't wonder, we are committing the redelivered settings
            ctx.recoveryManager.commit(new CommitLogRecord(txId, null, newJournal, this, localCallback, null));
        } catch (Exception e) {
            localCallback.setException(new StoreException(e.toString()));
            localCallback.notifyCallbackStack(false);
            removeTxId();
            return;
        }
    }
    if (doNotify)
        callback.notifyCallbackStack(true);
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AbortLogRecord(com.swiftmq.impl.store.standard.log.AbortLogRecord) StoreException(com.swiftmq.swiftlet.store.StoreException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 4 with AsyncCompletionCallback

use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.

the class CompositeStoreTransactionImpl method commitTransaction.

public void commitTransaction(AsyncCompletionCallback callback) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit (callback) ...");
    AsyncCompletionCallback localCallback = createLocalCallback(callback);
    checkClosedAsync(localCallback);
    if (localCallback.isNotified())
        return;
    try {
        List<MessagePageReference> messagePageRefs = processRemovedKeys();
        if (journal != null && journal.size() > 0)
            ctx.recoveryManager.commit(new CommitLogRecord(txId, null, journal, this, localCallback, messagePageRefs));
        else {
            localCallback.notifyCallbackStack(true);
            removeTxId();
        }
    } catch (Exception e) {
        localCallback.setException(new StoreException(e.toString()));
        localCallback.notifyCallbackStack(false);
        removeTxId();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit (callback) ... done.");
}
Also used : MessagePageReference(com.swiftmq.impl.store.standard.index.MessagePageReference) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) StoreException(com.swiftmq.swiftlet.store.StoreException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 5 with AsyncCompletionCallback

use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.

the class AMQPHandler method visit.

public void visit(POSendClose po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    CloseFrame frame = new CloseFrame(0);
    if (po.getErrorCondition() != null) {
        com.swiftmq.amqp.v100.generated.transport.definitions.Error error = new Error();
        error.setCondition(po.getErrorCondition());
        if (po.getDescription() != null)
            error.setDescription(po.getDescription());
        frame.setError(error);
        connectionDisabled = true;
    }
    frame.setCallback(new AsyncCompletionCallback() {

        public void done(boolean b) {
            ctx.networkSwiftlet.getConnectionManager().removeConnection(versionedConnection.getConnection());
        }
    });
    versionedConnection.send(frame);
    closeFrameSent = true;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : Error(com.swiftmq.amqp.v100.generated.transport.definitions.Error) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) ConnectionError(com.swiftmq.amqp.v100.generated.transport.definitions.ConnectionError) Error(com.swiftmq.amqp.v100.generated.transport.definitions.Error) AmqpError(com.swiftmq.amqp.v100.generated.transport.definitions.AmqpError)

Aggregations

AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)18 ArrayList (java.util.ArrayList)5 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)4 List (java.util.List)4 JMSException (javax.jms.JMSException)4 CommitLogRecord (com.swiftmq.impl.store.standard.log.CommitLogRecord)3 StoreException (com.swiftmq.swiftlet.store.StoreException)3 MessagePageReference (com.swiftmq.impl.store.standard.index.MessagePageReference)2 QueueLimitException (com.swiftmq.swiftlet.queue.QueueLimitException)2 CompositeStoreTransaction (com.swiftmq.swiftlet.store.CompositeStoreTransaction)2 AmqpError (com.swiftmq.amqp.v100.generated.transport.definitions.AmqpError)1 ConnectionError (com.swiftmq.amqp.v100.generated.transport.definitions.ConnectionError)1 Error (com.swiftmq.amqp.v100.generated.transport.definitions.Error)1 CacheReleaseListener (com.swiftmq.impl.store.standard.cache.CacheReleaseListener)1 QueueIndexEntry (com.swiftmq.impl.store.standard.index.QueueIndexEntry)1 AbortLogRecord (com.swiftmq.impl.store.standard.log.AbortLogRecord)1 MessageImpl (com.swiftmq.jms.MessageImpl)1 Semaphore (com.swiftmq.tools.concurrent.Semaphore)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1