Search in sources :

Example 1 with QueueLimitException

use of com.swiftmq.swiftlet.queue.QueueLimitException in project swiftmq-client by iitsoftware.

the class ReplyNE method createException.

private void createException(String className, String msg) throws Exception {
    if (className.equals("com.swiftmq.swiftlet.queue.QueueException"))
        exception = new QueueException(msg);
    else if (className.equals("com.swiftmq.swiftlet.queue.QueueLimitException"))
        exception = new QueueLimitException(msg);
    else if (className.equals("com.swiftmq.swiftlet.queue.UnknownQueueException"))
        exception = new InvalidDestinationException(msg);
    else if (className.equals("com.swiftmq.swiftlet.auth.ResourceLimitException"))
        exception = new ResourceLimitException(msg);
    else if (className.equals("com.swiftmq.swiftlet.auth.AuthenticationException"))
        exception = new AuthenticationException(msg);
    else if (className.equals("javax.jms.InvalidDestinationException"))
        exception = new InvalidDestinationException(msg);
    else
        exception = new Exception(className + ": " + msg);
}
Also used : QueueLimitException(com.swiftmq.swiftlet.queue.QueueLimitException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidDestinationException(javax.jms.InvalidDestinationException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueException(com.swiftmq.swiftlet.queue.QueueException) QueueLimitException(com.swiftmq.swiftlet.queue.QueueLimitException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException)

Example 2 with QueueLimitException

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

the class TopicTransaction method noParentTxCommit.

private long noParentTxCommit() throws Exception {
    long delay = 0;
    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 {
                    delay = Math.max(delay, sub.commit());
                } catch (QueueTransactionClosedException ignored) {
                }
            } else
                durPersSubs.add(sub);
        }
    }
    int size = durPersSubs.size();
    if (size > 0) {
        if (size == 1) {
            TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
            try {
                delay = Math.max(delay, sub.commit());
            } catch (QueueTransactionClosedException ignored) {
            }
        } else {
            int lastLocked = -1;
            boolean spaceLeft = true;
            for (int i = 0; i < size; i++) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                sub.getTransaction().lockQueue();
                lastLocked = i;
                if (!sub.getTransaction().hasSpaceLeft()) {
                    spaceLeft = false;
                    break;
                }
            }
            if (!spaceLeft) {
                for (int i = 0; i <= lastLocked; i++) {
                    TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                    sub.getTransaction().unlockQueue(false);
                }
                throw new QueueLimitException("Maximum Messages in at least one Durable Subscriber Queue reached!");
            }
            CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
            try {
                for (int i = 0; i < size; i++) {
                    TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                    try {
                        sub.getTransaction().setCompositeStoreTransaction(compositeTx);
                        delay = Math.max(delay, sub.commit());
                        sub.getTransaction().setCompositeStoreTransaction(null);
                    } catch (QueueTransactionClosedException ignored) {
                    }
                }
                compositeTx.commitTransaction();
            } finally {
                for (int i = 0; i < size; i++) {
                    TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                    sub.getTransaction().unlockQueue(false);
                }
            }
        }
    }
    subscriberTransactions = null;
    return delay;
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) QueueLimitException(com.swiftmq.swiftlet.queue.QueueLimitException) CompositeStoreTransaction(com.swiftmq.swiftlet.store.CompositeStoreTransaction) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with QueueLimitException

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

the class TopicTransaction method commit.

protected void commit(AsyncCompletionCallback callback) {
    final DelayCollector delayCollector = new DelayCollector(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()) {
                    delayCollector.incNumberCallbacks();
                    sub.commit(new AsyncCompletionCallback() {

                        public void done(boolean success) {
                            delayCollector.done(this, success);
                        }
                    });
                } else
                    durPersSubs.add(sub);
            }
        }
        final int size = durPersSubs.size();
        long delay = 0;
        if (size > 0) {
            // Only 1 subscriber, direct commit
            if (size == 1) {
                TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
                delayCollector.incNumberCallbacks();
                sub.commit(new AsyncCompletionCallback() {

                    public void done(boolean success) {
                        delayCollector.done(this, success);
                    }
                });
            } else {
                // Multiple subscriber, composite tx
                int lastLocked = -1;
                boolean spaceLeft = true;
                for (int i = 0; i < size; i++) {
                    TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                    sub.getTransaction().lockQueue();
                    lastLocked = i;
                    if (!sub.getTransaction().hasSpaceLeft()) {
                        spaceLeft = false;
                        break;
                    }
                }
                if (!spaceLeft) {
                    for (int i = 0; i <= lastLocked; i++) {
                        TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                        sub.getTransaction().unlockQueue(false);
                    }
                    callback.setException(new QueueLimitException("Maximum Messages in at least one Durable Subscriber Queue reached!"));
                    callback.notifyCallbackStack(false);
                    return;
                }
                CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
                for (int i = 0; i < size; i++) {
                    TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                    sub.getTransaction().setCompositeStoreTransaction(compositeTx);
                    try {
                        delay = Math.max(delay, sub.commit());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    sub.getTransaction().setCompositeStoreTransaction(null);
                    sub.getTransaction().unlockQueue(true);
                }
                delayCollector.incNumberCallbacks();
                AsyncCompletionCallback cb = new AsyncCompletionCallback() {

                    public void done(boolean success) {
                        for (int i = 0; i < size; i++) {
                            TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
                            sub.getTransaction().unmarkAsyncActive();
                        }
                        delayCollector.done(this, success);
                    }
                };
                cb.setResult(Long.valueOf(delay));
                compositeTx.commitTransaction(cb);
            }
        }
        subscriberTransactions = null;
    }
    delayCollector.setBlocked(false);
}
Also used : QueueLimitException(com.swiftmq.swiftlet.queue.QueueLimitException) 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)

Aggregations

QueueLimitException (com.swiftmq.swiftlet.queue.QueueLimitException)3 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)2 CompositeStoreTransaction (com.swiftmq.swiftlet.store.CompositeStoreTransaction)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)1 IOException (java.io.IOException)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1