KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > advisory > AdvisorySupport


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.advisory;
19
20 import org.apache.activemq.command.ActiveMQDestination;
21 import org.apache.activemq.command.ActiveMQTopic;
22
23 import javax.jms.Destination JavaDoc;
24
25 public class AdvisorySupport {
26     
27     public static final String JavaDoc ADVISORY_TOPIC_PREFIX = "ActiveMQ.Advisory.";
28     public static final ActiveMQTopic CONNECTION_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX+"Connection");
29     public static final ActiveMQTopic QUEUE_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX+"Queue");
30     public static final ActiveMQTopic TOPIC_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX+"Topic");
31     public static final ActiveMQTopic TEMP_QUEUE_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX+"TempQueue");
32     public static final ActiveMQTopic TEMP_TOPIC_ADVISORY_TOPIC = new ActiveMQTopic(ADVISORY_TOPIC_PREFIX+"TempTopic");
33     public static final String JavaDoc PRODUCER_ADVISORY_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Producer.";
34     public static final String JavaDoc QUEUE_PRODUCER_ADVISORY_TOPIC_PREFIX = PRODUCER_ADVISORY_TOPIC_PREFIX+"Queue.";
35     public static final String JavaDoc TOPIC_PRODUCER_ADVISORY_TOPIC_PREFIX = PRODUCER_ADVISORY_TOPIC_PREFIX+"Topic.";
36     public static final String JavaDoc CONSUMER_ADVISORY_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Consumer.";
37     public static final String JavaDoc QUEUE_CONSUMER_ADVISORY_TOPIC_PREFIX = CONSUMER_ADVISORY_TOPIC_PREFIX+"Queue.";
38     public static final String JavaDoc TOPIC_CONSUMER_ADVISORY_TOPIC_PREFIX = CONSUMER_ADVISORY_TOPIC_PREFIX+"Topic.";
39     public static final String JavaDoc EXPIRED_TOPIC_MESSAGES_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Expired.Topic.";
40     public static final String JavaDoc EXPIRED_QUEUE_MESSAGES_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Expired.Queue.";
41     public static final String JavaDoc NO_TOPIC_CONSUMERS_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"NoConsumer.Topic.";
42     public static final String JavaDoc NO_QUEUE_CONSUMERS_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"NoConsumer.Queue.";
43     public static final String JavaDoc AGENT_TOPIC = "ActiveMQ.Agent";
44
45     public static final String JavaDoc ADIVSORY_MESSAGE_TYPE = "Advisory";
46     public static final ActiveMQTopic TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC = new ActiveMQTopic(TEMP_QUEUE_ADVISORY_TOPIC+","+TEMP_TOPIC_ADVISORY_TOPIC);
47     private static final ActiveMQTopic AGENT_TOPIC_DESTINATION = new ActiveMQTopic(AGENT_TOPIC);
48
49     public static ActiveMQTopic getConnectionAdvisoryTopic() {
50         return CONNECTION_ADVISORY_TOPIC;
51     }
52
53     public static ActiveMQTopic getConsumerAdvisoryTopic(ActiveMQDestination destination) {
54         if( destination.isQueue() )
55             return new ActiveMQTopic(QUEUE_CONSUMER_ADVISORY_TOPIC_PREFIX+destination.getPhysicalName());
56         else
57             return new ActiveMQTopic(TOPIC_CONSUMER_ADVISORY_TOPIC_PREFIX+destination.getPhysicalName());
58     }
59     
60     public static ActiveMQTopic getProducerAdvisoryTopic(ActiveMQDestination destination) {
61         if( destination.isQueue() )
62             return new ActiveMQTopic(QUEUE_PRODUCER_ADVISORY_TOPIC_PREFIX+destination.getPhysicalName());
63         else
64             return new ActiveMQTopic(TOPIC_PRODUCER_ADVISORY_TOPIC_PREFIX+destination.getPhysicalName());
65     }
66     
67     public static ActiveMQTopic getExpiredTopicMessageAdvisoryTopic(ActiveMQDestination destination) {
68         String JavaDoc name = EXPIRED_TOPIC_MESSAGES_TOPIC_PREFIX+destination.getPhysicalName();
69         return new ActiveMQTopic(name);
70     }
71     
72     public static ActiveMQTopic getExpiredQueueMessageAdvisoryTopic(ActiveMQDestination destination) {
73         String JavaDoc name = EXPIRED_QUEUE_MESSAGES_TOPIC_PREFIX+destination.getPhysicalName();
74         return new ActiveMQTopic(name);
75     }
76     
77     public static ActiveMQTopic getNoTopicConsumersAdvisoryTopic(ActiveMQDestination destination) {
78         String JavaDoc name = NO_TOPIC_CONSUMERS_TOPIC_PREFIX+destination.getPhysicalName();
79         return new ActiveMQTopic(name);
80     }
81     
82     public static ActiveMQTopic getNoQueueConsumersAdvisoryTopic(ActiveMQDestination destination) {
83         String JavaDoc name = NO_QUEUE_CONSUMERS_TOPIC_PREFIX+destination.getPhysicalName();
84         return new ActiveMQTopic(name);
85     }
86     
87     public static ActiveMQTopic getDestinationAdvisoryTopic(ActiveMQDestination destination) {
88         switch( destination.getDestinationType() ) {
89         case ActiveMQDestination.QUEUE_TYPE:
90             return QUEUE_ADVISORY_TOPIC;
91         case ActiveMQDestination.TOPIC_TYPE:
92             return TOPIC_ADVISORY_TOPIC;
93         case ActiveMQDestination.TEMP_QUEUE_TYPE:
94             return TEMP_QUEUE_ADVISORY_TOPIC;
95         case ActiveMQDestination.TEMP_TOPIC_TYPE:
96             return TEMP_TOPIC_ADVISORY_TOPIC;
97         }
98         throw new RuntimeException JavaDoc("Unknown destination type: "+destination.getDestinationType());
99     }
100
101     public static boolean isDestinationAdvisoryTopic(ActiveMQDestination destination) {
102         if( destination.isComposite() ) {
103             ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
104             for (int i = 0; i < compositeDestinations.length; i++) {
105                 if( isDestinationAdvisoryTopic(compositeDestinations[i]) ) {
106                     return true;
107                 }
108             }
109             return false;
110         } else {
111             return
112                 destination.equals(TEMP_QUEUE_ADVISORY_TOPIC)
113                 || destination.equals(TEMP_TOPIC_ADVISORY_TOPIC)
114                 || destination.equals(QUEUE_ADVISORY_TOPIC)
115                 || destination.equals(TOPIC_ADVISORY_TOPIC);
116         }
117     }
118
119     public static boolean isAdvisoryTopic(ActiveMQDestination destination) {
120         if( destination.isComposite() ) {
121             ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
122             for (int i = 0; i < compositeDestinations.length; i++) {
123                 if( isAdvisoryTopic(compositeDestinations[i]) ) {
124                     return true;
125                 }
126             }
127             return false;
128         } else {
129             return destination.isTopic() && destination.getPhysicalName().startsWith(ADVISORY_TOPIC_PREFIX);
130         }
131     }
132
133     public static boolean isConnectionAdvisoryTopic(ActiveMQDestination destination) {
134         if( destination.isComposite() ) {
135             ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
136             for (int i = 0; i < compositeDestinations.length; i++) {
137                 if( isConnectionAdvisoryTopic(compositeDestinations[i]) ) {
138                     return true;
139                 }
140             }
141             return false;
142         } else {
143             return destination.equals(CONNECTION_ADVISORY_TOPIC);
144         }
145     }
146
147     public static boolean isProducerAdvisoryTopic(ActiveMQDestination destination) {
148         if( destination.isComposite() ) {
149             ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
150             for (int i = 0; i < compositeDestinations.length; i++) {
151                 if( isProducerAdvisoryTopic(compositeDestinations[i]) ) {
152                     return true;
153                 }
154             }
155             return false;
156         } else {
157             return destination.isTopic() && destination.getPhysicalName().startsWith(PRODUCER_ADVISORY_TOPIC_PREFIX);
158         }
159     }
160
161     public static boolean isConsumerAdvisoryTopic(ActiveMQDestination destination) {
162         if( destination.isComposite() ) {
163             ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations();
164             for (int i = 0; i < compositeDestinations.length; i++) {
165                 if( isConsumerAdvisoryTopic(compositeDestinations[i]) ) {
166                     return true;
167                 }
168             }
169             return false;
170         } else {
171             return destination.isTopic() && destination.getPhysicalName().startsWith(CONSUMER_ADVISORY_TOPIC_PREFIX);
172         }
173     }
174
175     /**
176      * Returns the agent topic which is used to send commands to the broker
177      */

178     public static Destination getAgentDestination() {
179         return AGENT_TOPIC_DESTINATION;
180     }
181 }
182
Popular Tags