Search in sources :

Example 11 with AsyncCompletionCallback

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

the class ClusteredQueue method commit.

public void commit(final Object txId, AsyncCompletionCallback callback) {
    if (ctx.queueSpace.enabled)
        ctx.queueSpace.trace(getQueueName(), toString() + "/commit (callback), txId=" + txId);
    final ClusteredTransactionId cTxId = (ClusteredTransactionId) txId;
    cTxId.commit(new AsyncCompletionCallback(callback) {

        public synchronized void done(boolean success) {
            Long fcDelay = (Long) getResult();
            if (fcDelay != null) {
                if (ctx.queueSpace.enabled)
                    ctx.queueSpace.trace(getQueueName(), toString() + "/commit (callback), txId=" + txId + ", newDelay=" + fcDelay);
                ((ClusteredQueueFlowController) getFlowController()).setLastDelay(fcDelay.longValue());
            }
        }
    });
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback)

Example 12 with AsyncCompletionCallback

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

the class MessageQueue method acknowledgeMessages.

public void acknowledgeMessages(Object tId, List messageIndexList, AsyncCompletionCallback callback) {
    lockAndWaitAsyncFinished();
    try {
        if (!running) {
            callback.setException(new QueueException("queue " + getQueueName() + " is not running"));
            callback.notifyCallbackStack(false);
            return;
        }
        TransactionId transactionId = (TransactionId) tId;
        if (ctx.queueSpace.enabled)
            ctx.queueSpace.trace(getQueueName(), "acknowledgeMessage txId=" + transactionId + " messageIndexList=" + messageIndexList);
        final List txList = transactionId.getTxList();
        try {
            if (txList != null) {
                long size = 0;
                int n = 0;
                StoreReadTransaction srt = null;
                for (int i = 0; i < messageIndexList.size(); i++) {
                    MessageIndex messageIndex = (MessageIndex) messageIndexList.get(i);
                    for (Iterator iter = txList.iterator(); iter.hasNext(); ) {
                        StoreId storeId = (StoreId) iter.next();
                        if (storeId.equals(messageIndex)) {
                            if (pStore != null && srt == null && storeId.isPersistent())
                                srt = pStore.createReadTransaction(false);
                            size += storeId.getMsgSize();
                            n++;
                            removeMessage(srt, storeId);
                            iter.remove();
                        }
                    }
                }
                callback.setResult(Long.valueOf(size));
                if (flowController != null)
                    flowController.setReceiveMessageCount(n);
                if (srt != null) {
                    asyncActive = true;
                    srt.commit(new AsyncCompletionCallback(callback) {

                        public void done(boolean b) {
                            queueLock.lock();
                            asyncActive = false;
                            asyncFinished.signalAll();
                            queueLock.unlock();
                        }
                    });
                } else {
                    callback.notifyCallbackStack(true);
                }
            }
        } catch (Exception e) {
            callback.setException(new QueueException(e.toString()));
            callback.notifyCallbackStack(false);
            asyncActive = false;
            asyncFinished.signalAll();
            return;
        }
    } finally {
        queueLock.unlock();
    }
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) JMSException(javax.jms.JMSException)

Example 13 with AsyncCompletionCallback

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

the class MessageQueue method acknowledgeMessage.

public void acknowledgeMessage(Object tId, MessageIndex messageIndex, AsyncCompletionCallback callback) {
    lockAndWaitAsyncFinished();
    try {
        if (!running) {
            callback.setException(new QueueException("queue " + getQueueName() + " is not running"));
            callback.notifyCallbackStack(false);
            return;
        }
        TransactionId transactionId = (TransactionId) tId;
        if (ctx.queueSpace.enabled)
            ctx.queueSpace.trace(getQueueName(), "acknowledgeMessage txId=" + transactionId + " messageIndex=" + messageIndex);
        final List txList = transactionId.getTxList();
        try {
            if (txList != null) {
                StoreId storeId = null;
                for (int i = 0; i < txList.size(); i++) {
                    storeId = (StoreId) txList.get(i);
                    if (storeId.equals(messageIndex))
                        break;
                    else
                        storeId = null;
                }
                if (storeId != null) {
                    final StoreId sid = storeId;
                    callback.setResult(Long.valueOf(storeId.getMsgSize()));
                    txList.remove(sid);
                    if (flowController != null)
                        flowController.setReceiveMessageCount(1);
                    StoreReadTransaction srt = null;
                    if (pStore != null && storeId.isPersistent())
                        srt = pStore.createReadTransaction(false);
                    removeMessage(srt, storeId);
                    if (srt != null) {
                        asyncActive = true;
                        srt.commit(new AsyncCompletionCallback(callback) {

                            public void done(boolean b) {
                                queueLock.lock();
                                asyncActive = false;
                                asyncFinished.signalAll();
                                queueLock.unlock();
                            }
                        });
                    } else
                        callback.notifyCallbackStack(true);
                } else
                    // May happen that an auto-ack storeId wasn't found after a transparent reconnect
                    // but the client is waiting for a reply...
                    callback.notifyCallbackStack(true);
            }
        } catch (Exception e) {
            callback.setException(new QueueException(e.toString()));
            callback.notifyCallbackStack(false);
            asyncActive = false;
            asyncFinished.signalAll();
            return;
        }
    } finally {
        queueLock.unlock();
    }
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) JMSException(javax.jms.JMSException)

Example 14 with AsyncCompletionCallback

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

the class TopicSubscriberTransaction method commit.

protected void commit(AsyncCompletionCallback callback) {
    if (!valid) {
        callback.setException(new QueueTransactionClosedException("TopicSubscriberTransaction is invalid"));
        callback.done(false);
        return;
    }
    transaction.commit(new AsyncCompletionCallback(callback) {

        public void done(boolean success) {
            topicSubscription.removeTransaction(TopicSubscriberTransaction.this);
            valid = false;
            fcDelay = transaction.getFlowControlDelay();
            if (success)
                next.setResult(Long.valueOf(fcDelay));
            else
                next.setException(getException());
        }
    });
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback)

Example 15 with AsyncCompletionCallback

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

the class TopicSubscriberTransaction method rollback.

protected void rollback(AsyncCompletionCallback callback) {
    if (!valid) {
        callback.setException(new QueueTransactionClosedException("TopicSubscriberTransaction is invalid"));
        callback.done(false);
        return;
    }
    transaction.rollback(new AsyncCompletionCallback(callback) {

        public void done(boolean success) {
            topicSubscription.removeTransaction(TopicSubscriberTransaction.this);
            valid = false;
            if (!success)
                next.setException(getException());
        }
    });
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback)

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