001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.advisory;
018
019import java.util.ArrayList;
020
021import javax.jms.Destination;
022import javax.jms.JMSException;
023
024import org.apache.activemq.ActiveMQMessageTransformation;
025import org.apache.activemq.command.ActiveMQDestination;
026import org.apache.activemq.command.ActiveMQTopic;
027
028public final class AdvisorySupport {
029    public static final String ADVISORY_TOPIC_PREFIX = "ActiveMQ.Advisory.";
030    public static final ActiveMQTopic CONNECTION_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX
031            + "Connection");
032    public static final ActiveMQTopic QUEUE_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX + "Queue");
033    public static final ActiveMQTopic TOPIC_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX + "Topic");
034    public static final ActiveMQTopic TEMP_QUEUE_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX + "TempQueue");
035    public static final ActiveMQTopic TEMP_TOPIC_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX + "TempTopic");
036    public static final String PRODUCER_ADVISORY_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "Producer.";
037    public static final String QUEUE_PRODUCER_ADVISORY_TOPIC_PREFIX = PRODUCER_ADVISORY_TOPIC_PREFIX + "Queue.";
038    public static final String TOPIC_PRODUCER_ADVISORY_TOPIC_PREFIX = PRODUCER_ADVISORY_TOPIC_PREFIX + "Topic.";
039    public static final String CONSUMER_ADVISORY_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "Consumer.";
040    public static final String VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "VirtualDestination.Consumer.";
041    public static final String QUEUE_CONSUMER_ADVISORY_TOPIC_PREFIX = CONSUMER_ADVISORY_TOPIC_PREFIX + "Queue.";
042    public static final String TOPIC_CONSUMER_ADVISORY_TOPIC_PREFIX = CONSUMER_ADVISORY_TOPIC_PREFIX + "Topic.";
043    public static final String QUEUE_VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX = VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX + "Queue.";
044    public static final String TOPIC_VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX = VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX + "Topic.";
045    public static final String EXPIRED_TOPIC_MESSAGES_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "Expired.Topic.";
046    public static final String EXPIRED_QUEUE_MESSAGES_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "Expired.Queue.";
047    public static final String NO_TOPIC_CONSUMERS_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "NoConsumer.Topic.";
048    public static final String NO_QUEUE_CONSUMERS_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "NoConsumer.Queue.";
049    public static final String SLOW_CONSUMER_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "SlowConsumer.";
050    public static final String FAST_PRODUCER_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "FastProducer.";
051    public static final String MESSAGE_DISCAREDED_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "MessageDiscarded.";
052    public static final String FULL_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "FULL.";
053    public static final String MESSAGE_DELIVERED_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "MessageDelivered.";
054    public static final String MESSAGE_CONSUMED_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "MessageConsumed.";
055    public static final String MESSAGE_DLQ_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "MessageDLQd.";
056    public static final String MASTER_BROKER_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "MasterBroker";
057    public static final String NETWORK_BRIDGE_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX + "NetworkBridge";
058    public static final String NETWORK_BRIDGE_FORWARD_FAILURE_TOPIC_PREFIX = NETWORK_BRIDGE_TOPIC_PREFIX + ".ForwardFailure";
059    public static final String AGENT_TOPIC = "ActiveMQ.Agent";
060    public static final String ADIVSORY_MESSAGE_TYPE = "Advisory";
061    public static final String MSG_PROPERTY_ORIGIN_BROKER_ID = "originBrokerId";
062    public static final String MSG_PROPERTY_ORIGIN_BROKER_NAME = "originBrokerName";
063    public static final String MSG_PROPERTY_ORIGIN_BROKER_URL = "originBrokerURL";
064    public static final String MSG_PROPERTY_USAGE_NAME = "usageName";
065    public static final String MSG_PROPERTY_USAGE_COUNT = "usageCount";
066
067    public static final String MSG_PROPERTY_CONSUMER_ID = "consumerId";
068    public static final String MSG_PROPERTY_PRODUCER_ID = "producerId";
069    public static final String MSG_PROPERTY_MESSAGE_ID = "orignalMessageId";
070    public static final String MSG_PROPERTY_DESTINATION = "orignalDestination";
071    public static final String MSG_PROPERTY_CONSUMER_COUNT = "consumerCount";
072    public static final String MSG_PROPERTY_DISCARDED_COUNT = "discardedCount";
073
074    public static final ActiveMQTopic ALL_DESTINATIONS_COMPOSITE_ADVISORY_TOPIC = new ActiveMQTopic(
075            TOPIC_ADVISORY_TOPIC.getPhysicalName() + "," + QUEUE_ADVISORY_TOPIC.getPhysicalName() + "," +
076                    TEMP_QUEUE_ADVISORY_TOPIC.getPhysicalName() + "," + TEMP_TOPIC_ADVISORY_TOPIC.getPhysicalName());
077    public static final ActiveMQTopic TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC = new ActiveMQTopic(
078            TEMP_QUEUE_ADVISORY_TOPIC.getPhysicalName() + "," + TEMP_TOPIC_ADVISORY_TOPIC.getPhysicalName());
079    private static final ActiveMQTopic AGENT_TOPIC_DESTINATION = new ActiveMQTopic(AGENT_TOPIC);
080
081    private AdvisorySupport() {
082    }
083
084    public static ActiveMQTopic getConnectionAdvisoryTopic() {
085        return CONNECTION_ADVISORY_TOPIC;
086    }
087
088    public static ActiveMQTopic[] getAllDestinationAdvisoryTopics(Destination destination) throws JMSException {
089        return getAllDestinationAdvisoryTopics(ActiveMQMessageTransformation.transformDestination(destination));
090    }
091
092    public static ActiveMQTopic[] getAllDestinationAdvisoryTopics(ActiveMQDestination destination) throws JMSException {
093        ArrayList<ActiveMQTopic> result = new ArrayList<ActiveMQTopic>();
094
095        result.add(getConsumerAdvisoryTopic(destination));
096        result.add(getProducerAdvisoryTopic(destination));
097        result.add(getExpiredMessageTopic(destination));
098        result.add(getNoConsumersAdvisoryTopic(destination));
099        result.add(getSlowConsumerAdvisoryTopic(destination));
100        result.add(getFastProducerAdvisoryTopic(destination));
101        result.add(getMessageDiscardedAdvisoryTopic(destination));
102        result.add(getMessageDeliveredAdvisoryTopic(destination));
103        result.add(getMessageConsumedAdvisoryTopic(destination));
104        result.add(getMessageDLQdAdvisoryTopic(destination));
105        result.add(getFullAdvisoryTopic(destination));
106
107        return result.toArray(new ActiveMQTopic[0]);
108    }
109
110    public static ActiveMQTopic getConsumerAdvisoryTopic(Destination destination) throws JMSException {
111        return getConsumerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
112    }
113
114    public static ActiveMQTopic getConsumerAdvisoryTopic(ActiveMQDestination destination) {
115        String prefix;
116        if (destination.isQueue()) {
117            prefix = QUEUE_CONSUMER_ADVISORY_TOPIC_PREFIX;
118        } else {
119            prefix = TOPIC_CONSUMER_ADVISORY_TOPIC_PREFIX;
120        }
121        return getAdvisoryTopic(destination, prefix, true);
122    }
123
124    public static ActiveMQTopic getVirtualDestinationConsumerAdvisoryTopic(ActiveMQDestination destination) {
125        String prefix;
126        if (destination.isQueue()) {
127            prefix = QUEUE_VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX;
128        } else {
129            prefix = TOPIC_VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX;
130        }
131        return getAdvisoryTopic(destination, prefix, true);
132    }
133
134    public static ActiveMQTopic getProducerAdvisoryTopic(Destination destination) throws JMSException {
135        return getProducerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
136    }
137
138    public static ActiveMQTopic getProducerAdvisoryTopic(ActiveMQDestination destination) {
139        String prefix;
140        if (destination.isQueue()) {
141            prefix = QUEUE_PRODUCER_ADVISORY_TOPIC_PREFIX;
142        } else {
143            prefix = TOPIC_PRODUCER_ADVISORY_TOPIC_PREFIX;
144        }
145        return getAdvisoryTopic(destination, prefix, false);
146    }
147
148    private static ActiveMQTopic getAdvisoryTopic(ActiveMQDestination destination, String prefix, boolean consumerTopics) {
149        return new ActiveMQTopic(prefix + destination.getPhysicalName().replaceAll(",", "&sbquo;"));
150    }
151
152    public static ActiveMQTopic getExpiredMessageTopic(Destination destination) throws JMSException {
153        return getExpiredMessageTopic(ActiveMQMessageTransformation.transformDestination(destination));
154    }
155
156    public static ActiveMQTopic getExpiredMessageTopic(ActiveMQDestination destination) {
157        if (destination.isQueue()) {
158            return getExpiredQueueMessageAdvisoryTopic(destination);
159        }
160        return getExpiredTopicMessageAdvisoryTopic(destination);
161    }
162
163    public static ActiveMQTopic getExpiredTopicMessageAdvisoryTopic(ActiveMQDestination destination) {
164        String name = EXPIRED_TOPIC_MESSAGES_TOPIC_PREFIX + destination.getPhysicalName();
165        return new ActiveMQTopic(name);
166    }
167
168    public static ActiveMQTopic getExpiredQueueMessageAdvisoryTopic(Destination destination) throws JMSException {
169        return getExpiredQueueMessageAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
170    }
171
172    public static ActiveMQTopic getExpiredQueueMessageAdvisoryTopic(ActiveMQDestination destination) {
173        String name = EXPIRED_QUEUE_MESSAGES_TOPIC_PREFIX + destination.getPhysicalName();
174        return new ActiveMQTopic(name);
175    }
176
177    public static ActiveMQTopic getNoConsumersAdvisoryTopic(Destination destination) throws JMSException {
178        return getExpiredMessageTopic(ActiveMQMessageTransformation.transformDestination(destination));
179    }
180
181    public static ActiveMQTopic getNoConsumersAdvisoryTopic(ActiveMQDestination destination) {
182        if (destination.isQueue()) {
183            return getNoQueueConsumersAdvisoryTopic(destination);
184        }
185        return getNoTopicConsumersAdvisoryTopic(destination);
186    }
187
188    public static ActiveMQTopic getNoTopicConsumersAdvisoryTopic(Destination destination) throws JMSException {
189        return getNoTopicConsumersAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
190    }
191
192    public static ActiveMQTopic getNoTopicConsumersAdvisoryTopic(ActiveMQDestination destination) {
193        String name = NO_TOPIC_CONSUMERS_TOPIC_PREFIX + destination.getPhysicalName();
194        return new ActiveMQTopic(name);
195    }
196
197    public static ActiveMQTopic getNoQueueConsumersAdvisoryTopic(Destination destination) throws JMSException {
198        return getNoQueueConsumersAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
199    }
200
201    public static ActiveMQTopic getNoQueueConsumersAdvisoryTopic(ActiveMQDestination destination) {
202        String name = NO_QUEUE_CONSUMERS_TOPIC_PREFIX + destination.getPhysicalName();
203        return new ActiveMQTopic(name);
204    }
205
206    public static ActiveMQTopic getSlowConsumerAdvisoryTopic(Destination destination) throws JMSException {
207        return getSlowConsumerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
208    }
209
210    public static ActiveMQTopic getSlowConsumerAdvisoryTopic(ActiveMQDestination destination) {
211        String name = SLOW_CONSUMER_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "."
212                + destination.getPhysicalName();
213        return new ActiveMQTopic(name);
214    }
215
216    public static ActiveMQTopic getFastProducerAdvisoryTopic(Destination destination) throws JMSException {
217        return getFastProducerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
218    }
219
220    public static ActiveMQTopic getFastProducerAdvisoryTopic(ActiveMQDestination destination) {
221        String name = FAST_PRODUCER_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "."
222                + destination.getPhysicalName();
223        return new ActiveMQTopic(name);
224    }
225
226    public static ActiveMQTopic getMessageDiscardedAdvisoryTopic(Destination destination) throws JMSException {
227        return getMessageDiscardedAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
228    }
229
230    public static ActiveMQTopic getMessageDiscardedAdvisoryTopic(ActiveMQDestination destination) {
231        String name = MESSAGE_DISCAREDED_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "."
232                + destination.getPhysicalName();
233        return new ActiveMQTopic(name);
234    }
235
236    public static ActiveMQTopic getMessageDeliveredAdvisoryTopic(Destination destination) throws JMSException {
237        return getMessageDeliveredAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
238    }
239
240    public static ActiveMQTopic getMessageDeliveredAdvisoryTopic(ActiveMQDestination destination) {
241        String name = MESSAGE_DELIVERED_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "."
242                + destination.getPhysicalName();
243        return new ActiveMQTopic(name);
244    }
245
246    public static ActiveMQTopic getMessageConsumedAdvisoryTopic(Destination destination) throws JMSException {
247        return getMessageConsumedAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
248    }
249
250    public static ActiveMQTopic getMessageConsumedAdvisoryTopic(ActiveMQDestination destination) {
251        String name = MESSAGE_CONSUMED_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "."
252                + destination.getPhysicalName();
253        return new ActiveMQTopic(name);
254    }
255
256    public static ActiveMQTopic getMessageDLQdAdvisoryTopic(ActiveMQDestination destination) {
257        String name = MESSAGE_DLQ_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "."
258                + destination.getPhysicalName();
259        return new ActiveMQTopic(name);
260    }
261
262    public static ActiveMQTopic getMasterBrokerAdvisoryTopic() {
263        return new ActiveMQTopic(MASTER_BROKER_TOPIC_PREFIX);
264    }
265
266    public static ActiveMQTopic getNetworkBridgeAdvisoryTopic() {
267        return new ActiveMQTopic(NETWORK_BRIDGE_TOPIC_PREFIX);
268    }
269
270    public static ActiveMQTopic getFullAdvisoryTopic(Destination destination) throws JMSException {
271        return getFullAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
272    }
273
274    public static ActiveMQTopic getFullAdvisoryTopic(ActiveMQDestination destination) {
275        String name = FULL_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "."
276                + destination.getPhysicalName();
277        return new ActiveMQTopic(name);
278    }
279
280    public static ActiveMQTopic getDestinationAdvisoryTopic(Destination destination) throws JMSException {
281        return getDestinationAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
282    }
283
284    public static ActiveMQTopic getDestinationAdvisoryTopic(ActiveMQDestination destination) {
285        switch (destination.getDestinationType()) {
286            case ActiveMQDestination.QUEUE_TYPE:
287                return QUEUE_ADVISORY_TOPIC;
288            case ActiveMQDestination.TOPIC_TYPE:
289                return TOPIC_ADVISORY_TOPIC;
290            case ActiveMQDestination.TEMP_QUEUE_TYPE:
291                return TEMP_QUEUE_ADVISORY_TOPIC;
292            case ActiveMQDestination.TEMP_TOPIC_TYPE:
293                return TEMP_TOPIC_ADVISORY_TOPIC;
294            default:
295                throw new RuntimeException("Unknown destination type: " + destination.getDestinationType());
296        }
297    }
298
299    public static boolean isDestinationAdvisoryTopic(Destination destination) throws JMSException {
300        return isDestinationAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
301    }
302
303    public static boolean isTempDestinationAdvisoryTopic(ActiveMQDestination destination) {
304        if (destination.isComposite()) {
305            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
306            for (int i = 0; i < compositeDestinations.length; i++) {
307                if (!isTempDestinationAdvisoryTopic(compositeDestinations[i])) {
308                    return false;
309                }
310            }
311            return true;
312        } else {
313            return destination.equals(TEMP_QUEUE_ADVISORY_TOPIC) || destination.equals(TEMP_TOPIC_ADVISORY_TOPIC);
314        }
315    }
316
317    public static boolean isDestinationAdvisoryTopic(ActiveMQDestination destination) {
318        if (destination.isComposite()) {
319            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
320            for (int i = 0; i < compositeDestinations.length; i++) {
321                if (isDestinationAdvisoryTopic(compositeDestinations[i])) {
322                    return true;
323                }
324            }
325            return false;
326        } else {
327            return destination.equals(TEMP_QUEUE_ADVISORY_TOPIC) || destination.equals(TEMP_TOPIC_ADVISORY_TOPIC)
328                    || destination.equals(QUEUE_ADVISORY_TOPIC) || destination.equals(TOPIC_ADVISORY_TOPIC);
329        }
330    }
331
332    public static boolean isAdvisoryTopic(Destination destination) throws JMSException {
333        return isAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
334    }
335
336    public static boolean isAdvisoryTopic(ActiveMQDestination destination) {
337        if (destination != null) {
338            if (destination.isComposite()) {
339                ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
340                for (int i = 0; i < compositeDestinations.length; i++) {
341                    if (isAdvisoryTopic(compositeDestinations[i])) {
342                        return true;
343                    }
344                }
345                return false;
346            } else {
347                return destination.isTopic() && destination.getPhysicalName().startsWith(ADVISORY_TOPIC_PREFIX);
348            }
349        }
350        return false;
351    }
352
353    public static boolean isConnectionAdvisoryTopic(Destination destination) throws JMSException {
354        return isConnectionAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
355    }
356
357    public static boolean isConnectionAdvisoryTopic(ActiveMQDestination destination) {
358        if (destination.isComposite()) {
359            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
360            for (int i = 0; i < compositeDestinations.length; i++) {
361                if (isConnectionAdvisoryTopic(compositeDestinations[i])) {
362                    return true;
363                }
364            }
365            return false;
366        } else {
367            return destination.equals(CONNECTION_ADVISORY_TOPIC);
368        }
369    }
370
371    public static boolean isProducerAdvisoryTopic(Destination destination) throws JMSException {
372        return isProducerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
373    }
374
375    public static boolean isProducerAdvisoryTopic(ActiveMQDestination destination) {
376        if (destination.isComposite()) {
377            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
378            for (int i = 0; i < compositeDestinations.length; i++) {
379                if (isProducerAdvisoryTopic(compositeDestinations[i])) {
380                    return true;
381                }
382            }
383            return false;
384        } else {
385            return destination.isTopic() && destination.getPhysicalName().startsWith(PRODUCER_ADVISORY_TOPIC_PREFIX);
386        }
387    }
388
389    public static boolean isConsumerAdvisoryTopic(Destination destination) throws JMSException {
390        return isConsumerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
391    }
392
393    public static boolean isConsumerAdvisoryTopic(ActiveMQDestination destination) {
394        if (destination.isComposite()) {
395            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
396            for (int i = 0; i < compositeDestinations.length; i++) {
397                if (isConsumerAdvisoryTopic(compositeDestinations[i])) {
398                    return true;
399                }
400            }
401            return false;
402        } else {
403            return destination.isTopic() && destination.getPhysicalName().startsWith(CONSUMER_ADVISORY_TOPIC_PREFIX);
404        }
405    }
406
407    public static boolean isVirtualDestinationConsumerAdvisoryTopic(Destination destination) throws JMSException {
408        return isVirtualDestinationConsumerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
409    }
410
411    public static boolean isVirtualDestinationConsumerAdvisoryTopic(ActiveMQDestination destination) {
412        if (destination.isComposite()) {
413            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
414            for (int i = 0; i < compositeDestinations.length; i++) {
415                if (isVirtualDestinationConsumerAdvisoryTopic(compositeDestinations[i])) {
416                    return true;
417                }
418            }
419            return false;
420        } else {
421            return destination.isTopic() && destination.getPhysicalName().startsWith(VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX);
422        }
423    }
424
425    public static boolean isSlowConsumerAdvisoryTopic(Destination destination) throws JMSException {
426        return isSlowConsumerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
427    }
428
429    public static boolean isSlowConsumerAdvisoryTopic(ActiveMQDestination destination) {
430        if (destination.isComposite()) {
431            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
432            for (int i = 0; i < compositeDestinations.length; i++) {
433                if (isSlowConsumerAdvisoryTopic(compositeDestinations[i])) {
434                    return true;
435                }
436            }
437            return false;
438        } else {
439            return destination.isTopic() && destination.getPhysicalName().startsWith(SLOW_CONSUMER_TOPIC_PREFIX);
440        }
441    }
442
443    public static boolean isFastProducerAdvisoryTopic(Destination destination) throws JMSException {
444        return isFastProducerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
445    }
446
447    public static boolean isFastProducerAdvisoryTopic(ActiveMQDestination destination) {
448        if (destination.isComposite()) {
449            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
450            for (int i = 0; i < compositeDestinations.length; i++) {
451                if (isFastProducerAdvisoryTopic(compositeDestinations[i])) {
452                    return true;
453                }
454            }
455            return false;
456        } else {
457            return destination.isTopic() && destination.getPhysicalName().startsWith(FAST_PRODUCER_TOPIC_PREFIX);
458        }
459    }
460
461    public static boolean isMessageConsumedAdvisoryTopic(Destination destination) throws JMSException {
462        return isMessageConsumedAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
463    }
464
465    public static boolean isMessageConsumedAdvisoryTopic(ActiveMQDestination destination) {
466        if (destination.isComposite()) {
467            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
468            for (int i = 0; i < compositeDestinations.length; i++) {
469                if (isMessageConsumedAdvisoryTopic(compositeDestinations[i])) {
470                    return true;
471                }
472            }
473            return false;
474        } else {
475            return destination.isTopic() && destination.getPhysicalName().startsWith(MESSAGE_CONSUMED_TOPIC_PREFIX);
476        }
477    }
478
479    public static boolean isMasterBrokerAdvisoryTopic(Destination destination) throws JMSException {
480        return isMasterBrokerAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
481    }
482
483    public static boolean isMasterBrokerAdvisoryTopic(ActiveMQDestination destination) {
484        if (destination.isComposite()) {
485            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
486            for (int i = 0; i < compositeDestinations.length; i++) {
487                if (isMasterBrokerAdvisoryTopic(compositeDestinations[i])) {
488                    return true;
489                }
490            }
491            return false;
492        } else {
493            return destination.isTopic() && destination.getPhysicalName().startsWith(MASTER_BROKER_TOPIC_PREFIX);
494        }
495    }
496
497    public static boolean isMessageDeliveredAdvisoryTopic(Destination destination) throws JMSException {
498        return isMessageDeliveredAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
499    }
500
501    public static boolean isMessageDeliveredAdvisoryTopic(ActiveMQDestination destination) {
502        if (destination.isComposite()) {
503            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
504            for (int i = 0; i < compositeDestinations.length; i++) {
505                if (isMessageDeliveredAdvisoryTopic(compositeDestinations[i])) {
506                    return true;
507                }
508            }
509            return false;
510        } else {
511            return destination.isTopic() && destination.getPhysicalName().startsWith(MESSAGE_DELIVERED_TOPIC_PREFIX);
512        }
513    }
514
515    public static boolean isMessageDiscardedAdvisoryTopic(Destination destination) throws JMSException {
516        return isMessageDiscardedAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
517    }
518
519    public static boolean isMessageDiscardedAdvisoryTopic(ActiveMQDestination destination) {
520        if (destination.isComposite()) {
521            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
522            for (int i = 0; i < compositeDestinations.length; i++) {
523                if (isMessageDiscardedAdvisoryTopic(compositeDestinations[i])) {
524                    return true;
525                }
526            }
527            return false;
528        } else {
529            return destination.isTopic() && destination.getPhysicalName().startsWith(MESSAGE_DISCAREDED_TOPIC_PREFIX);
530        }
531    }
532
533    public static boolean isFullAdvisoryTopic(Destination destination) throws JMSException {
534        return isFullAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
535    }
536
537    public static boolean isFullAdvisoryTopic(ActiveMQDestination destination) {
538        if (destination.isComposite()) {
539            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
540            for (int i = 0; i < compositeDestinations.length; i++) {
541                if (isFullAdvisoryTopic(compositeDestinations[i])) {
542                    return true;
543                }
544            }
545            return false;
546        } else {
547            return destination.isTopic() && destination.getPhysicalName().startsWith(FULL_TOPIC_PREFIX);
548        }
549    }
550
551    public static boolean isNetworkBridgeAdvisoryTopic(Destination destination) throws JMSException {
552        return isNetworkBridgeAdvisoryTopic(ActiveMQMessageTransformation.transformDestination(destination));
553    }
554
555    public static boolean isNetworkBridgeAdvisoryTopic(ActiveMQDestination destination) {
556        if (destination.isComposite()) {
557            ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
558            for (int i = 0; i < compositeDestinations.length; i++) {
559                if (isNetworkBridgeAdvisoryTopic(compositeDestinations[i])) {
560                    return true;
561                }
562            }
563            return false;
564        } else {
565            return destination.isTopic() && destination.getPhysicalName().startsWith(NETWORK_BRIDGE_TOPIC_PREFIX);
566        }
567    }
568
569    /**
570     * Returns the agent topic which is used to send commands to the broker
571     */
572    public static Destination getAgentDestination() {
573        return AGENT_TOPIC_DESTINATION;
574    }
575
576    public static ActiveMQTopic getNetworkBridgeForwardFailureAdvisoryTopic() {
577        return new ActiveMQTopic(NETWORK_BRIDGE_FORWARD_FAILURE_TOPIC_PREFIX);
578    }
579}