Search in sources :

Example 1 with Selector

use of com.swiftmq.swiftlet.queue.Selector 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

EntityList (com.swiftmq.mgmt.EntityList)1 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)1 Selector (com.swiftmq.swiftlet.queue.Selector)1 JMSException (javax.jms.JMSException)1