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.Queue;
024
025 import org.apache.qpid.exchange.ExchangeDefaults;
026 import org.apache.qpid.framing.AMQShortString;
027 import org.apache.qpid.url.BindingURL;
028
029 public class AMQQueue extends AMQDestination implements Queue
030 {
031
032 /**
033 * Create a reference to a non temporary queue using a BindingURL object.
034 * Note this does not actually imply the queue exists.
035 * @param binding a BindingURL object
036 */
037 public AMQQueue(BindingURL binding)
038 {
039 super(binding);
040 }
041
042 /**
043 * Create a reference to a non temporary queue. Note this does not actually imply the queue exists.
044 * @param name the name of the queue
045 */
046 public AMQQueue(AMQShortString exchangeName, String name)
047 {
048 this(exchangeName, new AMQShortString(name));
049 }
050
051
052 /**
053 * Create a reference to a non temporary queue. Note this does not actually imply the queue exists.
054 * @param name the name of the queue
055 */
056 public AMQQueue(AMQShortString exchangeName, AMQShortString name)
057 {
058 this(exchangeName, name, false);
059 }
060
061 public AMQQueue(AMQShortString exchangeName, AMQShortString routingKey, AMQShortString queueName)
062 {
063 super(exchangeName, ExchangeDefaults.DIRECT_EXCHANGE_CLASS, routingKey, false,
064 false, queueName, false);
065 }
066
067 public AMQQueue(AMQShortString exchangeName, AMQShortString routingKey, AMQShortString queueName,AMQShortString[] bindingKeys)
068 {
069 super(exchangeName, ExchangeDefaults.DIRECT_EXCHANGE_CLASS, routingKey, false,
070 false, queueName, false,bindingKeys);
071 }
072
073 /**
074 * Create a reference to a non temporary queue. Note this does not actually imply the queue exists.
075 * @param name the name of the queue
076 */
077 public AMQQueue(String exchangeName, String name)
078 {
079 this(new AMQShortString(exchangeName), new AMQShortString(name), false);
080 }
081
082
083 public AMQQueue(AMQConnection connection, String name)
084 {
085 this(connection.getDefaultQueueExchangeName(),name);
086 }
087
088 public AMQQueue(AMQConnection connection, String name, boolean temporary)
089 {
090 this(connection.getDefaultQueueExchangeName(), new AMQShortString(name),temporary);
091 }
092
093
094 /**
095 * Create a queue with a specified name.
096 *
097 * @param name the destination name (used in the routing key)
098 * @param temporary if true the broker will generate a queue name, also if true then the queue is autodeleted
099 * and exclusive
100 */
101 public AMQQueue(String exchangeName, String name, boolean temporary)
102 {
103 this(new AMQShortString(exchangeName), new AMQShortString(name),temporary);
104 }
105
106
107 /**
108 * Create a queue with a specified name.
109 *
110 * @param name the destination name (used in the routing key)
111 * @param temporary if true the broker will generate a queue name, also if true then the queue is autodeleted
112 * and exclusive
113 */
114 public AMQQueue(AMQShortString exchangeName, AMQShortString name, boolean temporary)
115 {
116 // queue name is set to null indicating that the broker assigns a name in the case of temporary queues
117 // temporary queues are typically used as response queues
118 this(exchangeName, name, temporary?null:name, temporary, temporary, !temporary);
119
120 }
121
122 /**
123 * Create a reference to a queue. Note this does not actually imply the queue exists.
124 * @param exchangeName the exchange name we want to send the message to
125 * @param routingKey the routing key
126 * @param queueName the queue name
127 * @param exclusive true if the queue should only permit a single consumer
128 * @param autoDelete true if the queue should be deleted automatically when the last consumers detaches
129 */
130 public AMQQueue(AMQShortString exchangeName, AMQShortString routingKey, AMQShortString queueName, boolean exclusive, boolean autoDelete)
131 {
132 this(exchangeName, routingKey, queueName, exclusive, autoDelete, false);
133 }
134
135 public AMQQueue(AMQShortString exchangeName, AMQShortString routingKey, AMQShortString queueName, boolean exclusive, boolean autoDelete, boolean durable)
136 {
137 this(exchangeName,routingKey,queueName,exclusive,autoDelete,durable,null);
138 }
139
140 public AMQQueue(AMQShortString exchangeName, AMQShortString routingKey, AMQShortString queueName, boolean exclusive, boolean autoDelete, boolean durable,AMQShortString[] bindingKeys)
141 {
142 super(exchangeName, ExchangeDefaults.DIRECT_EXCHANGE_CLASS, routingKey, exclusive,
143 autoDelete, queueName, durable, bindingKeys);
144 }
145
146 public AMQShortString getRoutingKey()
147 {
148 //return getAMQQueueName();
149 if (getAMQQueueName() != null && getAMQQueueName().equals(super.getRoutingKey()))
150 {
151 return getAMQQueueName();
152 }
153 else
154 {
155 return super.getRoutingKey();
156 }
157 }
158
159 public boolean isNameRequired()
160 {
161 //If the name is null, we require one to be generated by the client so that it will#
162 //remain valid if we failover (see BLZ-24)
163 return getQueueName() == null;
164 }
165 }
|