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