Reduce contention by not sending an advisory for every destination when not all destination types are requested.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1214964 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-12-15 21:49:44 +00:00
parent 41cdadbe2a
commit 68bcf0fb15
2 changed files with 58 additions and 33 deletions

View File

@ -96,15 +96,23 @@ public class AdvisoryBroker extends BrokerFilter {
}
}
// We need to replay all the previously collected destination
// objects
// for this newly added consumer.
if (AdvisorySupport.isDestinationAdvisoryTopic(info.getDestination())) {
// Replay the destinations.
for (Iterator<DestinationInfo> iter = destinations.values().iterator(); iter.hasNext();) {
DestinationInfo value = iter.next();
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(value.getDestination());
fireAdvisory(context, topic, value, info.getConsumerId());
// We check here whether the Destination is Temporary Destination specific or not since we
// can avoid sending advisory messages to the consumer if it only wants Temporary Destination
// notifications. If its not just temporary destination related destinations then we have
// to send them all, a composite destination could want both.
if (AdvisorySupport.isTempDestinationAdvisoryTopic(info.getDestination())) {
// Replay the temporary destinations.
for (DestinationInfo destination : destinations.values()) {
if (destination.getDestination().isTemporary()) {
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination.getDestination());
fireAdvisory(context, topic, destination, info.getConsumerId());
}
}
} else if (AdvisorySupport.isDestinationAdvisoryTopic(info.getDestination())) {
// Replay all the destinations.
for (DestinationInfo destination : destinations.values()) {
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination.getDestination());
fireAdvisory(context, topic, destination, info.getConsumerId());
}
}
@ -243,7 +251,7 @@ public class AdvisoryBroker extends BrokerFilter {
ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(dest);
consumers.remove(info.getConsumerId());
if (!dest.isTemporary() || destinations.containsKey(dest)) {
fireConsumerAdvisory(context,dest, topic, info.createRemoveCommand());
fireConsumerAdvisory(context,dest, topic, info.createRemoveCommand());
}
}
}

View File

@ -60,6 +60,9 @@ public final class AdvisorySupport {
public static final String MSG_PROPERTY_CONSUMER_COUNT = "consumerCount";
public static final String MSG_PROPERTY_DISCARDED_COUNT = "discardedCount";
public static final ActiveMQTopic ALL_DESTINATIONS_COMPOSITE_ADVISORY_TOPIC = new ActiveMQTopic(
TOPIC_ADVISORY_TOPIC.getPhysicalName() + "," + QUEUE_ADVISORY_TOPIC.getPhysicalName() + "," +
TEMP_QUEUE_ADVISORY_TOPIC.getPhysicalName() + "," + TEMP_TOPIC_ADVISORY_TOPIC.getPhysicalName());
public static final ActiveMQTopic TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC = new ActiveMQTopic(
TEMP_QUEUE_ADVISORY_TOPIC.getPhysicalName() + "," + TEMP_TOPIC_ADVISORY_TOPIC.getPhysicalName());
private static final ActiveMQTopic AGENT_TOPIC_DESTINATION = new ActiveMQTopic(AGENT_TOPIC);
@ -239,6 +242,20 @@ public final class AdvisorySupport {
return isDestinationAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
}
public static boolean isTempDestinationAdvisoryTopic(ActiveMQDestination destination) {
if (destination.isComposite()) {
ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
for (int i = 0; i < compositeDestinations.length; i++) {
if (!isTempDestinationAdvisoryTopic(compositeDestinations[i])) {
return false;
}
}
return true;
} else {
return destination.equals(TEMP_QUEUE_ADVISORY_TOPIC) || destination.equals(TEMP_TOPIC_ADVISORY_TOPIC);
}
}
public static boolean isDestinationAdvisoryTopic(ActiveMQDestination destination) {
if (destination.isComposite()) {
ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();