1 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 ; 24 25 public class AdvisorySupport { 26 27 public static final String 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 PRODUCER_ADVISORY_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Producer."; 34 public static final String QUEUE_PRODUCER_ADVISORY_TOPIC_PREFIX = PRODUCER_ADVISORY_TOPIC_PREFIX+"Queue."; 35 public static final String TOPIC_PRODUCER_ADVISORY_TOPIC_PREFIX = PRODUCER_ADVISORY_TOPIC_PREFIX+"Topic."; 36 public static final String CONSUMER_ADVISORY_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Consumer."; 37 public static final String QUEUE_CONSUMER_ADVISORY_TOPIC_PREFIX = CONSUMER_ADVISORY_TOPIC_PREFIX+"Queue."; 38 public static final String TOPIC_CONSUMER_ADVISORY_TOPIC_PREFIX = CONSUMER_ADVISORY_TOPIC_PREFIX+"Topic."; 39 public static final String EXPIRED_TOPIC_MESSAGES_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Expired.Topic."; 40 public static final String EXPIRED_QUEUE_MESSAGES_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"Expired.Queue."; 41 public static final String NO_TOPIC_CONSUMERS_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"NoConsumer.Topic."; 42 public static final String NO_QUEUE_CONSUMERS_TOPIC_PREFIX = ADVISORY_TOPIC_PREFIX+"NoConsumer.Queue."; 43 public static final String AGENT_TOPIC = "ActiveMQ.Agent"; 44 45 public static final String 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 name = EXPIRED_TOPIC_MESSAGES_TOPIC_PREFIX+destination.getPhysicalName(); 69 return new ActiveMQTopic(name); 70 } 71 72 public static ActiveMQTopic getExpiredQueueMessageAdvisoryTopic(ActiveMQDestination destination) { 73 String name = EXPIRED_QUEUE_MESSAGES_TOPIC_PREFIX+destination.getPhysicalName(); 74 return new ActiveMQTopic(name); 75 } 76 77 public static ActiveMQTopic getNoTopicConsumersAdvisoryTopic(ActiveMQDestination destination) { 78 String name = NO_TOPIC_CONSUMERS_TOPIC_PREFIX+destination.getPhysicalName(); 79 return new ActiveMQTopic(name); 80 } 81 82 public static ActiveMQTopic getNoQueueConsumersAdvisoryTopic(ActiveMQDestination destination) { 83 String 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 ("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 178 public static Destination getAgentDestination() { 179 return AGENT_TOPIC_DESTINATION; 180 } 181 } 182 | Popular Tags |