Search in sources :

Example 16 with QueueException

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

the class TopicSubscriberTransaction method commit.

protected long commit(XidImpl globalTxId) throws Exception {
    if (!valid)
        throw new QueueTransactionClosedException("TopicSubscriberTransaction is invalid");
    try {
        transaction.commit(globalTxId);
    } catch (QueueException e) {
        if (transaction.isQueueRunning())
            throw e;
    }
    topicSubscription.removeTransaction(this);
    valid = false;
    return transaction.getFlowControlDelay();
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 17 with QueueException

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

the class TopicBroker method putMessage.

public void putMessage(Object transactionId, MessageImpl msg) throws QueueException {
    lockAndWaitAsyncFinished();
    try {
        if (subscriptions.size() == 0)
            return;
        TopicTransaction transaction = (TopicTransaction) transactionId;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "putMessage, transaction=" + transaction + ", message=" + msg);
        // set dest queue for routing
        if (msg.getDestQueue() == null) {
            String s = getQueueName();
            msg.setDestQueue(s.substring(0, s.indexOf('@')));
        }
        String topicName = null;
        // local msgs haven't set a source router
        boolean publishedLocal = msg.getSourceRouter() == null;
        try {
            TopicImpl topic = (TopicImpl) msg.getJMSDestination();
            topicName = topic.getTopicName();
        } catch (Exception ignored) {
        }
        String[] tokenizedPubTopic = topicName.indexOf(TopicManagerImpl.TOPIC_DELIMITER_CHAR) == -1 ? rootTokenized : ctx.topicManager.tokenizeTopicName(topicName);
        List matchedNodes = null;
        if (ctx.topicManager.isDirectSubscriberSelection())
            matchedNodes = getMatchedNodes(tokenizedPubTopic);
        else
            matchedNodes = getMatchedNodes(getMatchedTopics(tokenizedPubTopic));
        if (matchedNodes != null) {
            for (int i = 0; i < matchedNodes.size(); i++) {
                PredicateNode node = (PredicateNode) matchedNodes.get(i);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "putMessage, node: " + node + " does match");
                publishToNode(transaction, msg, node, publishedLocal);
            }
        }
    } finally {
        lock.unlock();
    }
}
Also used : EntityList(com.swiftmq.mgmt.EntityList) TopicImpl(com.swiftmq.jms.TopicImpl) EntityRemoveException(com.swiftmq.mgmt.EntityRemoveException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) JMSException(javax.jms.JMSException) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 18 with QueueException

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

the class TopicBroker method prepare.

public void prepare(Object localTransactionId, XidImpl globalTransactionId) throws QueueException {
    lockAndWaitAsyncFinished();
    try {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "prepare, globalTxId=" + globalTransactionId);
        TopicTransaction transaction = (TopicTransaction) localTransactionId;
        transaction.prepare(globalTransactionId);
        transactions.set(transaction.getTransactionId(), null);
    } catch (Exception e) {
        throw new QueueException(e.getMessage());
    } finally {
        lock.unlock();
    }
}
Also used : QueueException(com.swiftmq.swiftlet.queue.QueueException) EntityRemoveException(com.swiftmq.mgmt.EntityRemoveException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) JMSException(javax.jms.JMSException) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 19 with QueueException

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

the class TopicBroker method rollback.

public void rollback(Object localTransactionId, XidImpl globalTransactionId, boolean setRedelivered) throws QueueException {
    lockAndWaitAsyncFinished();
    try {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$topicmanager", tracePrefix + "rollback, globalTxId=" + globalTransactionId);
        TopicTransaction transaction = (TopicTransaction) localTransactionId;
        transaction.rollback(globalTransactionId);
        transactions.set(transaction.getTransactionId(), null);
    } catch (Exception e) {
        throw new QueueException(e.getMessage());
    } finally {
        lock.unlock();
    }
}
Also used : QueueException(com.swiftmq.swiftlet.queue.QueueException) EntityRemoveException(com.swiftmq.mgmt.EntityRemoveException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) JMSException(javax.jms.JMSException) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 20 with QueueException

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

QueueException (com.swiftmq.swiftlet.queue.QueueException)20 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)8 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)7 JMSException (javax.jms.JMSException)7 Property (com.swiftmq.mgmt.Property)3 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)3 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)3 NonPersistentStore (com.swiftmq.swiftlet.store.NonPersistentStore)3 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 QueueImpl (com.swiftmq.jms.QueueImpl)2 TopicImpl (com.swiftmq.jms.TopicImpl)2 EntityList (com.swiftmq.mgmt.EntityList)2 PropertyChangeException (com.swiftmq.mgmt.PropertyChangeException)2 PersistentStore (com.swiftmq.swiftlet.store.PersistentStore)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)1 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)1