Search in sources :

Example 11 with QueueTransactionClosedException

use of com.swiftmq.swiftlet.queue.QueueTransactionClosedException 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 12 with QueueTransactionClosedException

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

the class TopicBroker method publishToNode.

private void publishToNode(TopicTransaction transaction, MessageImpl message, PredicateNode node, boolean publishedLocal) throws QueueException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode " + node);
    boolean isPersistent = false;
    try {
        isPersistent = message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT;
    } catch (JMSException e) {
    }
    List subs = node.getSubscriptions();
    for (int i = 0; i < subs.size(); i++) {
        // check all subs (selector, noLocal)
        TopicSubscription sub = (TopicSubscription) subs.get(i);
        if (sub != null) {
            boolean exclude = false;
            if (slowSubscriberCondition != null) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", checking slow subscriber condition: " + slowSubscriberCondition);
                try {
                    exclude = slowSubscriberCondition.isMatch(message.getJMSDeliveryMode(), sub);
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", checking slow subscriber condition: " + slowSubscriberCondition + " returns " + exclude);
                } catch (Exception e) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", exception checking slow subscriber condition: " + slowSubscriberCondition + ", exception=" + e);
                    exclude = false;
                }
            }
            if (exclude) {
                checkDisconnect(sub);
            } else {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", checking remote");
                if (!sub.isRemote() || sub.isRemote() && publishedLocal) {
                    Selector selector = sub.getSelector();
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", checking selector: " + selector);
                    if (selector == null || selector.isSelected(message)) {
                        String clientId = null;
                        try {
                            clientId = message.getStringProperty(MessageImpl.PROP_CLIENT_ID);
                        } catch (Exception ignored) {
                        }
                        String subClientId = sub.getActiveLogin() != null ? sub.getActiveLogin().getClientId() : null;
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", checking clientId: " + clientId + " subClientId: " + subClientId);
                        if ((!sub.isNoLocal()) || (sub.isNoLocal() && (clientId == null || sub.getActiveLogin() != null && !clientId.equals(subClientId)))) {
                            if (ctx.traceSpace.enabled)
                                ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", that seems ok...");
                            // check if sub has already transaction
                            TopicSubscriberTransaction subTransaction = transaction.getTopicSubscriberTransaction(sub.getBrokerSubscriberId());
                            if (subTransaction == null) {
                                if (ctx.traceSpace.enabled)
                                    ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", creating new subscriber transaction");
                                // if not, create one and store it in TopicTransaction
                                try {
                                    subTransaction = sub.createTransaction();
                                } catch (Exception e) {
                                    throw new QueueException(e.getMessage());
                                }
                                transaction.setTopicSubscriberTransaction(sub.getBrokerSubscriberId(), subTransaction);
                            }
                            // publish to subTransaction
                            try {
                                subTransaction.setPersistentMessageIncluded(isPersistent);
                                if (sub.isRemote() || sub.isForceCopy()) {
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", remote/forceCopy, therefore publish AS copy");
                                    subTransaction.publish(copyMessage(message));
                                } else {
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "publishToNode, sub=" + sub + ", publish NO copy");
                                    subTransaction.publish(message);
                                }
                            } catch (QueueTransactionClosedException qtce) {
                                transaction.setTopicSubscriberTransaction(sub.getBrokerSubscriberId(), null);
                            } catch (Exception e) {
                                throw new QueueException(e.getMessage());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) QueueException(com.swiftmq.swiftlet.queue.QueueException) JMSException(javax.jms.JMSException) EntityList(com.swiftmq.mgmt.EntityList) EntityRemoveException(com.swiftmq.mgmt.EntityRemoveException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) JMSException(javax.jms.JMSException) QueueException(com.swiftmq.swiftlet.queue.QueueException) Selector(com.swiftmq.swiftlet.queue.Selector)

Aggregations

QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)12 CompositeStoreTransaction (com.swiftmq.swiftlet.store.CompositeStoreTransaction)3 QueueException (com.swiftmq.swiftlet.queue.QueueException)2 AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)1 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 EntityAddException (com.swiftmq.mgmt.EntityAddException)1 EntityList (com.swiftmq.mgmt.EntityList)1 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)1 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)1 QueueLimitException (com.swiftmq.swiftlet.queue.QueueLimitException)1 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)1 Selector (com.swiftmq.swiftlet.queue.Selector)1 Iterator (java.util.Iterator)1 JMSException (javax.jms.JMSException)1