001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.client;
022
023 import javax.jms.JMSException;
024 import javax.jms.Topic;
025
026 import org.apache.qpid.exchange.ExchangeDefaults;
027 import org.apache.qpid.framing.AMQShortString;
028 import org.apache.qpid.url.BindingURL;
029
030 public class AMQTopic extends AMQDestination implements Topic
031 {
032 /**
033 * Constructor for use in creating a topic using a BindingURL.
034 *
035 * @param binding The binding url object.
036 */
037 public AMQTopic(BindingURL binding)
038 {
039 super(binding);
040 }
041
042 // public AMQTopic(String exchangeName, String routingKey)
043 // {
044 // this(new AMQShortString(exchangeName), new AMQShortString(routingKey));
045 // }
046
047 public AMQTopic(AMQShortString exchange, AMQShortString routingKey, AMQShortString queueName)
048 {
049 super(exchange, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, routingKey, true, true, queueName, false);
050 }
051
052 public AMQTopic(AMQShortString exchange, AMQShortString routingKey, AMQShortString queueName,AMQShortString[] bindingKeys)
053 {
054 super(exchange, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, routingKey, true, true, queueName, false,bindingKeys);
055 }
056
057 public AMQTopic(AMQConnection conn, String routingKey)
058 {
059 this(conn.getDefaultTopicExchangeName(), new AMQShortString(routingKey));
060 }
061
062
063 public AMQTopic(AMQShortString exchangeName, String routingKey)
064 {
065 this(exchangeName, new AMQShortString(routingKey));
066 }
067
068 public AMQTopic(AMQShortString exchangeName, AMQShortString routingKey)
069 {
070 this(exchangeName, routingKey, null);
071 }
072
073 public AMQTopic(AMQShortString exchangeName, AMQShortString name, boolean isAutoDelete, AMQShortString queueName, boolean isDurable)
074 {
075 super(exchangeName, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, name, true, isAutoDelete,
076 queueName, isDurable);
077 }
078
079 protected AMQTopic(AMQShortString exchangeName, AMQShortString exchangeClass, AMQShortString routingKey, boolean isExclusive,
080 boolean isAutoDelete, AMQShortString queueName, boolean isDurable)
081 {
082 super(exchangeName, exchangeClass, routingKey, isExclusive, isAutoDelete, queueName, isDurable );
083 }
084
085 protected AMQTopic(AMQShortString exchangeName, AMQShortString exchangeClass, AMQShortString routingKey, boolean isExclusive,
086 boolean isAutoDelete, AMQShortString queueName, boolean isDurable,AMQShortString[] bindingKeys)
087 {
088 super(exchangeName, exchangeClass, routingKey, isExclusive, isAutoDelete, queueName, isDurable,bindingKeys);
089 }
090
091 public static AMQTopic createDurableTopic(AMQTopic topic, String subscriptionName, AMQConnection connection)
092 throws JMSException
093 {
094 return new AMQTopic(topic.getExchangeName(), topic.getRoutingKey(), false,
095 getDurableTopicQueueName(subscriptionName, connection),
096 true);
097 }
098
099 public static AMQTopic createDurable010Topic(AMQTopic topic, String subscriptionName, AMQConnection connection)
100 throws JMSException
101 {
102 return new AMQTopic(topic.getExchangeName(), ExchangeDefaults.TOPIC_EXCHANGE_CLASS, topic.getRoutingKey(), true, false,
103 getDurableTopicQueueName(subscriptionName, connection), true);
104 }
105
106 public static AMQShortString getDurableTopicQueueName(String subscriptionName, AMQConnection connection) throws JMSException
107 {
108 return new AMQShortString(connection.getClientID() + ":" + subscriptionName);
109 }
110
111 public String getTopicName() throws JMSException
112 {
113 return super.getRoutingKey().toString();
114 }
115
116 public AMQShortString getRoutingKey()
117 {
118 return super.getRoutingKey();
119 }
120
121 public boolean isNameRequired()
122 {
123 return !isDurable();
124 }
125
126 /**
127 * Override since the queue is always private and we must ensure it remains null. If not,
128 * reuse of the topic when registering consumers will make all consumers listen on the same (private) queue rather
129 * than getting their own (private) queue.
130 * <p/>
131 * This is relatively nasty but it is difficult to come up with a more elegant solution, given
132 * the requirement in the case on AMQQueue and possibly other AMQDestination subclasses to
133 * use the underlying queue name even where it is server generated.
134 */
135 public void setQueueName(String queueName)
136 {
137 }
138
139 public boolean equals(Object o)
140 {
141 return (o instanceof AMQTopic)
142 && ((AMQTopic)o).getExchangeName().equals(getExchangeName())
143 && ((AMQTopic)o).getRoutingKey().equals(getRoutingKey());
144
145 }
146
147 public int hashCode()
148 {
149 return getExchangeName().hashCode() + getRoutingKey().hashCode();
150 }
151 }
|