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();
}
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();
}
}
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();
}
}
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();
}
}
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());
}
}
}
}
}
}
}
}
Aggregations