diff options
Diffstat (limited to 'java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java')
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java | 197 |
1 files changed, 71 insertions, 126 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java index e557085631..eada676b65 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java @@ -23,35 +23,66 @@ package org.apache.qpid.server.configuration; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; - -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.queue.AMQQueue; -import org.apache.qpid.server.registry.ApplicationRegistry; + +import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.store.MemoryMessageStore; -import java.util.ArrayList; -import java.util.Arrays; +import java.io.File; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -public class VirtualHostConfiguration extends ConfigurationPlugin +public class VirtualHostConfiguration extends AbstractConfiguration { private final String _name; private final Map<String, QueueConfiguration> _queues = new HashMap<String, QueueConfiguration>(); private final Map<String, ExchangeConfiguration> _exchanges = new HashMap<String, ExchangeConfiguration>(); + private final Broker _broker; + private final long _defaultHouseKeepingCheckPeriod; - public VirtualHostConfiguration(String name, Configuration config) throws ConfigurationException + public VirtualHostConfiguration(String name, Configuration config, Broker broker) throws ConfigurationException { _name = name; + _broker = broker; + + // store value of this attribute for running life of virtual host since updating of this value has no run-time effect + _defaultHouseKeepingCheckPeriod = ((Number)_broker.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).longValue(); setConfiguration(config); } + public VirtualHostConfiguration(String name, File configurationFile, Broker broker) throws ConfigurationException + { + this(name, loadConfiguration(name, configurationFile), broker); + } + + private static Configuration loadConfiguration(String name, File configurationFile) throws ConfigurationException + { + Configuration configuration = null; + if (configurationFile == null) + { + throw new IllegalConfigurationException("Virtualhost configuration file must be supplied!"); + } + else + { + Configuration virtualHostConfig = XmlConfigurationUtilities.parseConfig(configurationFile, null); + + // check if it is an old virtual host configuration file which has an element of the same name as virtual host + Configuration config = virtualHostConfig.subset("virtualhost." + XmlConfigurationUtilities.escapeTagName(name)); + if (config.isEmpty()) + { + // assume it is a new configuration which does not have an element of the same name as the virtual host + configuration = virtualHostConfig; + } + else + { + configuration = config; + } + } + return configuration; + } + /** * Apply the given configuration to this VirtualHostConfiguration * @@ -89,12 +120,7 @@ public class VirtualHostConfiguration extends ConfigurationPlugin public long getHousekeepingCheckPeriod() { - return getLongValue("housekeeping.checkPeriod", ApplicationRegistry.getInstance().getConfiguration().getHousekeepingCheckPeriod()); - } - - public List getCustomExchanges() - { - return getListValue("custom-exchanges.class-name"); + return getLongValue("housekeeping.checkPeriod", _defaultHouseKeepingCheckPeriod); } public Configuration getStoreConfiguration() @@ -149,138 +175,39 @@ public class VirtualHostConfiguration extends ConfigurationPlugin } } - public ConfigurationPlugin getQueueConfiguration(AMQQueue queue) - { - VirtualHostConfiguration hostConfig = queue.getVirtualHost().getConfiguration(); - - // First check if we have a named queue configuration (the easy case) - if (Arrays.asList(hostConfig.getQueueNames()).contains(queue.getName())) - { - return null; - } - - // We don't have an explicit queue config we must find out what we need. - ArrayList<Binding> bindings = new ArrayList<Binding>(queue.getBindings()); - - List<AMQShortString> exchangeClasses = new ArrayList<AMQShortString>(bindings.size()); - - //Remove default exchange - for (int index = 0; index < bindings.size(); index++) - { - // Ignore the DEFAULT Exchange binding - if (bindings.get(index).getExchange().getNameShortString().equals(ExchangeDefaults.DEFAULT_EXCHANGE_NAME)) - { - bindings.remove(index); - } - else - { - exchangeClasses.add(bindings.get(index).getExchange().getType().getName()); - - if (exchangeClasses.size() > 1) - { - // If we have more than 1 class of exchange then we can only use the global queue configuration. - // and this will be returned from the default getQueueConfiguration - return null; - } - } - } - - // If we are just bound the the default exchange then use the default. - if (bindings.isEmpty()) - { - return null; - } - - // If we are bound to only one type of exchange then we are going - // to have to resolve the configuration for that exchange. - - String exchangeName = bindings.get(0).getExchange().getType().getName().toString(); - - // Lookup a Configuration handler for this Exchange. - - // Build the expected class name. <Exchangename>sConfiguration - // i.e. TopicConfiguration or HeadersConfiguration - String exchangeClass = "org.apache.qpid.server.configuration." - + exchangeName.substring(0, 1).toUpperCase() - + exchangeName.substring(1) + "Configuration"; - - ExchangeConfigurationPlugin exchangeConfiguration - = (ExchangeConfigurationPlugin) queue.getVirtualHost().getConfiguration().getConfiguration(exchangeClass); - - // now need to perform the queue-topic-topics-queues magic. - // So make a new ConfigurationObject that will hold all the configuration for this queue. - ConfigurationPlugin queueConfig = new QueueConfiguration.QueueConfig(); - - // Initialise the queue with any Global values we may have - PropertiesConfiguration newQueueConfig = new PropertiesConfiguration(); - newQueueConfig.setProperty("name", queue.getName()); - - try - { - //Set the queue name - CompositeConfiguration mungedConf = new CompositeConfiguration(); - //Set the queue name - mungedConf.addConfiguration(newQueueConfig); - //Set the global queue configuration - mungedConf.addConfiguration(getConfig().subset("queues")); - - // Set configuration - queueConfig.setConfiguration("virtualhosts.virtualhost.queues", mungedConf); - } - catch (ConfigurationException e) - { - // This will not occur as queues only require a name. - _logger.error("QueueConfiguration requirements have changed."); - } - - // Merge any configuration the Exchange wishes to apply - if (exchangeConfiguration != null) - { - queueConfig.addConfiguration(exchangeConfiguration.getConfiguration(queue)); - } - - //Finally merge in any specific queue configuration we have. - if (_queues.containsKey(queue.getName())) - { - queueConfig.addConfiguration(_queues.get(queue.getName())); - } - - return queueConfig; - } - public int getMaximumMessageAge() { - return getIntValue("queues.maximumMessageAge"); + return getIntValue("queues.maximumMessageAge", getBrokerAttributeAsInt(Broker.ALERT_THRESHOLD_MESSAGE_AGE)); } public Long getMaximumQueueDepth() { - return getLongValue("queues.maximumQueueDepth"); + return getLongValue("queues.maximumQueueDepth", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_QUEUE_DEPTH)); } public Long getMaximumMessageSize() { - return getLongValue("queues.maximumMessageSize"); + return getLongValue("queues.maximumMessageSize", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_MESSAGE_SIZE)); } public Long getMaximumMessageCount() { - return getLongValue("queues.maximumMessageCount"); + return getLongValue("queues.maximumMessageCount", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_MESSAGE_COUNT)); } public Long getMinimumAlertRepeatGap() { - return getLongValue("queues.minimumAlertRepeatGap", ApplicationRegistry.getInstance().getConfiguration().getMinimumAlertRepeatGap()); + return getLongValue("queues.minimumAlertRepeatGap", getBrokerAttributeAsLong(Broker.ALERT_REPEAT_GAP)); } public long getCapacity() { - return getLongValue("queues.capacity"); + return getLongValue("queues.capacity", getBrokerAttributeAsLong(Broker.FLOW_CONTROL_SIZE_BYTES)); } public long getFlowResumeCapacity() { - return getLongValue("queues.flowResumeCapacity", getCapacity()); + return getLongValue("queues.flowResumeCapacity", getBrokerAttributeAsLong(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES)); } public String[] getElementsProcessed() @@ -336,7 +263,7 @@ public class VirtualHostConfiguration extends ConfigurationPlugin public int getMaxDeliveryCount() { - return getIntValue("queues.maximumDeliveryCount", ApplicationRegistry.getInstance().getConfiguration().getMaxDeliveryCount()); + return getIntValue("queues.maximumDeliveryCount", getBrokerAttributeAsInt(Broker.MAXIMUM_DELIVERY_ATTEMPTS)); } /** @@ -344,7 +271,25 @@ public class VirtualHostConfiguration extends ConfigurationPlugin */ public boolean isDeadLetterQueueEnabled() { - return getBooleanValue("queues.deadLetterQueues", ApplicationRegistry.getInstance().getConfiguration().isDeadLetterQueueEnabled()); + return getBooleanValue("queues.deadLetterQueues", getBrokerAttributeAsBoolean(Broker.DEAD_LETTER_QUEUE_ENABLED)); + } + + private long getBrokerAttributeAsLong(String name) + { + Number brokerValue = (Number)_broker.getAttribute(name); + return brokerValue == null? 0 : brokerValue.longValue(); + } + + private int getBrokerAttributeAsInt(String name) + { + Number brokerValue = (Number)_broker.getAttribute(name); + return brokerValue == null? 0 : brokerValue.intValue(); + } + + private boolean getBrokerAttributeAsBoolean(String name) + { + Boolean brokerValue = (Boolean)_broker.getAttribute(name); + return brokerValue == null? false : brokerValue.booleanValue(); } } |