From 6b1c43afd9171e7b7053956b5656e89a98f14021 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Mon, 13 Apr 2009 14:23:52 +0000 Subject: QPID-1730: make it easy to configure queues, fix inheriting settings from the virtualhost. AMQQueue.configure: new method AMQQueueFactory: use AMQQueue.configure, don't set things directly SimpleAMQQueue.configure, MockAMQQueue.configure: implement new method from the interface QueueConfiguration: use VirtualHostConfiguration for default values if they're unset VirtualHostConfiguration: if a queue doesn't exist, give it a default configuration. Add methods to get default settings for configuration items QueueConfigurationTest: test case, checks that inheritance and defaults work along with explicitly set values. merged from trunk r761721 git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.5-fix@764484 13f79535-47bb-0310-9956-ffa450edef68 --- .../server/configuration/QueueConfiguration.java | 21 ++-- .../configuration/VirtualHostConfiguration.java | 79 +++++++++++- .../org/apache/qpid/server/queue/AMQQueue.java | 2 + .../apache/qpid/server/queue/AMQQueueFactory.java | 6 +- .../apache/qpid/server/queue/SimpleAMQQueue.java | 15 +++ .../configuration/QueueConfigurationTest.java | 139 +++++++++++++++++++++ .../org/apache/qpid/server/queue/MockAMQQueue.java | 8 +- 7 files changed, 252 insertions(+), 18 deletions(-) create mode 100644 qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java index 90d6caec99..99d2bf6067 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java @@ -26,18 +26,23 @@ import org.apache.commons.configuration.Configuration; public class QueueConfiguration { - - // FIXME AIDAN XXX -- deal with defaults private Configuration _config; private String _name; + private VirtualHostConfiguration _vHostConfig; public QueueConfiguration(String name, Configuration config) { + _vHostConfig = virtualHostConfiguration; _config = config; _name = name; } + public VirtualHostConfiguration getVirtualHostConfiguration() + { + return _vHostConfig; + } + public boolean getDurable() { return _config.getBoolean("durable" ,false); @@ -78,29 +83,29 @@ public class QueueConfiguration return _name; } - public long getMaximumMessageAge() + public int getMaximumMessageAge() { - return _config.getLong("maximumMessageAge", 0); + return _config.getInt("maximumMessageAge", _vHostConfig.getMaximumMessageAge()); } public long getMaximumQueueDepth() { - return _config.getLong("maximumQueueDepth", 0); + return _config.getLong("maximumQueueDepth", _vHostConfig.getMaximumQueueDepth()); } public long getMaximumMessageSize() { - return _config.getLong("maximumMessageSize", 0); + return _config.getLong("maximumMessageSize", _vHostConfig.getMaximumMessageSize()); } public long getMaximumMessageCount() { - return _config.getLong("maximumMessageCount", 0); + return _config.getLong("maximumMessageCount", _vHostConfig.getMaximumMessageCount()); } public long getMinimumAlertRepeatGap() { - return _config.getLong("minimumAlertRepeatGap", 0); + return _config.getLong("minimumAlertRepeatGap", _vHostConfig.getMinimumAlertRepeatGap()); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java index f51e515db1..1576cd4582 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java @@ -116,8 +116,79 @@ public class VirtualHostConfiguration return _queues.keySet().toArray(new String[_queues.size()]); } - public QueueConfiguration getQueueConfiguration(String queueName) - { - return _queues.get(queueName); - } + public List getExchanges() + { + return _config.getList("exchanges.exchange.name"); + } + + public ExchangeConfiguration getExchangeConfiguration(String exchangeName) + { + return _exchanges.get(exchangeName); + } + + public String[] getQueueNames() + { + return _queues.keySet().toArray(new String[_queues.size()]); + } + + public QueueConfiguration getQueueConfiguration(String queueName) + { + // We might be asked for the config for a queue we don't know about, + // such as one that's been dynamically created. Those get the defaults by default. + if (_queues.containsKey(queueName)) + { + return _queues.get(queueName); + } + else + { + return new QueueConfiguration(queueName, new PropertiesConfiguration(), this); + } + } + + public long getMemoryUsageMaximum() + { + return _config.getLong("queues.maximumMemoryUsage", 0); + } + + public long getMemoryUsageMinimum() + { + return _config.getLong("queues.minimumMemoryUsage", 0); + } + + public ServerConfiguration getServerConfiguration() + { + return _serverConfiguration; + } + + public static final String FLOW_TO_DISK_PATH = "flowToDiskPath"; + public String getFlowToDiskLocation() + { + return _config.getString(FLOW_TO_DISK_PATH, getServerConfiguration().getQpidWork()); + } + + public int getMaximumMessageAge() + { + return _config.getInt("queues.maximumMessageAge", 0); + } + + public Long getMaximumQueueDepth() + { + return _config.getLong("queues.maximumQueueDepth", 0); + } + + public Long getMaximumMessageSize() + { + return _config.getLong("queues.maximumMessageSize", 0); + } + + public Long getMaximumMessageCount() + { + return _config.getLong("queues.maximumMessageCount", 0); + } + + public Long getMinimumAlertRepeatGap() + { + return _config.getLong("queues.minimumAlertRepeatGap", 0); + } + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java index 5dc8703aef..b49cdde66e 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java @@ -214,4 +214,6 @@ public interface AMQQueue extends Managable, Comparable { public void doTask(AMQQueue queue) throws AMQException; } + + void configure(QueueConfiguration config); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java index eb0a011e93..84b59456cb 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java @@ -80,11 +80,7 @@ public class AMQQueueFactory } AMQQueue q = createAMQQueueImpl(queueName, durable, owner, autodelete, host, arguments); - q.setMaximumMessageAge(config.getMaximumMessageAge()); - q.setMaximumQueueDepth(config.getMaximumQueueDepth()); - q.setMaximumMessageSize(config.getMaximumMessageSize()); - q.setMaximumMessageCount(config.getMaximumMessageCount()); - q.setMinimumAlertRepeatGap(config.getMinimumAlertRepeatGap()); + q.configure(config); return q; } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java index 172a3af481..ca6e7a8ce6 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java @@ -19,6 +19,7 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.pool.ReadWriteRunnable; import org.apache.qpid.pool.ReferenceCountingExecutorService; +import org.apache.qpid.server.configuration.QueueConfiguration; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.management.ManagedObject; import org.apache.qpid.server.output.ProtocolOutputConverter; @@ -1584,4 +1585,18 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener } return ids; } + + public void configure(QueueConfiguration config) + { + if (config != null) + { + setMaximumMessageAge(config.getMaximumMessageAge()); + setMaximumQueueDepth(config.getMaximumQueueDepth()); + setMaximumMessageSize(config.getMaximumMessageSize()); + setMaximumMessageCount(config.getMaximumMessageCount()); + setMinimumAlertRepeatGap(config.getMinimumAlertRepeatGap()); + setMemoryUsageMaximum(config.getMemoryUsageMaximum()); + setMemoryUsageMinimum(config.getMemoryUsageMinimum()); + } + } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java new file mode 100644 index 0000000000..b3a792521a --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java @@ -0,0 +1,139 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.configuration; + +import junit.framework.TestCase; + +import org.apache.commons.configuration.PropertiesConfiguration; + +public class QueueConfigurationTest extends TestCase +{ + + private VirtualHostConfiguration _emptyConf; + private PropertiesConfiguration _env; + private ServerConfiguration _fullServerConf; + private VirtualHostConfiguration _fullHostConf; + + public void setUp() throws Exception + { + _env = new PropertiesConfiguration(); + ServerConfiguration emptyServerConfig; + emptyServerConfig = new ServerConfiguration(_env); + _emptyConf = new VirtualHostConfiguration("test", _env, emptyServerConfig); + + PropertiesConfiguration fullEnv = new PropertiesConfiguration(); + fullEnv.setProperty("queues.maximumMessageAge", 1); + fullEnv.setProperty("queues.maximumQueueDepth", 1); + fullEnv.setProperty("queues.maximumMessageSize", 1); + fullEnv.setProperty("queues.maximumMessageCount", 1); + fullEnv.setProperty("queues.minimumAlertRepeatGap", 1); + + _fullServerConf = new ServerConfiguration(fullEnv); + _fullHostConf = new VirtualHostConfiguration("test", fullEnv, _fullServerConf); + + } + + public void testGetMaximumMessageAge() + { + // Check default value + QueueConfiguration qConf = new QueueConfiguration("test", _env, _emptyConf); + assertEquals(0, qConf.getMaximumMessageAge()); + + // Check explicit value + PropertiesConfiguration fullEnv = new PropertiesConfiguration(); + fullEnv.setProperty("maximumMessageAge", 2); + qConf = new QueueConfiguration("test", fullEnv, _fullHostConf); + assertEquals(2, qConf.getMaximumMessageAge()); + + // Check inherited value + qConf = new QueueConfiguration("test", _env, _fullHostConf); + assertEquals(1, qConf.getMaximumMessageAge()); + } + + public void testGetMaximumQueueDepth() + { + // Check default value + QueueConfiguration qConf = new QueueConfiguration("test", _env, _emptyConf); + assertEquals(0, qConf.getMaximumQueueDepth()); + + // Check explicit value + PropertiesConfiguration fullEnv = new PropertiesConfiguration(); + fullEnv.setProperty("maximumQueueDepth", 2); + qConf = new QueueConfiguration("test", fullEnv, _fullHostConf); + assertEquals(2, qConf.getMaximumQueueDepth()); + + // Check inherited value + qConf = new QueueConfiguration("test", _env, _fullHostConf); + assertEquals(1, qConf.getMaximumQueueDepth()); + } + + public void testGetMaximumMessageSize() + { + // Check default value + QueueConfiguration qConf = new QueueConfiguration("test", _env, _emptyConf); + assertEquals(0, qConf.getMaximumMessageSize()); + + // Check explicit value + PropertiesConfiguration fullEnv = new PropertiesConfiguration(); + fullEnv.setProperty("maximumMessageSize", 2); + qConf = new QueueConfiguration("test", fullEnv, _fullHostConf); + assertEquals(2, qConf.getMaximumMessageSize()); + + // Check inherited value + qConf = new QueueConfiguration("test", _env, _fullHostConf); + assertEquals(1, qConf.getMaximumMessageSize()); + } + + public void testGetMaximumMessageCount() + { + // Check default value + QueueConfiguration qConf = new QueueConfiguration("test", _env, _emptyConf); + assertEquals(0, qConf.getMaximumMessageCount()); + + // Check explicit value + PropertiesConfiguration fullEnv = new PropertiesConfiguration(); + fullEnv.setProperty("maximumMessageCount", 2); + qConf = new QueueConfiguration("test", fullEnv, _fullHostConf); + assertEquals(2, qConf.getMaximumMessageCount()); + + // Check inherited value + qConf = new QueueConfiguration("test", _env, _fullHostConf); + assertEquals(1, qConf.getMaximumMessageCount()); + } + + public void testGetMinimumAlertRepeatGap() + { + // Check default value + QueueConfiguration qConf = new QueueConfiguration("test", _env, _emptyConf); + assertEquals(0, qConf.getMinimumAlertRepeatGap()); + + // Check explicit value + PropertiesConfiguration fullEnv = new PropertiesConfiguration(); + fullEnv.setProperty("minimumAlertRepeatGap", 2); + qConf = new QueueConfiguration("test", fullEnv, _fullHostConf); + assertEquals(2, qConf.getMinimumAlertRepeatGap()); + + // Check inherited value + qConf = new QueueConfiguration("test", _env, _fullHostConf); + assertEquals(1, qConf.getMinimumAlertRepeatGap()); + } + +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java index 3d44aac469..8e0712e27c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java @@ -22,8 +22,9 @@ package org.apache.qpid.server.queue; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.configuration.QueueConfiguration; +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.subscription.Subscription; import org.apache.qpid.server.store.StoreContext; @@ -325,4 +326,9 @@ public class MockAMQQueue implements AMQQueue } + public void configure(QueueConfiguration config) + { + + } + } -- cgit v1.2.1