01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.server.queue;
22
23 import org.apache.qpid.AMQException;
24 import org.apache.qpid.framing.AMQShortString;
25 import org.apache.qpid.framing.FieldTable;
26 import org.apache.qpid.server.configuration.QueueConfiguration;
27 import org.apache.qpid.server.virtualhost.VirtualHost;
28
29
30 public class AMQQueueFactory
31 {
32 public static final AMQShortString X_QPID_PRIORITIES = new AMQShortString("x-qpid-priorities");
33
34 public static AMQQueue createAMQQueueImpl(AMQShortString name,
35 boolean durable,
36 AMQShortString owner,
37 boolean autoDelete,
38 VirtualHost virtualHost, final FieldTable arguments)
39 throws AMQException
40 {
41
42 final int priorities = arguments == null ? 1 : arguments.containsKey(X_QPID_PRIORITIES) ? arguments.getInteger(X_QPID_PRIORITIES) : 1;
43
44 AMQQueue q = null;
45 if(priorities > 1)
46 {
47 q = new AMQPriorityQueue(name, durable, owner, autoDelete, virtualHost, priorities);
48 }
49 else
50 {
51 q = new SimpleAMQQueue(name, durable, owner, autoDelete, virtualHost);
52 }
53
54 //Register the new queue
55 virtualHost.getQueueRegistry().registerQueue(q);
56 return q;
57 }
58
59 public static AMQQueue createAMQQueueImpl(QueueConfiguration config, VirtualHost host) throws AMQException
60 {
61 AMQShortString queueName = new AMQShortString(config.getName());
62
63 boolean durable = config.getDurable();
64 boolean autodelete = config.getAutoDelete();
65 AMQShortString owner = (config.getOwner() != null) ? new AMQShortString(config.getOwner()) : null;
66 FieldTable arguments = null;
67 boolean priority = config.getPriority();
68 int priorities = config.getPriorities();
69 if(priority || priorities > 0)
70 {
71 if(arguments == null)
72 {
73 arguments = new FieldTable();
74 }
75 if (priorities < 0)
76 {
77 priorities = 10;
78 }
79 arguments.put(new AMQShortString("x-qpid-priorities"), priorities);
80 }
81
82 AMQQueue q = createAMQQueueImpl(queueName, durable, owner, autodelete, host, arguments);
83 q.setMaximumMessageAge(config.getMaximumMessageAge());
84 q.setMaximumQueueDepth(config.getMaximumQueueDepth());
85 q.setMaximumMessageSize(config.getMaximumMessageSize());
86 q.setMaximumMessageCount(config.getMaximumMessageCount());
87 q.setMinimumAlertRepeatGap(config.getMinimumAlertRepeatGap());
88 return q;
89 }
90 }
|