diff options
Diffstat (limited to 'java/broker/src/main/java/org/apache/qpid/server/configuration')
62 files changed, 3147 insertions, 4633 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfig.java deleted file mode 100644 index 233134abc5..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * - * 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 java.util.Map; - - -public interface BindingConfig extends ConfiguredObject<BindingConfigType, BindingConfig> -{ - - ExchangeConfig getExchange(); - - QueueConfig getQueue(); - - String getBindingKey(); - - Map<String, Object> getArguments(); - - String getOrigin(); - - long getMatches(); -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfigType.java deleted file mode 100644 index 1ed6b38758..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfigType.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public final class BindingConfigType extends ConfigObjectType<BindingConfigType, BindingConfig> -{ - private static final List<BindingProperty<?>> BINDING_PROPERTIES = new ArrayList<BindingProperty<?>>(); - - public static interface BindingProperty<S> extends ConfigProperty<BindingConfigType, BindingConfig, S> - { - } - - private abstract static class BindingReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<BindingConfigType, BindingConfig, S> implements BindingProperty<S> - { - public BindingReadWriteProperty(String name) - { - super(name); - BINDING_PROPERTIES.add(this); - } - } - - private abstract static class BindingReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<BindingConfigType, BindingConfig, S> implements BindingProperty<S> - { - public BindingReadOnlyProperty(String name) - { - super(name); - BINDING_PROPERTIES.add(this); - } - } - - public static final BindingReadOnlyProperty<ExchangeConfig> EXCHANGE_PROPERTY = new BindingReadOnlyProperty<ExchangeConfig>("exchange") - { - public ExchangeConfig getValue(BindingConfig object) - { - return object.getExchange(); - } - }; - - public static final BindingReadOnlyProperty<QueueConfig> QUEUE_PROPERTY = new BindingReadOnlyProperty<QueueConfig>("queue") - { - public QueueConfig getValue(BindingConfig object) - { - return object.getQueue(); - } - }; - - public static final BindingReadOnlyProperty<String> BINDING_KEY_PROPERTY = new BindingReadOnlyProperty<String>("bindingKey") - { - public String getValue(BindingConfig object) - { - return object.getBindingKey(); - } - }; - - public static final BindingReadOnlyProperty<Map<String,Object>> ARGUMENTS = new BindingReadOnlyProperty<Map<String,Object>>("arguments") - { - public Map<String,Object> getValue(BindingConfig object) - { - return object.getArguments(); - } - }; - - public static final BindingReadOnlyProperty<String> ORIGIN_PROPERTY = new BindingReadOnlyProperty<String>("origin") - { - public String getValue(BindingConfig object) - { - return object.getOrigin(); - } - }; - - private static final BindingConfigType INSTANCE = new BindingConfigType(); - - private BindingConfigType() - { - } - - public Collection<BindingProperty<?>> getProperties() - { - return Collections.unmodifiableList(BINDING_PROPERTIES); - } - - public static BindingConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfig.java deleted file mode 100644 index 00ed5fd0dd..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * 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; - -public interface BridgeConfig extends ConfiguredObject<BridgeConfigType, BridgeConfig> -{ - - boolean isDynamic(); - - boolean isQueueBridge(); - - boolean isLocalSource(); - - String getSource(); - - String getDestination(); - - String getKey(); - - String getTag(); - - String getExcludes(); - - LinkConfig getLink(); - - Integer getChannelId(); - - int getAckBatching(); -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfigType.java deleted file mode 100644 index 888feeff0c..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfigType.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public final class BridgeConfigType extends ConfigObjectType<BridgeConfigType, BridgeConfig> -{ - private static final List<BridgeProperty<?>> BRIDGE_PROPERTIES = new ArrayList<BridgeProperty<?>>(); - - public static interface BridgeProperty<S> extends ConfigProperty<BridgeConfigType, BridgeConfig, S> - { - } - - private abstract static class BridgeReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<BridgeConfigType, BridgeConfig, S> implements BridgeProperty<S> - { - public BridgeReadWriteProperty(String name) - { - super(name); - BRIDGE_PROPERTIES.add(this); - } - } - - private abstract static class BridgeReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<BridgeConfigType, BridgeConfig, S> implements BridgeProperty<S> - { - public BridgeReadOnlyProperty(String name) - { - super(name); - BRIDGE_PROPERTIES.add(this); - } - } - - public static final BridgeReadOnlyProperty<LinkConfig> LINK_PROPERTY = new BridgeReadOnlyProperty<LinkConfig>("link") - { - public LinkConfig getValue(BridgeConfig object) - { - return object.getLink(); - } - }; - - public static final BridgeReadOnlyProperty<Integer> CHANNEL_ID_PROPERTY = new BridgeReadOnlyProperty<Integer>("channelId") - { - public Integer getValue(BridgeConfig object) - { - return object.getChannelId(); - } - }; - - public static final BridgeReadOnlyProperty<Boolean> DURABLE_PROPERTY = new BridgeReadOnlyProperty<Boolean>("durable") - { - public Boolean getValue(BridgeConfig object) - { - return object.isDurable(); - } - }; - - public static final BridgeReadOnlyProperty<String> SOURCE_PROPERTY = new BridgeReadOnlyProperty<String>("source") - { - public String getValue(BridgeConfig object) - { - return object.getSource(); - } - }; - - public static final BridgeReadOnlyProperty<String> DESTINATION_PROPERTY = new BridgeReadOnlyProperty<String>("destination") - { - public String getValue(BridgeConfig object) - { - return object.getDestination(); - } - }; - - public static final BridgeReadOnlyProperty<String> KEY_PROPERTY = new BridgeReadOnlyProperty<String>("key") - { - public String getValue(BridgeConfig object) - { - return object.getKey(); - } - }; - - public static final BridgeReadOnlyProperty<Boolean> QUEUE_BRIDGE_PROPERTY = new BridgeReadOnlyProperty<Boolean>("queueBridge") - { - public Boolean getValue(BridgeConfig object) - { - return object.isQueueBridge(); - } - }; - - public static final BridgeReadOnlyProperty<Boolean> LOCAL_SOURCE_PROPERTY = new BridgeReadOnlyProperty<Boolean>("localSource") - { - public Boolean getValue(BridgeConfig object) - { - return object.isLocalSource(); - } - }; - - public static final BridgeReadOnlyProperty<String> TAG_PROPERTY = new BridgeReadOnlyProperty<String>("tag") - { - public String getValue(BridgeConfig object) - { - return object.getTag(); - } - }; - - public static final BridgeReadOnlyProperty<String> EXCLUDES_PROPERTY = new BridgeReadOnlyProperty<String>("excludes") - { - public String getValue(BridgeConfig object) - { - return object.getExcludes(); - } - }; - - public static final BridgeReadOnlyProperty<Boolean> DYNAMIC_PROPERTY = new BridgeReadOnlyProperty<Boolean>("dynamic") - { - public Boolean getValue(BridgeConfig object) - { - return object.isDynamic(); - } - }; - - public static final BridgeReadOnlyProperty<Integer> ACK_BATCHING_PROPERTY = new BridgeReadOnlyProperty<Integer>("ackBatching") - { - public Integer getValue(BridgeConfig object) - { - return object.getAckBatching(); - } - }; - - - private static final BridgeConfigType INSTANCE = new BridgeConfigType(); - - private BridgeConfigType() - { - } - - public Collection<BridgeProperty<?>> getProperties() - { - return Collections.unmodifiableList(BRIDGE_PROPERTIES); - } - - public static BridgeConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfig.java deleted file mode 100644 index 7dffc2d3c0..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfig.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * 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 java.util.List; - - -public interface BrokerConfig extends ConfiguredObject<BrokerConfigType,BrokerConfig> -{ - void setSystem(SystemConfig system); - - SystemConfig getSystem(); - - Integer getPort(); - - Integer getWorkerThreads(); - - Integer getMaxConnections(); - - Integer getConnectionBacklogLimit(); - - Long getStagingThreshold(); - - Integer getManagementPublishInterval(); - - String getVersion(); - - String getDataDirectory(); - - String getFederationTag(); - - /** - * List of feature(s) to be advertised to clients on connection. - * Feature names are strings, beginning with qpid. followed by more or more - * words separated by minus signs e.g. qpid.jms-selector. - * - * If there are no features, this method must return an empty array. - * - * @return list of feature names - */ - List<String> getFeatures(); - - void addVirtualHost(VirtualHostConfig virtualHost); - - void createBrokerConnection(String transport, - String host, - int port, - boolean durable, - String authMechanism, - String username, String password); - -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigType.java deleted file mode 100644 index 64a59c3f61..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigType.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public final class BrokerConfigType extends ConfigObjectType<BrokerConfigType, BrokerConfig> -{ - private static final List<BrokerProperty<?>> BROKER_PROPERTIES = new ArrayList<BrokerProperty<?>>(); - - public static interface BrokerProperty<S> extends ConfigProperty<BrokerConfigType, BrokerConfig, S> - { - } - - private abstract static class BrokerReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<BrokerConfigType, BrokerConfig, S> implements BrokerProperty<S> - { - public BrokerReadWriteProperty(String name) - { - super(name); - BROKER_PROPERTIES.add(this); - } - } - - private abstract static class BrokerReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<BrokerConfigType, BrokerConfig, S> implements BrokerProperty<S> - { - public BrokerReadOnlyProperty(String name) - { - super(name); - BROKER_PROPERTIES.add(this); - } - } - - public static final BrokerReadOnlyProperty<SystemConfig> SYSTEM_PROPERTY = new BrokerReadOnlyProperty<SystemConfig>("system") - { - public SystemConfig getValue(BrokerConfig object) - { - return object.getSystem(); - } - }; - - public static final BrokerReadOnlyProperty<Integer> PORT_PROPERTY = new BrokerReadOnlyProperty<Integer>("port") - { - public Integer getValue(BrokerConfig object) - { - return object.getPort(); - } - }; - - public static final BrokerReadOnlyProperty<Integer> WORKER_THREADS_PROPERTY = new BrokerReadOnlyProperty<Integer>("workerThreads") - { - public Integer getValue(BrokerConfig object) - { - return object.getWorkerThreads(); - } - }; - - public static final BrokerReadOnlyProperty<Integer> MAX_CONNECTIONS_PROPERTY = new BrokerReadOnlyProperty<Integer>("maxConnections") - { - public Integer getValue(BrokerConfig object) - { - return object.getMaxConnections(); - } - }; - - public static final BrokerReadOnlyProperty<Integer> CONNECTION_BACKLOG_LIMIT_PROPERTY = new BrokerReadOnlyProperty<Integer>("connectionBacklog") - { - public Integer getValue(BrokerConfig object) - { - return object.getConnectionBacklogLimit(); - } - }; - - public static final BrokerReadOnlyProperty<Long> STAGING_THRESHOLD_PROPERTY = new BrokerReadOnlyProperty<Long>("stagingThreshold") - { - public Long getValue(BrokerConfig object) - { - return object.getStagingThreshold(); - } - }; - - public static final BrokerReadOnlyProperty<Integer> MANAGEMENT_PUBLISH_INTERVAL_PROPERTY = new BrokerReadOnlyProperty<Integer>("mgmtPublishInterval") - { - public Integer getValue(BrokerConfig object) - { - return object.getManagementPublishInterval(); - } - }; - - public static final BrokerReadOnlyProperty<String> VERSION_PROPERTY = new BrokerReadOnlyProperty<String>("version") - { - public String getValue(BrokerConfig object) - { - return object.getVersion(); - } - }; - - public static final BrokerReadOnlyProperty<String> DATA_DIR_PROPERTY = new BrokerReadOnlyProperty<String>("dataDirectory") - { - public String getValue(BrokerConfig object) - { - return object.getDataDirectory(); - } - }; - - private static final BrokerConfigType INSTANCE = new BrokerConfigType(); - - private BrokerConfigType() - { - } - - public Collection<BrokerProperty<?>> getProperties() - { - return Collections.unmodifiableList(BROKER_PROPERTIES); - } - - public static BrokerConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java new file mode 100644 index 0000000000..31e08ab88a --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java @@ -0,0 +1,102 @@ +/* + * + * 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 java.util.HashMap; +import java.util.Map; + +import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore; +import org.apache.qpid.server.plugin.QpidServiceLoader; + +/** + * A helper class responsible for creation and opening of broker store. + */ +public class BrokerConfigurationStoreCreator +{ + /** + * URL to resource containing broker default configuration + */ + public static final String DEFAULT_INITIAL_STORE_LOCATION = BrokerConfigurationStoreCreator.class.getClassLoader() + .getResource("initial-store.json").toExternalForm(); + + private Map<String, ConfigurationStoreFactory> _factories = new HashMap<String, ConfigurationStoreFactory>(); + + public BrokerConfigurationStoreCreator() + { + QpidServiceLoader<ConfigurationStoreFactory> serviceLoader = new QpidServiceLoader<ConfigurationStoreFactory>(); + Iterable<ConfigurationStoreFactory> configurationStoreFactories = serviceLoader + .instancesOf(ConfigurationStoreFactory.class); + for (ConfigurationStoreFactory storeFactory : configurationStoreFactories) + { + String type = storeFactory.getStoreType(); + ConfigurationStoreFactory factory = _factories.put(type.toLowerCase(), storeFactory); + if (factory != null) + { + throw new IllegalStateException("ConfigurationStoreFactory with type name '" + type + + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '" + + storeFactory.getClass().getName() + "'"); + } + } + } + + /** + * Create broker configuration store for a given store location, store type, initial store location and initial store type + * + * @param storeLocation store location + * @param storeType store type + * @param initialStoreLocation initial store location + * @param initialStoreType initial store type + * @return store instance opened at given store location + * @throws IllegalConfigurationException if store type is unknown + */ + public ConfigurationEntryStore createStore(String storeLocation, String storeType, String initialStoreLocation, + String initialStoreType) + { + ConfigurationEntryStore store = createStore(storeType); + if (initialStoreLocation == null) + { + initialStoreLocation = DEFAULT_INITIAL_STORE_LOCATION; + initialStoreType = JsonConfigurationEntryStore.STORE_TYPE; + } + if (storeType.equals(initialStoreType)) + { + store.open(storeLocation, initialStoreLocation); + } + else + { + ConfigurationEntryStore initialStore = createStore(initialStoreType); + initialStore.open(initialStoreLocation); + store.open(storeLocation, initialStore); + } + return store; + } + + private ConfigurationEntryStore createStore(String storeType) + { + ConfigurationStoreFactory factory = _factories.get(storeType.toLowerCase()); + if (factory == null) + { + throw new IllegalConfigurationException("Unknown store type: " + storeType); + } + return factory.createStore(); + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java new file mode 100644 index 0000000000..179d4a5640 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java @@ -0,0 +1,54 @@ +package org.apache.qpid.server.configuration; + +import java.util.Locale; + +/** + * Declares broker system property names + */ +public class BrokerProperties +{ + public static final int DEFAULT_HEART_BEAT_TIMEOUT_FACTOR = 2; + + public static final String PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX = "qpid.dead_letter_exchange_suffix"; + public static final String PROPERTY_DEAD_LETTER_QUEUE_SUFFIX = "qpid.dead_letter_queue_suffix"; + + public static final String PROPERTY_FRAME_SIZE = "qpid.frame_size"; + public static final String PROPERTY_MSG_AUTH = "qpid.msg_auth"; + public static final String PROPERTY_STATUS_UPDATES = "qpid.status_updates"; + public static final String PROPERTY_LOCALE = "qpid.locale"; + public static final String PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY = "qpid.default_supported_protocol_version_reply"; + public static final String PROPERTY_DISABLED_FEATURES = "qpid.broker_disabled_features"; + + public static final int DEFAULT_FRAME_SIZE = Integer.getInteger(PROPERTY_FRAME_SIZE, 65535); + public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES = "qpid.broker_default_amqp_protocol_excludes"; + public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES = "qpid.broker_default_amqp_protocol_includes"; + + public static final String PROPERTY_MANAGEMENT_RIGHTS_INFER_ALL_ACCESS = "qpid.broker_jmx_method_rights_infer_all_access"; + public static final String PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY = "qpid.broker_jmx_use_custom_rmi_socket_factory"; + + public static final String PROPERTY_QPID_HOME = "QPID_HOME"; + public static final String PROPERTY_QPID_WORK = "QPID_WORK"; + + private BrokerProperties() + { + } + + public static Locale getLocale() + { + Locale locale = Locale.US; + String localeSetting = System.getProperty(BrokerProperties.PROPERTY_LOCALE); + if (localeSetting != null) + { + String[] localeParts = localeSetting.split("_"); + String language = (localeParts.length > 0 ? localeParts[0] : ""); + String country = (localeParts.length > 1 ? localeParts[1] : ""); + String variant = ""; + if (localeParts.length > 2) + { + variant = localeSetting.substring(language.length() + 1 + country.length() + 1); + } + locale = new Locale(language, country, variant); + } + return locale; + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigProperty.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigProperty.java deleted file mode 100644 index 2d88ba00a0..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigProperty.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * 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; - -public interface ConfigProperty<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>, S> -{ - public String getName(); - - public S getValue(C object); - - public void setValue(C object, S value); - - public void clearValue(C object); - - public abstract static class ReadWriteConfigProperty<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>,S> implements ConfigProperty<T, C, S> - { - private final String _name; - - protected ReadWriteConfigProperty(String name) - { - _name = name; - } - - public final String getName() - { - return _name; - } - } - - public abstract static class ReadOnlyConfigProperty<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>, S> extends ReadWriteConfigProperty<T, C, S> - { - protected ReadOnlyConfigProperty(String name) - { - super(name); - } - - public final void setValue(C object, S value) - { - throw new UnsupportedOperationException("Cannot set value '"+getName()+"' as this property is read-only"); - } - - public final void clearValue(C object) - { - throw new UnsupportedOperationException("Cannot set value '"+getName()+"' as this property is read-only"); - } - } -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java deleted file mode 100644 index c519a0c0fa..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * 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 java.util.Collection; -import java.util.Collections; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - -public class ConfigStore -{ - private ConcurrentHashMap<ConfigObjectType, ConcurrentHashMap<UUID, ConfiguredObject>> _typeMap = - new ConcurrentHashMap<ConfigObjectType, ConcurrentHashMap<UUID, ConfiguredObject>>(); - - private ConcurrentHashMap<ConfigObjectType, CopyOnWriteArrayList<ConfigEventListener>> _listenerMap = - new ConcurrentHashMap<ConfigObjectType, CopyOnWriteArrayList<ConfigEventListener>>(); - - private AtomicReference<SystemConfig> _root = new AtomicReference<SystemConfig>(null); - - private final AtomicLong _objectIdSource = new AtomicLong(0l); - private final AtomicLong _persistentObjectIdSource = new AtomicLong(0l); - - // TODO - should load/increment this on broker startup - private long _sequenceNumber = 1L; - - public enum Event - { - CREATED, DELETED - } - - public interface ConfigEventListener<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T, C>> - { - void onEvent(C object, Event evt); - } - - private ConfigStore() - { - } - - public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> ConfiguredObject<T, C> getConfiguredObject(ConfigObjectType<T,C> type, UUID id) - { - ConcurrentHashMap<UUID, ConfiguredObject> typeMap = _typeMap.get(type); - if(typeMap != null) - { - return typeMap.get(id); - } - else - { - return null; - } - - } - - public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> Collection<? extends C> getConfiguredObjects(ConfigObjectType<T,C> type) - { - ConcurrentHashMap typeMap = _typeMap.get(type); - if(typeMap != null) - { - return typeMap.values(); - } - else - { - return Collections.EMPTY_LIST; - } - - } - - public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void addConfiguredObject(ConfiguredObject<T, C> object) - { - ConcurrentHashMap typeMap = _typeMap.get(object.getConfigType()); - if(typeMap == null) - { - typeMap = new ConcurrentHashMap(); - ConcurrentHashMap oldMap = _typeMap.putIfAbsent(object.getConfigType(), typeMap); - if(oldMap != null) - { - typeMap = oldMap; - } - - } - - typeMap.put(object.getQMFId(), object); - sendEvent(Event.CREATED, object); - } - - - public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void removeConfiguredObject(ConfiguredObject<T, C> object) - { - ConcurrentHashMap typeMap = _typeMap.get(object.getConfigType()); - if(typeMap != null) - { - typeMap.remove(object.getQMFId()); - sendEvent(Event.DELETED, object); - } - } - - public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void addConfigEventListener(T type, ConfigEventListener<T,C> listener) - { - CopyOnWriteArrayList listeners = _listenerMap.get(type); - if(listeners == null) - { - listeners = new CopyOnWriteArrayList(); - CopyOnWriteArrayList oldListeners = _listenerMap.putIfAbsent(type, listeners); - if(oldListeners != null) - { - listeners = oldListeners; - } - - } - - listeners.add(listener); - - } - - public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void removeConfigEventListener(T type, ConfigEventListener<T,C> listener) - { - CopyOnWriteArrayList listeners = _listenerMap.get(type); - if(listeners != null) - { - listeners.remove(listener); - } - } - - private void sendEvent(Event e, ConfiguredObject o) - { - CopyOnWriteArrayList<ConfigEventListener> listeners = _listenerMap.get(o.getConfigType()); - if(listeners != null) - { - for(ConfigEventListener listener : listeners) - { - listener.onEvent(o, e); - } - } - } - - public boolean setRoot(SystemConfig object) - { - if(_root.compareAndSet(null,object)) - { - addConfiguredObject(object); - return true; - } - else - { - return false; - } - } - - public UUID createId() - { - return new UUID(((_sequenceNumber & 0xFFFl)<<48), _objectIdSource.incrementAndGet()); - } - - public UUID createPersistentId() - { - return new UUID(0L, _persistentObjectIdSource.incrementAndGet()); - } - - public void persistentIdInUse(UUID id) - { - long lsb = id.getLeastSignificantBits(); - long currentId; - while((currentId = _persistentObjectIdSource.get()) < lsb) - { - _persistentObjectIdSource.compareAndSet(currentId, lsb); - } - } - - public SystemConfig getRoot() - { - return _root.get(); - } - - public static ConfigStore newInstance() - { - return new ConfigStore(); - } - -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java new file mode 100644 index 0000000000..8afb1af24d --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java @@ -0,0 +1,203 @@ +/* + * + * 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 java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +public class ConfigurationEntry +{ + public static final String ATTRIBUTE_NAME = "name"; + + private final UUID _id; + private final String _type; + private final Map<String, Object> _attributes; + private final Set<UUID> _childrenIds; + private final ConfigurationEntryStore _store; + + public ConfigurationEntry(UUID id, String type, Map<String, Object> attributes, Set<UUID> childrenIds, + ConfigurationEntryStore store) + { + super(); + _id = id; + _type = type; + _attributes = attributes; + _childrenIds = childrenIds; + _store = store; + } + + public UUID getId() + { + return _id; + } + + public String getType() + { + return _type; + } + + public Map<String, Object> getAttributes() + { + return _attributes; + } + + public Set<UUID> getChildrenIds() + { + return _childrenIds; + } + + public ConfigurationEntryStore getStore() + { + return _store; + } + + /** + * Returns this entry's children. The collection should not be modified. + */ + public Map<String, Collection<ConfigurationEntry>> getChildren() + { + Map<String, Collection<ConfigurationEntry>> children = null; + if (_childrenIds == null) + { + children = Collections.emptyMap(); + } + else + { + children = new HashMap<String, Collection<ConfigurationEntry>>(); + for (UUID childId : _childrenIds) + { + ConfigurationEntry entry = _store.getEntry(childId); + String type = entry.getType(); + Collection<ConfigurationEntry> childrenOfType = children.get(type); + if (childrenOfType == null) + { + childrenOfType = new ArrayList<ConfigurationEntry>(); + children.put(type, childrenOfType); + } + childrenOfType.add(entry); + } + } + return Collections.unmodifiableMap(children); + } + + public boolean hasChild(UUID id) + { + return _childrenIds.contains(id); + } + + @Override + public int hashCode() + { + return _id.hashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + + ConfigurationEntry other = (ConfigurationEntry) obj; + if (_id == null) + { + if (other._id != null) + { + return false; + } + } + else if (!_id.equals(other._id)) + { + return false; + } + + if (_type == null) + { + if (other._type != null) + { + return false; + } + } + else if (!_type.equals(other._type)) + { + return false; + } + + if (_store == null) + { + if (other._store != null) + { + return false; + } + } + else if (!_store.equals(other._store)) + { + return false; + } + + if (_childrenIds == null) + { + if (other._childrenIds != null) + { + return false; + } + } + else if (!_childrenIds.equals(other._childrenIds)) + { + return false; + } + + if (_attributes == null) + { + if (other._attributes != null) + { + return false; + } + } + else if (!_attributes.equals(other._attributes)) + { + return false; + } + return true; + } + + @Override + public String toString() + { + return "ConfigurationEntry [id=" + _id + ", type=" + _type + ", attributes=" + _attributes + ", childrenIds=" + + _childrenIds + "]"; + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java new file mode 100644 index 0000000000..8238d147bd --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java @@ -0,0 +1,98 @@ +/* + * + * 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 java.util.UUID; + +public interface ConfigurationEntryStore +{ + /** + * Opens the store from a given location. + * <p> + * If location does not exists than a new empty store is created with a single root entry + * + * @param storeLocation store location + * @throws IllegalConfigurationException if store cannot be opened in the given location + */ + void open(String storeLocation); + + /** + * Opens the store from a given location. + * <p> + * If location does not exists than a new store is created either empty or from the initial store location if it is provided + * + * @param storeLocation store location + * @param initialStoreLocation initial store location + * @throws IllegalConfigurationException if store cannot be opened in the given location or initial store location does not + * exists or corrupted. + */ + void open(String storeLocation, String initialStoreLocation); + + /** + * Opens the store from a given location. + * <p> + * If location does not exists than a new store is created either empty or from the initial store if it is provided + * + * @param storeLocation store location + * @param initialStore initial store + * @throws IllegalConfigurationException if store cannot be opened in the given location + */ + void open(String storeLocation, ConfigurationEntryStore initialStore); + + /** + * Returns stored root configuration entry + * + * @return root entry + */ + ConfigurationEntry getRootEntry(); + + /** + * Returns the configuration entry with a given id. + * + * @return entry with a given id or null if entry does not exists + */ + ConfigurationEntry getEntry(UUID id); + + /** + * Saves given entries in the store. + * + * @param entries entries to store + * @throws IllegalConfigurationException if save operation fails + */ + void save(ConfigurationEntry... entries); + + /** + * Removes the entries with given IDs and all their children + * + * @param entryIds IDs of entries to remove + * @return IDs of removed entries + * @throws IllegalConfigurationException if remove operation fails + */ + UUID[] remove(UUID... entryIds); + + /** + * Copies the store into the given location + * + * @param target location to copy store into + * @throws IllegalConfigurationException if store cannot be copied into given location + */ + public void copyTo(String copyLocation); +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java deleted file mode 100644 index 06402fa646..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * 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 org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; -import org.apache.qpid.server.registry.ApplicationRegistry; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class ConfigurationManager -{ - public List<ConfigurationPlugin> getConfigurationPlugins(String configurationElement, Configuration configuration) throws ConfigurationException - { - List<ConfigurationPlugin> plugins = new ArrayList<ConfigurationPlugin>(); - Map<List<String>, ConfigurationPluginFactory> factories = - ApplicationRegistry.getInstance().getPluginManager().getConfigurationPlugins(); - - for (Entry<List<String>, ConfigurationPluginFactory> entry : factories.entrySet()) - { - if (entry.getKey().contains(configurationElement)) - { - ConfigurationPluginFactory factory = entry.getValue(); - plugins.add(factory.newInstance(configurationElement, configuration)); - } - } - - return plugins; - } -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigObjectType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java index c45aaaf1ee..dced38d260 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigObjectType.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java @@ -18,13 +18,18 @@ * under the License. * */ - package org.apache.qpid.server.configuration; -import java.util.Collection; -public abstract class ConfigObjectType<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>> +public interface ConfigurationStoreFactory { - public abstract Collection<? extends ConfigProperty<T, C, ?>> getProperties(); + /** + * Returns the type of the store this factory can create + */ + public String getStoreType(); + /** + * Creates the store instance. + */ + public ConfigurationEntryStore createStore(); } diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigurationPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java index bfb2de4235..65d97e6db1 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigurationPlugin.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java @@ -20,10 +20,9 @@ */ package org.apache.qpid.server.configuration; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.model.ConfiguredObject; -public interface ExchangeConfigurationPlugin +public interface ConfiguredObjectRecoverer<T extends ConfiguredObject> { - ConfigurationPlugin getConfiguration(AMQQueue queue); + T create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents); } diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfig.java deleted file mode 100644 index 0dd36fe1fe..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfig.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * 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; - -public interface ConnectionConfig extends ConfiguredObject<ConnectionConfigType, ConnectionConfig> -{ - VirtualHostConfig getVirtualHost(); - - String getAddress(); - - Boolean isIncoming(); - - Boolean isSystemConnection(); - - Boolean isFederationLink(); - - String getAuthId(); - - String getRemoteProcessName(); - - Integer getRemotePID(); - - Integer getRemoteParentPID(); - - ConfigStore getConfigStore(); - - Boolean isShadow(); - - void mgmtClose(); -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfigType.java deleted file mode 100644 index 5631fda37c..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfigType.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public final class ConnectionConfigType extends ConfigObjectType<ConnectionConfigType, ConnectionConfig> -{ - private static final List<ConnectionProperty<?>> CONNECTION_PROPERTIES = new ArrayList<ConnectionProperty<?>>(); - - public static interface ConnectionProperty<S> extends ConfigProperty<ConnectionConfigType, ConnectionConfig, S> - { - } - - private abstract static class ConnectionReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<ConnectionConfigType, ConnectionConfig, S> implements ConnectionProperty<S> - { - public ConnectionReadWriteProperty(String name) - { - super(name); - CONNECTION_PROPERTIES.add(this); - } - } - - private abstract static class ConnectionReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<ConnectionConfigType, ConnectionConfig, S> implements ConnectionProperty<S> - { - public ConnectionReadOnlyProperty(String name) - { - super(name); - CONNECTION_PROPERTIES.add(this); - } - } - - public static final ConnectionReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new ConnectionReadOnlyProperty<VirtualHostConfig>("virtualHost") - { - public VirtualHostConfig getValue(ConnectionConfig object) - { - return object.getVirtualHost(); - } - }; - - public static final ConnectionReadOnlyProperty<String> ADDRESS_PROPERTY = new ConnectionReadOnlyProperty<String>("address") - { - public String getValue(ConnectionConfig object) - { - return object.getAddress(); - } - }; - - public static final ConnectionReadOnlyProperty<Boolean> INCOMING_PROPERTY = new ConnectionReadOnlyProperty<Boolean>("incoming") - { - public Boolean getValue(ConnectionConfig object) - { - return object.isIncoming(); - } - }; - - public static final ConnectionReadOnlyProperty<Boolean> SYSTEM_CONNECTION_PROPERTY = new ConnectionReadOnlyProperty<Boolean>("systemConnection") - { - public Boolean getValue(ConnectionConfig object) - { - return object.isSystemConnection(); - } - }; - - public static final ConnectionReadOnlyProperty<Boolean> FEDERATION_LINK_PROPERTY = new ConnectionReadOnlyProperty<Boolean>("federationLink") - { - public Boolean getValue(ConnectionConfig object) - { - return object.isFederationLink(); - } - }; - - public static final ConnectionReadOnlyProperty<String> AUTH_ID_PROPERTY = new ConnectionReadOnlyProperty<String>("authId") - { - public String getValue(ConnectionConfig object) - { - return object.getAuthId(); - } - }; - - public static final ConnectionReadOnlyProperty<String> REMOTE_PROCESS_NAME_PROPERTY = new ConnectionReadOnlyProperty<String>("remoteProcessName") - { - public String getValue(ConnectionConfig object) - { - return object.getRemoteProcessName(); - } - }; - - - public static final ConnectionReadOnlyProperty<Integer> REMOTE_PID_PROPERTY = new ConnectionReadOnlyProperty<Integer>("remotePid") - { - public Integer getValue(ConnectionConfig object) - { - return object.getRemotePID(); - } - }; - - public static final ConnectionReadOnlyProperty<Integer> REMOTE_PARENT_PID_PROPERTY = new ConnectionReadOnlyProperty<Integer>("remoteParentPid") - { - public Integer getValue(ConnectionConfig object) - { - return object.getRemoteParentPID(); - } - }; - - private static final ConnectionConfigType INSTANCE = new ConnectionConfigType(); - - private ConnectionConfigType() - { - } - - public Collection<ConnectionProperty<?>> getProperties() - { - return Collections.unmodifiableList(CONNECTION_PROPERTIES); - } - - public static ConnectionConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfig.java deleted file mode 100644 index 6633d93adf..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * 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 org.apache.qpid.server.exchange.ExchangeType; - -import java.util.Map; - - -public interface ExchangeConfig extends ConfiguredObject<ExchangeConfigType, ExchangeConfig> -{ - VirtualHostConfig getVirtualHost(); - - String getName(); - - ExchangeType getType(); - - boolean isAutoDelete(); - - ExchangeConfig getAlternateExchange(); - - Map<String, Object> getArguments(); - - - long getBindingCount(); - - long getBindingCountHigh(); - - long getMsgReceives(); - - long getMsgRoutes(); - - long getMsgDrops(); - - long getByteReceives(); - - long getByteRoutes(); - - long getByteDrops(); - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigType.java deleted file mode 100644 index c7744117c4..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigType.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public final class ExchangeConfigType extends ConfigObjectType<ExchangeConfigType, ExchangeConfig> -{ - private static final List<ExchangeProperty<?>> EXCHANGE_PROPERTIES = new ArrayList<ExchangeProperty<?>>(); - - public static interface ExchangeProperty<S> extends ConfigProperty<ExchangeConfigType, ExchangeConfig, S> - { - } - - private abstract static class ExchangeReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<ExchangeConfigType, ExchangeConfig, S> implements ExchangeProperty<S> - { - public ExchangeReadWriteProperty(String name) - { - super(name); - EXCHANGE_PROPERTIES.add(this); - } - } - - private abstract static class ExchangeReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<ExchangeConfigType, ExchangeConfig, S> implements ExchangeProperty<S> - { - public ExchangeReadOnlyProperty(String name) - { - super(name); - EXCHANGE_PROPERTIES.add(this); - } - } - - public static final ExchangeReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new ExchangeReadOnlyProperty<VirtualHostConfig>("virtualHost") - { - public VirtualHostConfig getValue(ExchangeConfig object) - { - return object.getVirtualHost(); - } - }; - - public static final ExchangeReadOnlyProperty<String> NAME_PROPERTY = new ExchangeReadOnlyProperty<String>("name") - { - public String getValue(ExchangeConfig object) - { - return object.getName(); - } - }; - - public static final ExchangeReadOnlyProperty<Boolean> AUTODELETE_PROPERTY = new ExchangeReadOnlyProperty<Boolean>("autodelete") - { - public Boolean getValue(ExchangeConfig object) - { - return object.isAutoDelete(); - } - }; - - - public static final ExchangeReadOnlyProperty<ExchangeConfig> ALTERNATE_EXCHANGE_PROPERTY = new ExchangeReadOnlyProperty<ExchangeConfig>("alternateExchange") - { - public ExchangeConfig getValue(ExchangeConfig object) - { - return object.getAlternateExchange(); - } - }; - - public static final ExchangeReadOnlyProperty<Map<String,Object>> ARGUMENTS = new ExchangeReadOnlyProperty<Map<String,Object>>("arguments") - { - public Map<String,Object> getValue(ExchangeConfig object) - { - return object.getArguments(); - } - }; - - private static final ExchangeConfigType INSTANCE = new ExchangeConfigType(); - - private ExchangeConfigType() - { - } - - public Collection<ExchangeProperty<?>> getProperties() - { - return Collections.unmodifiableList(EXCHANGE_PROPERTIES); - } - - public static ExchangeConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java index 8a9029fbfd..bedd470ddf 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfig.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java @@ -18,25 +18,20 @@ * under the License. * */ - package org.apache.qpid.server.configuration; -public interface SystemConfig extends ConfiguredObject<SystemConfigType,SystemConfig> +public class IllegalConfigurationException extends RuntimeException { - String getName(); - - String getOperatingSystemName(); - - String getNodeName(); - - - String getOSRelease(); - - String getOSVersion(); + private static final long serialVersionUID = 1130064756291179812L; - String getOSArchitecture(); + public IllegalConfigurationException(String message) + { + super(message); + } - void addBroker(BrokerConfig broker); + public IllegalConfigurationException(String message, Throwable cause) + { + super(message, cause); + } - void removeBroker(BrokerConfig broker); } diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfig.java deleted file mode 100644 index 2c37a94db0..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfig.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * 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; - -public interface LinkConfig extends ConfiguredObject<LinkConfigType, LinkConfig> -{ - VirtualHostConfig getVirtualHost(); - - - String getTransport(); - - String getHost(); - - int getPort(); - - String getRemoteVhost(); - - String getAuthMechanism(); - - String getUsername(); - - String getPassword(); - - void close(); - - void createBridge(boolean durable, - boolean dynamic, - boolean srcIsQueue, - boolean srcIsLocal, - String src, - String dest, - String key, String tag, String excludes); - - String getState(); - - String getLastError(); -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfigType.java deleted file mode 100644 index 847cae87f5..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfigType.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public final class LinkConfigType extends ConfigObjectType<LinkConfigType, LinkConfig> -{ - private static final List<LinkProperty<?>> LINK_PROPERTIES = new ArrayList<LinkProperty<?>>(); - - public static interface LinkProperty<S> extends ConfigProperty<LinkConfigType, LinkConfig, S> - { - } - - private abstract static class LinkReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<LinkConfigType, LinkConfig, S> implements LinkProperty<S> - { - public LinkReadWriteProperty(String name) - { - super(name); - LINK_PROPERTIES.add(this); - } - } - - private abstract static class LinkReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<LinkConfigType, LinkConfig, S> implements LinkProperty<S> - { - public LinkReadOnlyProperty(String name) - { - super(name); - LINK_PROPERTIES.add(this); - } - } - - public static final LinkReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new LinkReadOnlyProperty<VirtualHostConfig>("virtualHost") - { - public VirtualHostConfig getValue(LinkConfig object) - { - return object.getVirtualHost(); - } - }; - - public static final LinkReadOnlyProperty<String> TRANSPORT_PROPERTY = new LinkReadOnlyProperty<String>("transport") - { - public String getValue(LinkConfig object) - { - return object.getTransport(); - } - }; - - public static final LinkReadOnlyProperty<String> HOST_PROPERTY = new LinkReadOnlyProperty<String>("host") - { - public String getValue(LinkConfig object) - { - return object.getHost(); - } - }; - - public static final LinkReadOnlyProperty<Integer> PORT_PROPERTY = new LinkReadOnlyProperty<Integer>("port") - { - public Integer getValue(LinkConfig object) - { - return object.getPort(); - } - }; - - public static final LinkReadOnlyProperty<String> REMOTE_VHOST_PROPERTY = new LinkReadOnlyProperty<String>("remoteVhost") - { - public String getValue(LinkConfig object) - { - return object.getRemoteVhost(); - } - }; - - public static final LinkReadOnlyProperty<String> AUTH_MECHANISM_PROPERTY = new LinkReadOnlyProperty<String>("authMechanism") - { - public String getValue(LinkConfig object) - { - return object.getAuthMechanism(); - } - }; - - public static final LinkReadOnlyProperty<String> USERNAME_PROPERTY = new LinkReadOnlyProperty<String>("username") - { - public String getValue(LinkConfig object) - { - return object.getUsername(); - } - }; - - public static final LinkReadOnlyProperty<String> PASSWORD_PROPERTY = new LinkReadOnlyProperty<String>("password") - { - public String getValue(LinkConfig object) - { - return object.getPassword(); - } - }; - - private static final LinkConfigType INSTANCE = new LinkConfigType(); - - private LinkConfigType() - { - } - - public Collection<LinkProperty<?>> getProperties() - { - return Collections.unmodifiableList(LINK_PROPERTIES); - } - - public static LinkConfigType getInstance() - { - return INSTANCE; - } - - - -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfig.java deleted file mode 100644 index 1ef5edeb51..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfig.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * 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 org.apache.qpid.AMQException; - -import java.util.Map; - - -public interface QueueConfig extends ConfiguredObject<QueueConfigType, QueueConfig> -{ - VirtualHostConfig getVirtualHost(); - - String getName(); - - boolean isExclusive(); - - boolean isAutoDelete(); - - ExchangeConfig getAlternateExchange(); - - Map<String, Object> getArguments(); - - long getReceivedMessageCount(); - - int getMessageCount(); - - long getQueueDepth(); - - int getConsumerCount(); - - int getConsumerCountHigh(); - - int getBindingCount(); - - int getBindingCountHigh(); - - ConfigStore getConfigStore(); - - long getMessageDequeueCount(); - - long getTotalEnqueueSize(); - - long getTotalDequeueSize(); - - long getByteTxnEnqueues(); - - long getByteTxnDequeues(); - - long getMsgTxnEnqueues(); - - long getMsgTxnDequeues(); - - long getPersistentByteEnqueues(); - - long getPersistentByteDequeues(); - - long getPersistentMsgEnqueues(); - - long getPersistentMsgDequeues(); - - long getUnackedMessageCount(); - - long getUnackedMessageCountHigh(); - - void purge(long request) throws AMQException; -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfigType.java deleted file mode 100644 index f958ef5350..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfigType.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public final class QueueConfigType extends ConfigObjectType<QueueConfigType, QueueConfig> -{ - private static final List<QueueProperty<?>> QUEUE_PROPERTIES = new ArrayList<QueueProperty<?>>(); - - public static interface QueueProperty<S> extends ConfigProperty<QueueConfigType, QueueConfig, S> - { - } - - private abstract static class QueueReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<QueueConfigType, QueueConfig, S> implements QueueProperty<S> - { - public QueueReadWriteProperty(String name) - { - super(name); - QUEUE_PROPERTIES.add(this); - } - } - - private abstract static class QueueReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<QueueConfigType, QueueConfig, S> implements QueueProperty<S> - { - public QueueReadOnlyProperty(String name) - { - super(name); - QUEUE_PROPERTIES.add(this); - } - } - - public static final QueueReadOnlyProperty<VirtualHostConfig> VISTUAL_HOST_PROPERTY = new QueueReadOnlyProperty<VirtualHostConfig>("virtualHost") - { - public VirtualHostConfig getValue(QueueConfig object) - { - return object.getVirtualHost(); - } - }; - - public static final QueueReadOnlyProperty<String> NAME_PROPERTY = new QueueReadOnlyProperty<String>("name") - { - public String getValue(QueueConfig object) - { - return object.getName(); - } - }; - - public static final QueueReadOnlyProperty<Boolean> AUTODELETE_PROPERTY = new QueueReadOnlyProperty<Boolean>("autodelete") - { - public Boolean getValue(QueueConfig object) - { - return object.isAutoDelete(); - } - }; - - public static final QueueReadOnlyProperty<Boolean> EXCLUSIVE_PROPERTY = new QueueReadOnlyProperty<Boolean>("exclusive") - { - public Boolean getValue(QueueConfig object) - { - return object.isExclusive(); - } - }; - - public static final QueueReadOnlyProperty<ExchangeConfig> ALTERNATE_EXCHANGE_PROPERTY = new QueueReadOnlyProperty<ExchangeConfig>("alternateExchange") - { - public ExchangeConfig getValue(QueueConfig object) - { - return object.getAlternateExchange(); - } - }; - - public static final QueueReadOnlyProperty<Map<String,Object>> ARGUMENTS = new QueueReadOnlyProperty<Map<String,Object>>("arguments") - { - public Map<String,Object> getValue(QueueConfig object) - { - return object.getArguments(); - } - }; - - - private static final QueueConfigType INSTANCE = new QueueConfigType(); - - private QueueConfigType() - { - } - - public Collection<QueueProperty<?>> getProperties() - { - return Collections.unmodifiableList(QUEUE_PROPERTIES); - } - - public static QueueConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java index 8f03383777..06691d8659 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java @@ -24,11 +24,11 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; +import org.apache.qpid.server.configuration.plugins.AbstractConfiguration; import java.util.List; -public class QueueConfiguration extends ConfigurationPlugin +public class QueueConfiguration extends AbstractConfiguration { private String _name; private VirtualHostConfiguration _vHostConfig; @@ -39,7 +39,7 @@ public class QueueConfiguration extends ConfigurationPlugin _name = name; CompositeConfiguration mungedConf = new CompositeConfiguration(); - mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + name)); + mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + escapeTagName(name))); mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues")); setConfiguration("virtualhosts.virtualhost.queues.queue", mungedConf); @@ -193,43 +193,4 @@ public class QueueConfiguration extends ConfigurationPlugin { return getBooleanValue("deadLetterQueues", _vHostConfig.isDeadLetterQueueEnabled()); } - - public static class QueueConfig extends ConfigurationPlugin - { - @Override - public String[] getElementsProcessed() - { - return new String[]{"name"}; - } - - public String getName() - { - return getStringValue("name"); - } - - - public void validateConfiguration() throws ConfigurationException - { - if (getConfig().isEmpty()) - { - throw new ConfigurationException("Queue section cannot be empty."); - } - - if (getName() == null) - { - throw new ConfigurationException("Queue section must have a 'name' element."); - } - - } - - - @Override - public String formatToString() - { - return "Name:"+getName(); - } - - - } - } diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java index b96ddc56c6..963d019ec3 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfig.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java @@ -18,15 +18,11 @@ * under the License. * */ - package org.apache.qpid.server.configuration; -public interface VirtualHostConfig extends ConfiguredObject<VirtualHostConfigType, VirtualHostConfig> -{ - String getName(); - - BrokerConfig getBroker(); - - String getFederationTag(); +import org.apache.qpid.server.model.ConfiguredObject; +public interface RecovererProvider +{ + ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(String type); } diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java deleted file mode 100644 index f9e2d93cff..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java +++ /dev/null @@ -1,1031 +0,0 @@ -/* - * 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 java.io.File; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.TrustManagerFactory; -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.ConfigurationFactory; -import org.apache.commons.configuration.HierarchicalConfiguration; -import org.apache.commons.configuration.SystemConfiguration; -import org.apache.commons.configuration.XMLConfiguration; -import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.exchange.DefaultExchangeFactory; -import org.apache.qpid.server.protocol.AmqpProtocolVersion; -import org.apache.qpid.server.queue.AMQQueueFactory; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.signal.SignalHandlerTask; -import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.server.virtualhost.VirtualHostRegistry; - -import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; - -public class ServerConfiguration extends ConfigurationPlugin -{ - protected static final Logger _logger = Logger.getLogger(ServerConfiguration.class); - - // Default Configuration values - public static final int DEFAULT_BUFFER_SIZE = 262144; - public static final String DEFAULT_STATUS_UPDATES = "on"; - public static final String SECURITY_CONFIG_RELOADED = "SECURITY CONFIGURATION RELOADED"; - - public static final int DEFAULT_FRAME_SIZE = 65536; - public static final int DEFAULT_PORT = 5672; - public static final int DEFAULT_SSL_PORT = 5671; - public static final long DEFAULT_HOUSEKEEPING_PERIOD = 30000L; - public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999; - public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100; - public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 8080; - public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 8443; - public static final long DEFAULT_MINIMUM_ALERT_REPEAT_GAP = 30000l; - - public static final String QPID_HOME = "QPID_HOME"; - public static final String QPID_WORK = "QPID_WORK"; - public static final String LIB_DIR = "lib"; - public static final String PLUGIN_DIR = "plugins"; - public static final String CACHE_DIR = "cache"; - - private Map<String, VirtualHostConfiguration> _virtualHosts = new HashMap<String, VirtualHostConfiguration>(); - - private File _configFile; - private File _vhostsFile; - private String _qpidWork; - private String _qpidHome; - - // Map of environment variables to config items - private static final Map<String, String> envVarMap = new HashMap<String, String>(); - - // Configuration values to be read from the configuration file - //todo Move all properties to static values to ensure system testing can be performed. - public static final String MGMT_CUSTOM_REGISTRY_SOCKET = "management.custom-registry-socket"; - public static final String MGMT_JMXPORT_REGISTRYSERVER = "management.jmxport.registryServer"; - public static final String MGMT_JMXPORT_CONNECTORSERVER = "management.jmxport.connectorServer"; - public static final String SECURITY_DEFAULT_AUTH_MANAGER = "security.default-auth-manager"; - public static final String SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER = "security.port-mappings.port-mapping.auth-manager"; - public static final String SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT = "security.port-mappings.port-mapping.port"; - public static final String STATUS_UPDATES = "status-updates"; - public static final String ADVANCED_LOCALE = "advanced.locale"; - public static final String CONNECTOR_AMQP10ENABLED = "connector.amqp10enabled"; - public static final String CONNECTOR_AMQP010ENABLED = "connector.amqp010enabled"; - public static final String CONNECTOR_AMQP091ENABLED = "connector.amqp091enabled"; - public static final String CONNECTOR_AMQP09ENABLED = "connector.amqp09enabled"; - public static final String CONNECTOR_AMQP08ENABLED = "connector.amqp08enabled"; - public static final String CONNECTOR_AMQP_SUPPORTED_REPLY = "connector.amqpDefaultSupportedProtocolReply"; - public static final String CONNECTOR_INCLUDE_10 = "connector.include10"; - public static final String CONNECTOR_INCLUDE_010 = "connector.include010"; - public static final String CONNECTOR_INCLUDE_091 = "connector.include091"; - public static final String CONNECTOR_INCLUDE_09 = "connector.include09"; - public static final String CONNECTOR_INCLUDE_08 = "connector.include08"; - - { - envVarMap.put("QPID_PORT", "connector.port"); - envVarMap.put("QPID_SSLPORT", "connector.ssl.port"); - envVarMap.put("QPID_JMXPORT_REGISTRYSERVER", MGMT_JMXPORT_REGISTRYSERVER); - envVarMap.put("QPID_JMXPORT_CONNECTORSERVER", MGMT_JMXPORT_CONNECTORSERVER); - envVarMap.put("QPID_FRAMESIZE", "advanced.framesize"); - envVarMap.put("QPID_MSGAUTH", "security.msg-auth"); - envVarMap.put("QPID_AUTOREGISTER", "auto_register"); - envVarMap.put("QPID_MANAGEMENTENABLED", "management.enabled"); - envVarMap.put("QPID_HTTPMANAGEMENTENABLED", "management.http.enabled"); - envVarMap.put("QPID_HTTPMANAGEMENTPORT", "management.http.port"); - envVarMap.put("QPID_HEARTBEATDELAY", "heartbeat.delay"); - envVarMap.put("QPID_HEARTBEATTIMEOUTFACTOR", "heartbeat.timeoutFactor"); - envVarMap.put("QPID_MAXIMUMMESSAGEAGE", "maximumMessageAge"); - envVarMap.put("QPID_MAXIMUMMESSAGECOUNT", "maximumMessageCount"); - envVarMap.put("QPID_MAXIMUMQUEUEDEPTH", "maximumQueueDepth"); - envVarMap.put("QPID_MAXIMUMMESSAGESIZE", "maximumMessageSize"); - envVarMap.put("QPID_MAXIMUMCHANNELCOUNT", "maximumChannelCount"); - envVarMap.put("QPID_MINIMUMALERTREPEATGAP", "minimumAlertRepeatGap"); - envVarMap.put("QPID_QUEUECAPACITY", "capacity"); - envVarMap.put("QPID_FLOWRESUMECAPACITY", "flowResumeCapacity"); - envVarMap.put("QPID_SOCKETRECEIVEBUFFER", "connector.socketReceiveBuffer"); - envVarMap.put("QPID_SOCKETWRITEBUFFER", "connector.socketWriteBuffer"); - envVarMap.put("QPID_TCPNODELAY", "connector.tcpNoDelay"); - envVarMap.put("QPID_STATUS-UPDATES", "status-updates"); - } - - /** - * Loads the given file and sets up the HUP signal handler. - * - * This will load the file and present the root level properties but will - * not perform any virtualhost configuration. - * <p> - * To perform this {@link #initialise()} must be called. - * <p> - * This has been made a two step process to allow the Plugin Manager and - * Configuration Manager to be initialised in the Application Registry. - * <p> - * If using this ServerConfiguration via an ApplicationRegistry there is no - * need to explicitly call {@link #initialise()} as this is done via the - * {@link ApplicationRegistry#initialise()} method. - * - * @param configurationURL - * @throws org.apache.commons.configuration.ConfigurationException - */ - public ServerConfiguration(File configurationURL) throws ConfigurationException - { - this(parseConfig(configurationURL)); - _configFile = configurationURL; - - SignalHandlerTask hupReparseTask = new SignalHandlerTask() - { - public void handle() - { - try - { - reparseConfigFileSecuritySections(); - } - catch (ConfigurationException e) - { - _logger.error("Could not reload configuration file security sections", e); - } - } - }; - - if(!hupReparseTask.register("HUP")) - { - _logger.info("Unable to register Signal HUP handler to reload security configuration."); - _logger.info("Signal HUP not supported for this OS / JVM combination - " + SignalHandlerTask.getPlatformDescription()); - } - } - - /** - * Wraps the given Commons Configuration as a ServerConfiguration. - * - * Mainly used during testing and in locations where configuration is not - * desired but the interface requires configuration. - * <p> - * If the given configuration has VirtualHost configuration then - * {@link #initialise()} must be called to perform the required setup. - * <p> - * This has been made a two step process to allow the Plugin Manager and - * Configuration Manager to be initialised in the Application Registry. - * <p> - * If using this ServerConfiguration via an ApplicationRegistry there is no - * need to explicitly call {@link #initialise()} as this is done via the - * {@link ApplicationRegistry#initialise()} method. - * - * @param conf - */ - public ServerConfiguration(Configuration conf) - { - setConfig(conf); - } - - /** - * Processes this configuration and setups any VirtualHosts defined in the - * configuration. - * - * This has been separated from the constructor to allow the PluginManager - * time to be created and provide plugins to the ConfigurationManager for - * processing here. - * <p> - * Called by {@link ApplicationRegistry#initialise()}. - * <p> - * NOTE: A DEFAULT ApplicationRegistry must exist when using this method - * or a new ApplicationRegistry will be created. - * - * @throws ConfigurationException - */ - public void initialise() throws ConfigurationException - { - setConfiguration("", getConfig()); - setupVirtualHosts(getConfig()); - } - - public String[] getElementsProcessed() - { - return new String[] { "" }; - } - - @Override - public void validateConfiguration() throws ConfigurationException - { - // Support for security.jmx.access was removed when JMX access rights were incorporated into the main ACL. - // This ensure that users remove the element from their configuration file. - - if (getListValue("security.jmx.access").size() > 0) - { - String message = "Validation error : security/jmx/access is no longer a supported element within the configuration xml." - + (_configFile == null ? "" : " Configuration file : " + _configFile); - throw new ConfigurationException(message); - } - - if (getListValue("security.jmx.principal-database").size() > 0) - { - String message = "Validation error : security/jmx/principal-database is no longer a supported element within the configuration xml." - + (_configFile == null ? "" : " Configuration file : " + _configFile); - throw new ConfigurationException(message); - } - - if (getListValue("security.principal-databases.principal-database(0).class").size() > 0) - { - String message = "Validation error : security/principal-databases is no longer supported within the configuration xml." - + (_configFile == null ? "" : " Configuration file : " + _configFile); - throw new ConfigurationException(message); - } - - // QPID-3266. Tidy up housekeeping configuration option for scheduling frequency - if (contains("housekeeping.expiredMessageCheckPeriod")) - { - String message = "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod." - + (_configFile == null ? "" : " Configuration file : " + _configFile); - throw new ConfigurationException(message); - } - - String[] ports = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT); - String[] authManagers = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER); - if (ports.length != authManagers.length) - { - throw new ConfigurationException("Validation error: Each port-mapping must have exactly one port and exactly one auth-manager."); - } - - // QPID-3517: Inconsistency in capitalisation in the SSL configuration keys used within the connector and management configuration - // sections. For the moment, continue to understand both but generate a deprecated warning if the less preferred keystore is used. - for (String key : new String[] {"management.ssl.keystorePath", - "management.ssl.keystorePassword," + - "connector.ssl.keystorePath", - "connector.ssl.keystorePassword"}) - { - if (contains(key)) - { - final String deprecatedXpath = key.replaceAll("\\.", "/"); - final String preferredXpath = deprecatedXpath.replaceAll("keystore", "keyStore"); - _logger.warn("Validation warning: " + deprecatedXpath + " is deprecated and must be replaced by " + preferredXpath - + (_configFile == null ? "" : " Configuration file : " + _configFile)); - } - } - - // QPID-3739 certType was a misleading name. - if (contains("connector.ssl.certType")) - { - _logger.warn("Validation warning: connector/ssl/certType is deprecated and must be replaced by connector/ssl/keyManagerFactoryAlgorithm" - + (_configFile == null ? "" : " Configuration file : " + _configFile)); - } - } - - /* - * Modified to enforce virtualhosts configuration in external file or main file, but not - * both, as a fix for QPID-2360 and QPID-2361. - */ - @SuppressWarnings("unchecked") - protected void setupVirtualHosts(Configuration conf) throws ConfigurationException - { - List<String> vhostFiles = (List) conf.getList("virtualhosts"); - Configuration vhostConfig = conf.subset("virtualhosts"); - - // Only one configuration mechanism allowed - if (!vhostFiles.isEmpty() && !vhostConfig.subset("virtualhost").isEmpty()) - { - throw new ConfigurationException("Only one of external or embedded virtualhosts configuration allowed."); - } - - // We can only have one vhosts XML file included - if (vhostFiles.size() > 1) - { - throw new ConfigurationException("Only one external virtualhosts configuration file allowed, multiple filenames found."); - } - - // Virtualhost configuration object - Configuration vhostConfiguration = new HierarchicalConfiguration(); - - // Load from embedded configuration if possible - if (!vhostConfig.subset("virtualhost").isEmpty()) - { - vhostConfiguration = vhostConfig; - } - else - { - // Load from the external configuration if possible - for (String fileName : vhostFiles) - { - // Open the vhosts XML file and copy values from it to our config - _vhostsFile = new File(fileName); - if (!_vhostsFile.exists()) - { - throw new ConfigurationException("Virtualhosts file does not exist"); - } - vhostConfiguration = parseConfig(new File(fileName)); - - // save the default virtualhost name - String defaultVirtualHost = vhostConfiguration.getString("default"); - getConfig().setProperty("virtualhosts.default", defaultVirtualHost); - } - } - - // Now extract the virtual host names from the configuration object - List hosts = vhostConfiguration.getList("virtualhost.name"); - for (int j = 0; j < hosts.size(); j++) - { - String name = (String) hosts.get(j); - - // Add the virtual hosts to the server configuration - VirtualHostConfiguration virtualhost = new VirtualHostConfiguration(name, vhostConfiguration.subset("virtualhost." + name)); - _virtualHosts.put(virtualhost.getName(), virtualhost); - } - } - - private static void substituteEnvironmentVariables(Configuration conf) - { - for (Entry<String, String> var : envVarMap.entrySet()) - { - String val = System.getenv(var.getKey()); - if (val != null) - { - conf.setProperty(var.getValue(), val); - } - } - } - - private static Configuration parseConfig(File file) throws ConfigurationException - { - ConfigurationFactory factory = new ConfigurationFactory(); - factory.setConfigurationFileName(file.getAbsolutePath()); - Configuration conf = factory.getConfiguration(); - - Iterator<?> keys = conf.getKeys(); - if (!keys.hasNext()) - { - keys = null; - conf = flatConfig(file); - } - - substituteEnvironmentVariables(conf); - - return conf; - } - - /** - * Check the configuration file to see if status updates are enabled. - * - * @return true if status updates are enabled - */ - public boolean getStatusUpdatesEnabled() - { - // Retrieve the setting from configuration but default to on. - String value = getStringValue(STATUS_UPDATES, DEFAULT_STATUS_UPDATES); - - return value.equalsIgnoreCase("on"); - } - - /** - * The currently defined {@see Locale} for this broker - * - * @return the configuration defined locale - */ - public Locale getLocale() - { - String localeString = getStringValue(ADVANCED_LOCALE); - // Expecting locale of format langauge_country_variant - - // If the configuration does not have a defined locale use the JVM default - if (localeString == null) - { - return Locale.getDefault(); - } - - String[] parts = localeString.split("_"); - - Locale locale; - switch (parts.length) - { - case 1: - locale = new Locale(localeString); - break; - case 2: - locale = new Locale(parts[0], parts[1]); - break; - default: - StringBuilder variant = new StringBuilder(parts[2]); - // If we have a variant such as the Java doc suggests for Spanish - // Traditional_WIN we may end up with more than 3 parts on a - // split with '_'. So we should recombine the variant. - if (parts.length > 3) - { - for (int index = 3; index < parts.length; index++) - { - variant.append('_').append(parts[index]); - } - } - - locale = new Locale(parts[0], parts[1], variant.toString()); - } - - return locale; - } - - // Our configuration class needs to make the interpolate method - // public so it can be called below from the config method. - public static class MyConfiguration extends CompositeConfiguration - { - public String interpolate(String obj) - { - return super.interpolate(obj); - } - } - - public final static Configuration flatConfig(File file) throws ConfigurationException - { - // We have to override the interpolate methods so that - // interpolation takes place across the entirety of the - // composite configuration. Without doing this each - // configuration object only interpolates variables defined - // inside itself. - final MyConfiguration conf = new MyConfiguration(); - conf.addConfiguration(new SystemConfiguration() - { - protected String interpolate(String o) - { - return conf.interpolate(o); - } - }); - conf.addConfiguration(new XMLConfiguration(file) - { - protected String interpolate(String o) - { - return conf.interpolate(o); - } - }); - return conf; - } - - public String getConfigurationURL() - { - return _configFile == null ? "" : _configFile.getAbsolutePath(); - } - - public void reparseConfigFileSecuritySections() throws ConfigurationException - { - if (_configFile != null) - { - Configuration newConfig = parseConfig(_configFile); - setConfiguration("", newConfig); - ApplicationRegistry.getInstance().getSecurityManager().configureHostPlugins(this); - - // Reload virtualhosts from correct location - Configuration newVhosts; - if (_vhostsFile == null) - { - newVhosts = newConfig.subset("virtualhosts"); - } - else - { - newVhosts = parseConfig(_vhostsFile); - } - - VirtualHostRegistry vhostRegistry = ApplicationRegistry.getInstance().getVirtualHostRegistry(); - for (String hostName : _virtualHosts.keySet()) - { - VirtualHost vhost = vhostRegistry.getVirtualHost(hostName); - Configuration vhostConfig = newVhosts.subset("virtualhost." + hostName); - vhost.getConfiguration().setConfiguration("virtualhosts.virtualhost", vhostConfig); - vhost.getSecurityManager().configureGlobalPlugins(this); - vhost.getSecurityManager().configureHostPlugins(vhost.getConfiguration()); - } - - _logger.warn(SECURITY_CONFIG_RELOADED); - } - } - - public String getQpidWork() - { - if ( _qpidWork == null ) - { - return System.getProperty(QPID_WORK, System.getProperty("java.io.tmpdir")); - } - else - { - return _qpidWork; - } - } - - public String getQpidHome() - { - if ( _qpidHome == null ) - { - return System.getProperty(QPID_HOME); - } - else - { - return _qpidHome; - } - } - - public void setJMXPortRegistryServer(int registryServerPort) - { - getConfig().setProperty(MGMT_JMXPORT_REGISTRYSERVER, registryServerPort); - } - - public int getJMXPortRegistryServer() - { - return getIntValue(MGMT_JMXPORT_REGISTRYSERVER, DEFAULT_JMXPORT_REGISTRYSERVER); - } - - public void setJMXPortConnectorServer(int connectorServerPort) - { - getConfig().setProperty(MGMT_JMXPORT_CONNECTORSERVER, connectorServerPort); - } - - public int getJMXConnectorServerPort() - { - return getIntValue(MGMT_JMXPORT_CONNECTORSERVER, getJMXPortRegistryServer() + JMXPORT_CONNECTORSERVER_OFFSET); - } - - public boolean getUseCustomRMISocketFactory() - { - return getBooleanValue(MGMT_CUSTOM_REGISTRY_SOCKET, true); - } - - public void setUseCustomRMISocketFactory(boolean bool) - { - getConfig().setProperty(MGMT_CUSTOM_REGISTRY_SOCKET, bool); - } - - public boolean getPlatformMbeanserver() - { - return getBooleanValue("management.platform-mbeanserver", true); - } - - public boolean getHTTPManagementEnabled() - { - return getBooleanValue("management.http.enabled", true); - } - - public int getHTTPManagementPort() - { - return getIntValue("management.http.port", DEFAULT_HTTP_MANAGEMENT_PORT); - } - - public boolean getHTTPSManagementEnabled() - { - return getBooleanValue("management.https.enabled", false); - } - - public int getHTTPSManagementPort() - { - return getIntValue("management.https.port", DEFAULT_HTTPS_MANAGEMENT_PORT); - } - - public String[] getVirtualHosts() - { - return _virtualHosts.keySet().toArray(new String[_virtualHosts.size()]); - } - - public String getPluginDirectory() - { - return getStringValue("plugin-directory"); - } - - public String getCacheDirectory() - { - return getStringValue("cache-directory"); - } - - public VirtualHostConfiguration getVirtualHostConfig(String name) - { - return _virtualHosts.get(name); - } - - public void setVirtualHostConfig(VirtualHostConfiguration config) - { - _virtualHosts.put(config.getName(), config); - } - - public int getFrameSize() - { - return getIntValue("advanced.framesize", DEFAULT_FRAME_SIZE); - } - - public boolean getSynchedClocks() - { - return getBooleanValue("advanced.synced-clocks"); - } - - public boolean getMsgAuth() - { - return getBooleanValue("security.msg-auth"); - } - - public String getDefaultAuthenticationManager() - { - return getStringValue(SECURITY_DEFAULT_AUTH_MANAGER); - } - - public Map<Integer, String> getPortAuthenticationMappings() - { - String[] ports = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT); - String[] authManagers = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER); - - Map<Integer,String> portMappings = new HashMap<Integer, String>(); - for(int i = 0; i < ports.length; i++) - { - portMappings.put(Integer.valueOf(ports[i]), authManagers[i]); - } - - return portMappings; - } - - - public String getManagementKeyStorePath() - { - final String fallback = getStringValue("management.ssl.keystorePath"); - return getStringValue("management.ssl.keyStorePath", fallback); - } - - public boolean getManagementSSLEnabled() - { - return getBooleanValue("management.ssl.enabled", false); - } - - public String getManagementKeyStorePassword() - { - final String fallback = getStringValue("management.ssl.keystorePassword"); - return getStringValue("management.ssl.keyStorePassword", fallback); - } - - public boolean getQueueAutoRegister() - { - return getBooleanValue("queue.auto_register", true); - } - - public boolean getJMXManagementEnabled() - { - return getBooleanValue("management.enabled", true); - } - - public int getHeartBeatDelay() - { - return getIntValue("heartbeat.delay", 5); - } - - public double getHeartBeatTimeout() - { - return getDoubleValue("heartbeat.timeoutFactor", 2.0); - } - - public long getMaximumMessageAge() - { - return getLongValue("maximumMessageAge"); - } - - public long getMaximumMessageCount() - { - return getLongValue("maximumMessageCount"); - } - - public long getMaximumQueueDepth() - { - return getLongValue("maximumQueueDepth"); - } - - public long getMaximumMessageSize() - { - return getLongValue("maximumMessageSize"); - } - - public long getMinimumAlertRepeatGap() - { - return getLongValue("minimumAlertRepeatGap", DEFAULT_MINIMUM_ALERT_REPEAT_GAP); - } - - public long getCapacity() - { - return getLongValue("capacity"); - } - - public long getFlowResumeCapacity() - { - return getLongValue("flowResumeCapacity", getCapacity()); - } - - public int getConnectorProcessors() - { - return getIntValue("connector.processors", 4); - } - - public List getPorts() - { - return getListValue("connector.port", Collections.<Integer>singletonList(DEFAULT_PORT)); - } - - public List getPortExclude10() - { - return getListValue("connector.non10port"); - } - - public List getPortExclude010() - { - return getListValue("connector.non010port"); - } - - public List getPortExclude091() - { - return getListValue("connector.non091port"); - } - - public List getPortExclude09() - { - return getListValue("connector.non09port"); - } - - public List getPortExclude08() - { - return getListValue("connector.non08port"); - } - - public List getPortInclude08() - { - return getListValue(CONNECTOR_INCLUDE_08); - } - - public List getPortInclude09() - { - return getListValue(CONNECTOR_INCLUDE_09); - } - - public List getPortInclude091() - { - return getListValue(CONNECTOR_INCLUDE_091); - } - - public List getPortInclude010() - { - return getListValue(CONNECTOR_INCLUDE_010); - } - - public List getPortInclude10() - { - return getListValue(CONNECTOR_INCLUDE_10); - } - - public String getBind() - { - return getStringValue("connector.bind", WILDCARD_ADDRESS); - } - - public int getReceiveBufferSize() - { - return getIntValue("connector.socketReceiveBuffer", DEFAULT_BUFFER_SIZE); - } - - public int getWriteBufferSize() - { - return getIntValue("connector.socketWriteBuffer", DEFAULT_BUFFER_SIZE); - } - - public boolean getTcpNoDelay() - { - return getBooleanValue("connector.tcpNoDelay", true); - } - - public boolean getEnableSSL() - { - return getBooleanValue("connector.ssl.enabled"); - } - - public boolean getSSLOnly() - { - return getBooleanValue("connector.ssl.sslOnly"); - } - - public List getSSLPorts() - { - return getListValue("connector.ssl.port", Collections.<Integer>singletonList(DEFAULT_SSL_PORT)); - } - - public String getConnectorKeyStorePath() - { - final String fallback = getStringValue("connector.ssl.keystorePath"); // pre-0.13 broker supported this name. - return getStringValue("connector.ssl.keyStorePath", fallback); - } - - public String getConnectorKeyStorePassword() - { - final String fallback = getStringValue("connector.ssl.keystorePassword"); // pre-0.13 brokers supported this name. - return getStringValue("connector.ssl.keyStorePassword", fallback); - } - - public String getConnectorKeyStoreType() - { - return getStringValue("connector.ssl.keyStoreType", "JKS"); - } - - public String getConnectorKeyManagerFactoryAlgorithm() - { - final String systemFallback = KeyManagerFactory.getDefaultAlgorithm(); - // deprecated, pre-0.17 brokers supported this name. - final String fallback = getStringValue("connector.ssl.certType", systemFallback); - return getStringValue("connector.ssl.keyManagerFactoryAlgorithm", fallback); - } - - public String getConnectorTrustStorePath() - { - return getStringValue("connector.ssl.trustStorePath", null); - } - - public String getConnectorTrustStorePassword() - { - return getStringValue("connector.ssl.trustStorePassword", null); - } - - public String getConnectorTrustStoreType() - { - return getStringValue("connector.ssl.trustStoreType", "JKS"); - } - - public String getConnectorTrustManagerFactoryAlgorithm() - { - return getStringValue("connector.ssl.trustManagerFactoryAlgorithm", TrustManagerFactory.getDefaultAlgorithm()); - } - - public String getCertAlias() - { - return getStringValue("connector.ssl.certAlias", null); - } - - public boolean needClientAuth() - { - return getConfig().getBoolean("connector.ssl.needClientAuth", false); - } - - public boolean wantClientAuth() - { - return getConfig().getBoolean("connector.ssl.wantClientAuth", false); - } - - public String getDefaultVirtualHost() - { - return getStringValue("virtualhosts.default"); - } - - public void setDefaultVirtualHost(String vhost) - { - getConfig().setProperty("virtualhosts.default", vhost); - } - - public void setHousekeepingCheckPeriod(long value) - { - getConfig().setProperty("housekeeping.checkPeriod", value); - } - - public long getHousekeepingCheckPeriod() - { - return getLongValue("housekeeping.checkPeriod", DEFAULT_HOUSEKEEPING_PERIOD); - } - - public long getStatisticsSamplePeriod() - { - return getConfig().getLong("statistics.sample.period", 5000L); - } - - public boolean isStatisticsGenerationBrokerEnabled() - { - return getConfig().getBoolean("statistics.generation.broker", false); - } - - public boolean isStatisticsGenerationVirtualhostsEnabled() - { - return getConfig().getBoolean("statistics.generation.virtualhosts", false); - } - - public boolean isStatisticsGenerationConnectionsEnabled() - { - return getConfig().getBoolean("statistics.generation.connections", false); - } - - public long getStatisticsReportingPeriod() - { - return getConfig().getLong("statistics.reporting.period", 0L); - } - - public boolean isStatisticsReportResetEnabled() - { - return getConfig().getBoolean("statistics.reporting.reset", false); - } - - public int getMaxChannelCount() - { - return getIntValue("maximumChannelCount", 256); - } - - /** - * List of Broker features that have been disabled within configuration. Disabled - * features won't be advertised to the clients on connection. - * - * @return list of disabled features, or empty list if no features are disabled. - */ - public List<String> getDisabledFeatures() - { - final List<String> disabledFeatures = getListValue("disabledFeatures", Collections.emptyList()); - return disabledFeatures; - } - - public boolean getManagementRightsInferAllAccess() - { - return getBooleanValue("management.managementRightsInferAllAccess", true); - } - - public int getMaxDeliveryCount() - { - return getConfig().getInt("maximumDeliveryCount", 0); - } - - /** - * Check if dead letter queue delivery is enabled, defaults to disabled if not set. - */ - public boolean isDeadLetterQueueEnabled() - { - return getConfig().getBoolean("deadLetterQueues", false); - } - - /** - * String to affix to end of queue name when generating an alternate exchange for DLQ purposes. - */ - public String getDeadLetterExchangeSuffix() - { - return getConfig().getString("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX); - } - - /** - * String to affix to end of queue name when generating a queue for DLQ purposes. - */ - public String getDeadLetterQueueSuffix() - { - return getConfig().getString("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX); - } - - public boolean isAmqp10enabled() - { - return getConfig().getBoolean(CONNECTOR_AMQP10ENABLED, true); - } - - public boolean isAmqp010enabled() - { - return getConfig().getBoolean(CONNECTOR_AMQP010ENABLED, true); - } - - public boolean isAmqp091enabled() - { - return getConfig().getBoolean(CONNECTOR_AMQP091ENABLED, true); - } - - public boolean isAmqp09enabled() - { - return getConfig().getBoolean(CONNECTOR_AMQP09ENABLED, true); - } - - public boolean isAmqp08enabled() - { - return getConfig().getBoolean(CONNECTOR_AMQP08ENABLED, true); - } - - /** - * Returns the configured default reply to an unsupported AMQP protocol initiation, or null if there is none - */ - public AmqpProtocolVersion getDefaultSupportedProtocolReply() - { - String reply = getConfig().getString(CONNECTOR_AMQP_SUPPORTED_REPLY, null); - - return reply == null ? null : AmqpProtocolVersion.valueOf(reply); - } - - public void setQpidWork(String path) - { - _qpidWork = path; - } - - public void setQpidHome(String path) - { - _qpidHome = path; - } - -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java deleted file mode 100644 index 51dcc38c47..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 java.net.InetSocketAddress; -import org.apache.qpid.transport.NetworkTransportConfiguration; - -public class ServerNetworkTransportConfiguration implements NetworkTransportConfiguration -{ - private final ServerConfiguration _serverConfig; - private final String _transport; - private InetSocketAddress _address; - - public ServerNetworkTransportConfiguration(final ServerConfiguration serverConfig, - final InetSocketAddress address, - final String transport) - { - _serverConfig = serverConfig; - _address = address; - _transport = transport; - } - - public Boolean getTcpNoDelay() - { - return _serverConfig.getTcpNoDelay(); - } - - public Integer getSendBufferSize() - { - return _serverConfig.getWriteBufferSize(); - } - - public Integer getReceiveBufferSize() - { - return _serverConfig.getReceiveBufferSize(); - } - - public Integer getPort() - { - return _address.getPort(); - } - - public String getHost() - { - return _address.getHostName(); - } - - public String getTransport() - { - return _transport; - } - - public Integer getConnectorProcessors() - { - return _serverConfig.getConnectorProcessors(); - } - - public InetSocketAddress getAddress() - { - return _address; - } - - public boolean needClientAuth() - { - return _serverConfig.needClientAuth(); - } - - @Override - public boolean wantClientAuth() - { - return _serverConfig.wantClientAuth(); - } -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfig.java deleted file mode 100644 index 8fef642eff..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfig.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * 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 org.apache.qpid.AMQException; - -public interface SessionConfig extends ConfiguredObject<SessionConfigType, SessionConfig> -{ - VirtualHostConfig getVirtualHost(); - - String getSessionName(); - - int getChannel(); - - ConnectionConfig getConnectionConfig(); - - boolean isAttached(); - - long getDetachedLifespan(); - - Long getExpiryTime(); - - Long getMaxClientRate(); - - Long getTxnStarts(); - - Long getTxnCommits(); - - Long getTxnRejects(); - - Long getTxnCount(); - - boolean isTransactional(); - - void mgmtClose() throws AMQException; -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfigType.java deleted file mode 100644 index 1685cfab60..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfigType.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public final class SessionConfigType extends ConfigObjectType<SessionConfigType, SessionConfig> -{ - private static final List<SessionProperty<?>> SESSION_PROPERTIES = new ArrayList<SessionProperty<?>>(); - - public static interface SessionProperty<S> extends ConfigProperty<SessionConfigType, SessionConfig, S> - { - } - - private abstract static class SessionReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<SessionConfigType, SessionConfig, S> implements SessionProperty<S> - { - public SessionReadWriteProperty(String name) - { - super(name); - SESSION_PROPERTIES.add(this); - } - } - - private abstract static class SessionReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<SessionConfigType, SessionConfig, S> implements SessionProperty<S> - { - public SessionReadOnlyProperty(String name) - { - super(name); - SESSION_PROPERTIES.add(this); - } - } - - public static final SessionReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new SessionReadOnlyProperty<VirtualHostConfig>("virtualHost") - { - public VirtualHostConfig getValue(SessionConfig object) - { - return object.getVirtualHost(); - } - }; - - public static final SessionReadOnlyProperty<String> NAME_PROPERTY = new SessionReadOnlyProperty<String>("name") - { - public String getValue(SessionConfig object) - { - return object.getSessionName(); - } - }; - - public static final SessionReadOnlyProperty<Integer> CHANNEL_ID_PROPERTY = new SessionReadOnlyProperty<Integer>("channelId") - { - public Integer getValue(SessionConfig object) - { - return object.getChannel(); - } - }; - - public static final SessionReadOnlyProperty<ConnectionConfig> CONNECTION_PROPERTY = new SessionReadOnlyProperty<ConnectionConfig>("connection") - { - public ConnectionConfig getValue(SessionConfig object) - { - return object.getConnectionConfig(); - } - }; - - public static final SessionReadOnlyProperty<Boolean> ATTACHED_PROPERTY = new SessionReadOnlyProperty<Boolean>("attached") - { - public Boolean getValue(SessionConfig object) - { - return object.isAttached(); - } - }; - - public static final SessionReadOnlyProperty<Long> DETACHED_LIFESPAN_PROPERTY = new SessionReadOnlyProperty<Long>("detachedLifespan") - { - public Long getValue(SessionConfig object) - { - return object.getDetachedLifespan(); - } - }; - - public static final SessionReadOnlyProperty<Long> EXPIRE_TIME_PROPERTY = new SessionReadOnlyProperty<Long>("expireTime") - { - public Long getValue(SessionConfig object) - { - return object.getExpiryTime(); - } - }; - - public static final SessionReadOnlyProperty<Long> MAX_CLIENT_RATE_PROPERTY = new SessionReadOnlyProperty<Long>("maxClientRate") - { - public Long getValue(SessionConfig object) - { - return object.getMaxClientRate(); - } - }; - - private static final SessionConfigType INSTANCE = new SessionConfigType(); - - private SessionConfigType() - { - } - - public Collection<SessionProperty<?>> getProperties() - { - return Collections.unmodifiableList(SESSION_PROPERTIES); - } - - public static SessionConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfig.java deleted file mode 100644 index b101d70553..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * 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 java.util.Map; - - -public interface SubscriptionConfig extends ConfiguredObject<SubscriptionConfigType, SubscriptionConfig> -{ - - SessionConfig getSessionConfig(); - - QueueConfig getQueue(); - - String getName(); - - Map<String, Object> getArguments(); - - String getCreditMode(); - - boolean isBrowsing(); - - boolean isExclusive(); - - boolean isExplicitAcknowledge(); - - Long getDelivered(); -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfigType.java deleted file mode 100644 index 7b7848dd87..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfigType.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public final class SubscriptionConfigType extends ConfigObjectType<SubscriptionConfigType, SubscriptionConfig> -{ - private static final List<SubscriptionProperty<?>> SUBSCRIPTION_PROPERTIES = new ArrayList<SubscriptionProperty<?>>(); - - public static interface SubscriptionProperty<S> extends ConfigProperty<SubscriptionConfigType, SubscriptionConfig, S> - { - } - - private abstract static class SubscriptionReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<SubscriptionConfigType, SubscriptionConfig, S> implements SubscriptionProperty<S> - { - public SubscriptionReadWriteProperty(String name) - { - super(name); - SUBSCRIPTION_PROPERTIES.add(this); - } - } - - private abstract static class SubscriptionReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<SubscriptionConfigType, SubscriptionConfig, S> implements SubscriptionProperty<S> - { - public SubscriptionReadOnlyProperty(String name) - { - super(name); - SUBSCRIPTION_PROPERTIES.add(this); - } - } - - public static final SubscriptionReadOnlyProperty<SessionConfig> SESSION_PROPERTY = new SubscriptionReadOnlyProperty<SessionConfig>("session") - { - public SessionConfig getValue(SubscriptionConfig object) - { - return object.getSessionConfig(); - } - }; - - public static final SubscriptionReadOnlyProperty<QueueConfig> QUEUE_PROPERTY = new SubscriptionReadOnlyProperty<QueueConfig>("queue") - { - public QueueConfig getValue(SubscriptionConfig object) - { - return object.getQueue(); - } - }; - - public static final SubscriptionReadOnlyProperty<String> NAME_PROPERTY = new SubscriptionReadOnlyProperty<String>("name") - { - public String getValue(SubscriptionConfig object) - { - return object.getName(); - } - }; - - public static final SubscriptionReadOnlyProperty<Map<String,Object>> ARGUMENTS = new SubscriptionReadOnlyProperty<Map<String,Object>>("arguments") - { - public Map<String,Object> getValue(SubscriptionConfig object) - { - return object.getArguments(); - } - }; - - public static final SubscriptionReadOnlyProperty<String> CREDIT_MODE_PROPERTY = new SubscriptionReadOnlyProperty<String>("creditMode") - { - public String getValue(SubscriptionConfig object) - { - return object.getCreditMode(); - } - }; - - public static final SubscriptionReadOnlyProperty<Boolean> BROWSING_PROPERTY = new SubscriptionReadOnlyProperty<Boolean>("browsing") - { - public Boolean getValue(SubscriptionConfig object) - { - return object.isBrowsing(); - } - }; - - public static final SubscriptionReadOnlyProperty<Boolean> EXCLUSIVE_PROPERTY = new SubscriptionReadOnlyProperty<Boolean>("exclusive") - { - public Boolean getValue(SubscriptionConfig object) - { - return object.isExclusive(); - } - }; - - public static final SubscriptionReadOnlyProperty<Boolean> EXPLICIT_ACK_PROPERTY = new SubscriptionReadOnlyProperty<Boolean>("explicitAck") - { - public Boolean getValue(SubscriptionConfig object) - { - return object.isExplicitAcknowledge(); - } - }; - - private static final SubscriptionConfigType INSTANCE = new SubscriptionConfigType(); - - private SubscriptionConfigType() - { - } - - public Collection<SubscriptionProperty<?>> getProperties() - { - return Collections.unmodifiableList(SUBSCRIPTION_PROPERTIES); - } - - - public static SubscriptionConfigType getInstance() - { - return INSTANCE; - } - - - -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigImpl.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigImpl.java deleted file mode 100644 index 80c2e8b2f1..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigImpl.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * 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 java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -public class SystemConfigImpl implements SystemConfig -{ - private static final String OS_NAME = System.getProperty("os.name"); - private static final String OS_ARCH = System.getProperty("os.arch"); - private static final String OS_VERSION = System.getProperty("os.version"); - - private final UUID _qmfId; - private String _name; - - private final String _host; - - private final Map<UUID, BrokerConfig> _brokers = new ConcurrentHashMap<UUID, BrokerConfig>(); - - private final long _createTime = System.currentTimeMillis(); - private final ConfigStore _store; - - public SystemConfigImpl(ConfigStore store) - { - this(store.createId(), store); - } - - public SystemConfigImpl(UUID qmfId, ConfigStore store) - { - _qmfId = qmfId; - _store = store; - String host; - try - { - InetAddress addr = InetAddress.getLocalHost(); - host = addr.getHostName(); - } - catch (UnknownHostException e) - { - host="localhost"; - } - _host = host; - } - - public String getName() - { - return _name; - } - - public String getOperatingSystemName() - { - return OS_NAME; - } - - public String getNodeName() - { - return _host; - } - - public String getOSRelease() - { - return OS_VERSION; - } - - public String getOSVersion() - { - return ""; - } - - public String getOSArchitecture() - { - return OS_ARCH; - } - - @Override - public UUID getQMFId() - { - return _qmfId; - } - - public SystemConfigType getConfigType() - { - return SystemConfigType.getInstance(); - } - - public ConfiguredObject getParent() - { - return null; - } - - public boolean isDurable() - { - return false; - } - - public void addBroker(final BrokerConfig broker) - { - broker.setSystem(this); - _store.addConfiguredObject(broker); - _brokers.put(broker.getQMFId(), broker); - } - - public void removeBroker(final BrokerConfig broker) - { - _brokers.remove(broker.getQMFId()); - _store.removeConfiguredObject(broker); - } - - public long getCreateTime() - { - return _createTime; - } - -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigType.java deleted file mode 100644 index 4a383cce7a..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigType.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -public final class SystemConfigType extends ConfigObjectType<SystemConfigType, SystemConfig> -{ - private static final List<SystemProperty<?>> SYSTEM_PROPERTIES = new ArrayList<SystemProperty<?>>(); - - public static interface SystemProperty<S> extends ConfigProperty<SystemConfigType, SystemConfig, S> - { - } - - private abstract static class SystemReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<SystemConfigType, SystemConfig, S> implements SystemProperty<S> - { - public SystemReadWriteProperty(String name) - { - super(name); - SYSTEM_PROPERTIES.add(this); - } - } - - private abstract static class SystemReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<SystemConfigType, SystemConfig, S> implements SystemProperty<S> - { - public SystemReadOnlyProperty(String name) - { - super(name); - SYSTEM_PROPERTIES.add(this); - } - } - - public static final SystemReadOnlyProperty<String> NAME_PROPERTY = new SystemReadOnlyProperty<String>("name") - { - public String getValue(SystemConfig object) - { - return object.getName(); - } - }; - - public static final SystemReadOnlyProperty<UUID> ID_PROPERTY = new SystemReadOnlyProperty<UUID>("id") - { - public UUID getValue(SystemConfig object) - { - return object.getQMFId(); - } - }; - - public static final SystemReadOnlyProperty<String> OS_NAME_PROPERTY = new SystemReadOnlyProperty<String>("osName") - { - public String getValue(SystemConfig object) - { - return object.getOperatingSystemName(); - } - }; - - public static final SystemReadOnlyProperty<String> NODE_NAME_PROPERTY = new SystemReadOnlyProperty<String>("nodeName") - { - public String getValue(SystemConfig object) - { - return object.getNodeName(); - } - }; - - public static final SystemReadOnlyProperty<String> RELEASE_PROPERTY = new SystemReadOnlyProperty<String>("release") - { - public String getValue(SystemConfig object) - { - return object.getOSRelease(); - } - }; - - public static final SystemReadOnlyProperty<String> VERSION_PROPERTY = new SystemReadOnlyProperty<String>("version") - { - public String getValue(SystemConfig object) - { - return object.getOSVersion(); - } - }; - - public static final SystemReadOnlyProperty<String> MACHINE_PROPERTY = new SystemReadOnlyProperty<String>("machine") - { - public String getValue(SystemConfig object) - { - return object.getOSArchitecture(); - } - }; - - private static final SystemConfigType INSTANCE = new SystemConfigType(); - - private SystemConfigType() - { - } - - public Collection<SystemProperty<?>> getProperties() - { - return Collections.unmodifiableList(SYSTEM_PROPERTIES); - } - - - - public static SystemConfigType getInstance() - { - return INSTANCE; - } - - - -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfig.java deleted file mode 100644 index aaa1766489..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfig.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * 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 org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; - -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; - -public class TopicConfig extends ConfigurationPlugin -{ - public TopicConfig() - { - setConfig(new PropertiesConfiguration()); - } - - @Override - public String[] getElementsProcessed() - { - return new String[]{"name", "subscriptionName"}; - } - - public String getName() - { - // If we don't have a specific topic then this config is for all topics. - return getStringValue("name", "#"); - } - - public String getSubscriptionName() - { - return getStringValue("subscriptionName"); - } - - public void validateConfiguration() throws ConfigurationException - { - if (getConfig().isEmpty()) - { - throw new ConfigurationException("Topic section cannot be empty."); - } - - if (getStringValue("name") == null && getSubscriptionName() == null) - { - throw new ConfigurationException("Topic section must have a 'name' or 'subscriptionName' element."); - } - - } - - - @Override - public String formatToString() - { - String response = "Topic:"+getName(); - if (getSubscriptionName() != null) - { - response += ", SubscriptionName:"+getSubscriptionName(); - } - - return response; - } -}
\ No newline at end of file diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfiguration.java deleted file mode 100644 index feafd3de1d..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfiguration.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * - * 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 org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.binding.Binding; -import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; -import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; -import org.apache.qpid.server.exchange.TopicExchange; -import org.apache.qpid.server.queue.AMQQueue; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public class TopicConfiguration extends ConfigurationPlugin implements ExchangeConfigurationPlugin -{ - public static final ConfigurationPluginFactory FACTORY = new TopicConfigurationFactory(); - - private static final String VIRTUALHOSTS_VIRTUALHOST_TOPICS = "virtualhosts.virtualhost.topics"; - - public static class TopicConfigurationFactory implements ConfigurationPluginFactory - { - - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException - { - TopicConfiguration topicsConfig = new TopicConfiguration(); - topicsConfig.setConfiguration(path, config); - return topicsConfig; - } - - public List<String> getParentPaths() - { - return Arrays.asList(VIRTUALHOSTS_VIRTUALHOST_TOPICS); - } - } - - private Map<String, TopicConfig> _topics = new HashMap<String, TopicConfig>(); - private Map<String, Map<String, TopicConfig>> _subscriptions = new HashMap<String, Map<String, TopicConfig>>(); - - public String[] getElementsProcessed() - { - return new String[]{"topic"}; - } - - @Override - public void validateConfiguration() throws ConfigurationException - { - if (getConfig().isEmpty()) - { - throw new ConfigurationException("Topics section cannot be empty."); - } - - int topics = getConfig().getList("topic.name").size() + - getConfig().getList("topic.subscriptionName").size(); - - for (int index = 0; index < topics; index++) - { - Configuration topicSubset = getConfig().subset("topic(" + index + ")"); - - // This will occur when we have a subscriptionName that is bound to a - // topic. - if (topicSubset.isEmpty()) - { - break; - } - - TopicConfig topic = new TopicConfig(); - - topic.setConfiguration(VIRTUALHOSTS_VIRTUALHOST_TOPICS + ".topic", topicSubset ); - - String name = getConfig().getString("topic(" + index + ").name"); - String subscriptionName = getConfig().getString("topic(" + index + ").subscriptionName"); - - // Record config if subscriptionName is there - if (subscriptionName != null) - { - processSubscription(subscriptionName, topic); - } - else - { - // Otherwise record config as topic if we have the name - if (name != null) - { - processTopic(name, topic); - } - } - } - } - - /** - * @param name - * @param topic - * - * @throws org.apache.commons.configuration.ConfigurationException - * - */ - private void processTopic(String name, TopicConfig topic) throws ConfigurationException - { - if (_topics.containsKey(name)) - { - throw new ConfigurationException("Topics section cannot contain two entries for the same topic."); - } - else - { - _topics.put(name, topic); - } - } - - - private void processSubscription(String name, TopicConfig topic) throws ConfigurationException - { - Map<String,TopicConfig> topics; - if (_subscriptions.containsKey(name)) - { - topics = _subscriptions.get(name); - - if (topics.containsKey(topic.getName())) - { - throw new ConfigurationException("Subcription cannot contain two entries for the same topic."); - } - } - else - { - topics = new HashMap<String,TopicConfig>(); - } - - topics.put(topic.getName(),topic); - _subscriptions.put(name, topics); - - } - - @Override - public String formatToString() - { - return "Topics:" + _topics + ", Subscriptions:" + _subscriptions; - } - - /** - * This processes the given queue and apply configuration in the following - * order: - * - * Global Topic Values -> Topic Values -> Subscription Values - * - * @param queue - * - * @return - */ - public ConfigurationPlugin getConfiguration(AMQQueue queue) - { - //Create config with global topic configuration - TopicConfig config = new TopicConfig(); - - // Add global topic configuration - config.addConfiguration(this); - - // Process Topic Bindings as these are more generic than subscriptions - List<TopicConfig> boundToTopics = new LinkedList<TopicConfig>(); - - //Merge the configuration in the order that they are bound - for (Binding binding : queue.getBindings()) - { - if (binding.getExchange().getType().equals(TopicExchange.TYPE)) - { - // Identify topic for the binding key - TopicConfig topicConfig = getTopicConfigForRoutingKey(binding.getBindingKey()); - if (topicConfig != null) - { - boundToTopics.add(topicConfig); - } - } - } - - // If the Queue is bound to a number of topics then only use the global - // topic configuration. - // todo - What does it mean in terms of configuration to be bound to a - // number of topics? Do we try and merge? - // YES - right thing to do would be to merge from generic to specific. - // Means we need to be able to get an ordered list of topics for this - // binding. - if (boundToTopics.size() == 1) - { - config.addConfiguration(boundToTopics.get(0)); - } - - // If we have a subscription then attempt to look it up. - String subscriptionName = queue.getName(); - - // Apply subscription configurations - if (_subscriptions.containsKey(subscriptionName)) - { - - //Get all the Configuration that this subscription is bound to. - Map<String, TopicConfig> topics = _subscriptions.get(subscriptionName); - - TopicConfig subscriptionSpecificConfig = null; - - // See if we have a TopicConfig in topics for a topic we are bound to. - for (Binding binding : queue.getBindings()) - { - if (binding.getExchange().getType().equals(TopicExchange.TYPE)) - { - //todo - What does it mean to have multiple matches? - // Take the first match we get - if (subscriptionSpecificConfig == null) - { - // lookup the binding to see if we have a match in the subscription configs - subscriptionSpecificConfig = topics.get(binding.getBindingKey()); - } - } - } - - //todo we don't account for wild cards here. only explicit matching and all subscriptions - if (subscriptionSpecificConfig == null) - { - // lookup the binding to see if we have a match in the subscription configs - subscriptionSpecificConfig = topics.get("#"); - } - - // Apply subscription specific config. - if (subscriptionSpecificConfig != null) - { - config.addConfiguration(subscriptionSpecificConfig); - } - } - return config; - } - - /** - * This method should perform the same heuristics as the TopicExchange - * to attempt to identify a piece of configuration for the give routingKey. - * - * i.e. If we have 'stocks.*' defined in the config - * and we bind 'stocks.appl' then we should return the 'stocks.*' - * configuration. - * - * @param routingkey the key to lookup - * - * @return the TopicConfig if found. - */ - private TopicConfig getTopicConfigForRoutingKey(String routingkey) - { - //todo actually perform TopicExchange style lookup not just straight - // lookup as we are just now. - return _topics.get(routingkey); - } - -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfigType.java deleted file mode 100644 index 16e08e3934..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfigType.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * 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 java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class VirtualHostConfigType extends ConfigObjectType<VirtualHostConfigType, VirtualHostConfig> -{ - private static final List<VirtualHostProperty<?>> VIRTUAL_HOST_PROPERTIES = new ArrayList<VirtualHostProperty<?>>(); - private static final VirtualHostConfigType INSTANCE = new VirtualHostConfigType(); -public static interface VirtualHostProperty<S> extends ConfigProperty<VirtualHostConfigType, VirtualHostConfig, S> - { - } - - private abstract static class VirtualHostReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<VirtualHostConfigType, VirtualHostConfig, S> implements VirtualHostProperty<S> - { - public VirtualHostReadWriteProperty(String name) - { - super(name); - VIRTUAL_HOST_PROPERTIES.add(this); - } - } - - private abstract static class VirtualHostReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<VirtualHostConfigType, VirtualHostConfig, S> implements VirtualHostProperty<S> - { - public VirtualHostReadOnlyProperty(String name) - { - super(name); - VIRTUAL_HOST_PROPERTIES.add(this); - } - } - - - public static final VirtualHostReadOnlyProperty<String> NAME_PROPERTY = new VirtualHostReadOnlyProperty<String>("name") - { - public String getValue(VirtualHostConfig object) - { - return object.getName(); - } - }; - - - public static final VirtualHostReadOnlyProperty<BrokerConfig> BROKER_PROPERTY = new VirtualHostReadOnlyProperty<BrokerConfig>("broker") - { - public BrokerConfig getValue(VirtualHostConfig object) - { - return object.getBroker(); - } - }; - - public static final VirtualHostReadOnlyProperty<String> FEDERATION_TAG_PROPERTY = new VirtualHostReadOnlyProperty<String>("federationTag") - { - public String getValue(VirtualHostConfig object) - { - return object.getFederationTag(); - } - }; - - - - public Collection<? extends ConfigProperty<VirtualHostConfigType, VirtualHostConfig, ?>> getProperties() - { - return Collections.unmodifiableList(VIRTUAL_HOST_PROPERTIES); - } - - - private VirtualHostConfigType() - { - } - - public static VirtualHostConfigType getInstance() - { - return INSTANCE; - } - - -} 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(); } } diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java new file mode 100644 index 0000000000..c0cff2c109 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java @@ -0,0 +1,111 @@ +/* + * + * 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 java.io.File; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.configuration.CompositeConfiguration; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.ConfigurationFactory; +import org.apache.commons.configuration.SystemConfiguration; +import org.apache.commons.configuration.XMLConfiguration; + +public class XmlConfigurationUtilities +{ + + // Our configuration class needs to make the interpolate method + // public so it can be called below from the config method. + public static class MyConfiguration extends CompositeConfiguration + { + public String interpolate(String obj) + { + return super.interpolate(obj); + } + } + + public static Configuration parseConfig(File file, Map<String, String> envVarMap) throws ConfigurationException + { + ConfigurationFactory factory = new ConfigurationFactory(); + factory.setConfigurationFileName(file.getAbsolutePath()); + Configuration conf = factory.getConfiguration(); + + Iterator<?> keys = conf.getKeys(); + if (!keys.hasNext()) + { + keys = null; + conf = flatConfig(file); + } + + XmlConfigurationUtilities.substituteEnvironmentVariables(conf, envVarMap); + return conf; + } + + public final static Configuration flatConfig(File file) throws ConfigurationException + { + // We have to override the interpolate methods so that + // interpolation takes place across the entirety of the + // composite configuration. Without doing this each + // configuration object only interpolates variables defined + // inside itself. + final MyConfiguration conf = new MyConfiguration(); + conf.addConfiguration(new SystemConfiguration() + { + protected String interpolate(String o) + { + return conf.interpolate(o); + } + }); + conf.addConfiguration(new XMLConfiguration(file) + { + protected String interpolate(String o) + { + return conf.interpolate(o); + } + }); + return conf; + } + + static void substituteEnvironmentVariables(Configuration conf, Map<String, String> envVarMap) + { + if (envVarMap == null || envVarMap.isEmpty()) + { + return; + } + for (Entry<String, String> var : envVarMap.entrySet()) + { + String val = System.getenv(var.getKey()); + if (val != null) + { + conf.setProperty(var.getValue(), val); + } + } + } + + + public static String escapeTagName(String name) + { + return name.replaceAll("\\.", "\\.\\."); + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java index d08e3bc806..3c17faef75 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java @@ -23,25 +23,16 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConversionException; import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.ConfigurationManager; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.registry.IApplicationRegistry; - import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; -public abstract class ConfigurationPlugin +public abstract class AbstractConfiguration { - protected static final Logger _logger = Logger.getLogger(ConfigurationPlugin.class); - - private Map<String, ConfigurationPlugin> - _pluginConfiguration = new HashMap<String, ConfigurationPlugin>(); + protected static final Logger _logger = Logger.getLogger(AbstractConfiguration.class); private Configuration _config; @@ -69,11 +60,6 @@ public abstract class ConfigurationPlugin return _config; } - public <C extends ConfigurationPlugin> C getConfiguration(String plugin) - { - return (C) _pluginConfiguration.get(plugin); - } - /** * Sets the configuration for this plugin * @@ -118,7 +104,7 @@ public abstract class ConfigurationPlugin // With an XMLConfiguration the key will be [@property] // but with a CompositeConfiguration it will be @property]. // Hide this issue from our users so when/if we change the - // configuration they don't have to. + // configuration they don't have to. int bracketIndex = tag.indexOf("["); if (bracketIndex != -1) { @@ -140,62 +126,9 @@ public abstract class ConfigurationPlugin } } - offerRemainingConfigurationToOtherPlugins(path, configuration, elements); - validateConfiguration(); } - private void offerRemainingConfigurationToOtherPlugins(String path, - Configuration configuration, Set<String> elements) throws ConfigurationException - { - final IApplicationRegistry appRegistry = safeGetApplicationRegistryInstance(); - - if (appRegistry == null) - { - // We see this happen during shutdown due to asynchronous reconfig using IO threads. - // Need to remove the responsibility for offering configuration to other class. - _logger.info("Cannot offer remaining config to other plugins, can't find app registry"); - return; - } - - final ConfigurationManager configurationManager = appRegistry.getConfigurationManager(); - // Process the elements in the configuration - for (String element : elements) - { - Configuration handled = element.length() == 0 ? configuration : configuration.subset(element); - - String configurationElement = element; - if (path.length() > 0) - { - configurationElement = path + "." + configurationElement; - } - - List<ConfigurationPlugin> handlers = configurationManager.getConfigurationPlugins(configurationElement, handled); - - if(_logger.isDebugEnabled()) - { - _logger.debug("For '" + element + "' found handlers (" + handlers.size() + "):" + handlers); - } - - for (ConfigurationPlugin plugin : handlers) - { - _pluginConfiguration.put(plugin.getClass().getName(), plugin); - } - } - } - - private IApplicationRegistry safeGetApplicationRegistryInstance() - { - try - { - return ApplicationRegistry.getInstance(); - } - catch (IllegalStateException ise) - { - return null; - } - } - /** Helper method to print out list of keys in a {@link Configuration}. */ public static final void showKeys(Configuration config) { @@ -382,101 +315,9 @@ public abstract class ConfigurationPlugin } } - /** - * Given another configuration merge the configuration into our own config - * - * The new values being merged in will take precedence over existing values. - * - * In the simplistic case this means something like: - * - * So if we have configuration set - * name = 'fooo' - * - * And the new configuration contains a name then that will be reset. - * name = 'new' - * - * However this plugin will simply contain other plugins so the merge will - * be called until we end up at a base plugin that understand how to merge - * items. i.e Alerting values. Where the provided configuration will take - * precedence. - * - * @param configuration the config to merge in to our own. - */ - public void addConfiguration(ConfigurationPlugin configuration) - { - // If given configuration is null then there is nothing to process. - if (configuration == null) - { - return; - } - - // Merge all the sub configuration items - for (Map.Entry<String, ConfigurationPlugin> newPlugins : configuration._pluginConfiguration.entrySet()) - { - String key = newPlugins.getKey(); - ConfigurationPlugin config = newPlugins.getValue(); - - if (_pluginConfiguration.containsKey(key)) - { - //Merge the configuration if we already have this type of config - _pluginConfiguration.get(key).mergeConfiguration(config); - } - else - { - //otherwise just add it to our config. - _pluginConfiguration.put(key, config); - } - } - - //Merge the configuration itself - String key = configuration.getClass().getName(); - if (_pluginConfiguration.containsKey(key)) - { - //Merge the configuration if we already have this type of config - _pluginConfiguration.get(key).mergeConfiguration(configuration); - } - else - { - //If we are adding a configuration of our own type then merge - if (configuration.getClass() == this.getClass()) - { - mergeConfiguration(configuration); - } - else - { - // just store this in case someone else needs it. - _pluginConfiguration.put(key, configuration); - } - - } - - } - - protected void mergeConfiguration(ConfigurationPlugin configuration) - { - _config = configuration.getConfig(); - } - - public String toString() - { - StringBuilder sb = new StringBuilder(); - - sb.append("\n").append(getClass().getSimpleName()); - sb.append("=[ (").append(formatToString()).append(")"); - - for(Map.Entry<String,ConfigurationPlugin> item : _pluginConfiguration.entrySet()) - { - sb.append("\n").append(item.getValue()); - } - - sb.append("]\n"); - - return sb.toString(); - } - - public String formatToString() + public static String escapeTagName(String name) { - return super.toString(); + return name.replaceAll("\\.", "\\.\\."); } protected void setConfig(Configuration config) diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java deleted file mode 100644 index fa41f3ef06..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * 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.plugins; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import java.util.List; - -public interface ConfigurationPluginFactory -{ - /** - * The Parent paths of the configuration that this plugin supports. - * - * For example, {@code queue} elements have a parent path of {@code virtualhosts.virtualhost}. - */ - public List<String> getParentPaths(); - - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException; -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionConfiguration.java deleted file mode 100644 index a90b1d514f..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionConfiguration.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * 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.plugins; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - -public class SlowConsumerDetectionConfiguration extends ConfigurationPlugin -{ - public static class SlowConsumerDetectionConfigurationFactory implements ConfigurationPluginFactory - { - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException - { - SlowConsumerDetectionConfiguration slowConsumerConfig = new SlowConsumerDetectionConfiguration(); - slowConsumerConfig.setConfiguration(path, config); - return slowConsumerConfig; - } - - public List<String> getParentPaths() - { - return Arrays.asList("virtualhosts.virtualhost.slow-consumer-detection"); - } - } - - //Set Default time unit to seconds - private TimeUnit _timeUnit = TimeUnit.SECONDS; - - public String[] getElementsProcessed() - { - return new String[]{"delay", - "timeunit"}; - } - - public long getDelay() - { - return getLongValue("delay", 10); - } - - public TimeUnit getTimeUnit() - { - return _timeUnit; - } - - @Override - public void validateConfiguration() throws ConfigurationException - { - validatePositiveLong("delay"); - - String timeUnit = getStringValue("timeunit"); - - if (timeUnit != null) - { - try - { - _timeUnit = TimeUnit.valueOf(timeUnit.toUpperCase()); - } - catch (IllegalArgumentException iae) - { - throw new ConfigurationException("Unable to configure Slow Consumer Detection invalid TimeUnit:" + timeUnit); - } - } - - } -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionPolicyConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionPolicyConfiguration.java deleted file mode 100644 index a9026c6164..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionPolicyConfiguration.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * 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.plugins; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import java.util.Arrays; -import java.util.List; - -public class SlowConsumerDetectionPolicyConfiguration extends ConfigurationPlugin -{ - public static class SlowConsumerDetectionPolicyConfigurationFactory implements ConfigurationPluginFactory - { - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException - { - SlowConsumerDetectionPolicyConfiguration slowConsumerConfig = new SlowConsumerDetectionPolicyConfiguration(); - slowConsumerConfig.setConfiguration(path, config); - return slowConsumerConfig; - } - - public List<String> getParentPaths() - { - return Arrays.asList( - "virtualhosts.virtualhost.queues.slow-consumer-detection.policy", - "virtualhosts.virtualhost.queues.queue.slow-consumer-detection.policy", - "virtualhosts.virtualhost.topics.slow-consumer-detection.policy", - "virtualhosts.virtualhost.topics.topic.slow-consumer-detection.policy"); - } - } - - public String[] getElementsProcessed() - { - return new String[]{"name"}; - } - - public String getPolicyName() - { - return getStringValue("name"); - } - - @Override - public void validateConfiguration() throws ConfigurationException - { - if (getPolicyName() == null) - { - throw new ConfigurationException("No Slow consumer policy defined."); - } - } - - @Override - public String formatToString() - { - return "Policy:"+getPolicyName(); - } -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionQueueConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionQueueConfiguration.java deleted file mode 100644 index cb3bb5a77f..0000000000 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionQueueConfiguration.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * - * 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.plugins; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.plugins.PluginManager; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPlugin; -import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPluginFactory; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -public class SlowConsumerDetectionQueueConfiguration extends ConfigurationPlugin -{ - private SlowConsumerPolicyPlugin _policyPlugin; - - public static class SlowConsumerDetectionQueueConfigurationFactory implements ConfigurationPluginFactory - { - public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException - { - SlowConsumerDetectionQueueConfiguration slowConsumerConfig = new SlowConsumerDetectionQueueConfiguration(); - slowConsumerConfig.setConfiguration(path, config); - return slowConsumerConfig; - } - - public List<String> getParentPaths() - { - return Arrays.asList( - "virtualhosts.virtualhost.queues.slow-consumer-detection", - "virtualhosts.virtualhost.queues.queue.slow-consumer-detection", - "virtualhosts.virtualhost.topics.slow-consumer-detection", - "virtualhosts.virtualhost.topics.topic.slow-consumer-detection"); - } - } - - public String[] getElementsProcessed() - { - return new String[]{"messageAge", - "depth", - "messageCount"}; - } - - public long getMessageAge() - { - return getLongValue("messageAge"); - } - - public long getDepth() - { - return getLongValue("depth"); - } - - public long getMessageCount() - { - return getLongValue("messageCount"); - } - - public SlowConsumerPolicyPlugin getPolicy() - { - return _policyPlugin; - } - - @Override - public void validateConfiguration() throws ConfigurationException - { - PluginManager pluginManager; - try - { - pluginManager = ApplicationRegistry.getInstance().getPluginManager(); - } - catch (IllegalStateException ise) - { - // We see this happen during shutdown due to asynchronous reconfig performed IO threads - // running at the same time as the shutdown handler. - _policyPlugin = null; - return; - } - - if (!containsPositiveLong("messageAge") && - !containsPositiveLong("depth") && - !containsPositiveLong("messageCount")) - { - throw new ConfigurationException("At least one configuration property" + - "('messageAge','depth' or 'messageCount') must be specified."); - } - - SlowConsumerDetectionPolicyConfiguration policyConfig = getConfiguration(SlowConsumerDetectionPolicyConfiguration.class.getName()); - Map<String, SlowConsumerPolicyPluginFactory> factories = pluginManager.getSlowConsumerPlugins(); - - if (policyConfig == null) - { - throw new ConfigurationException("No Slow Consumer Policy specified. Known Policies:" + factories.keySet()); - } - - if (_logger.isDebugEnabled()) - { - Iterator<?> keys = policyConfig.getConfig().getKeys(); - - while (keys.hasNext()) - { - String key = (String) keys.next(); - - _logger.debug("Policy Keys:" + key); - } - - } - - SlowConsumerPolicyPluginFactory<SlowConsumerPolicyPlugin> pluginFactory = factories.get(policyConfig.getPolicyName().toLowerCase()); - - if (pluginFactory == null) - { - throw new ConfigurationException("Unknown Slow Consumer Policy specified:" + policyConfig.getPolicyName() + " Known Policies:" + factories.keySet()); - } - - _policyPlugin = pluginFactory.newInstance(policyConfig); - - // Debug the creation of this Config - _logger.debug(this); - } - - public String formatToString() - { - StringBuilder sb = new StringBuilder(); - if (getMessageAge() > 0) - { - sb.append("Age:").append(getMessageAge()).append(":"); - } - if (getDepth() > 0) - { - sb.append("Depth:").append(getDepth()).append(":"); - } - if (getMessageCount() > 0) - { - sb.append("Count:").append(getMessageCount()).append(":"); - } - - sb.append("Policy[").append(getPolicy()).append("]"); - return sb.toString(); - } -} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java new file mode 100644 index 0000000000..9b06a2b499 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java @@ -0,0 +1,55 @@ +/* + * + * 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.startup; + +import java.util.Map; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; + +public class AuthenticationProviderRecoverer implements ConfiguredObjectRecoverer<AuthenticationProvider> +{ + private final AuthenticationProviderFactory _authenticationProviderFactory; + + public AuthenticationProviderRecoverer(AuthenticationProviderFactory authenticationProviderFactory) + { + _authenticationProviderFactory = authenticationProviderFactory; + } + + @Override + public AuthenticationProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) + { + Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); + Map<String, Object> attributes = configurationEntry.getAttributes(); + AuthenticationProvider authenticationProvider = _authenticationProviderFactory.create( + configurationEntry.getId(), + broker, + attributes, null); + + return authenticationProvider; + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java new file mode 100644 index 0000000000..4bfa0ca7a3 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java @@ -0,0 +1,139 @@ +package org.apache.qpid.server.configuration.startup; + +import java.util.Collection; +import java.util.Map; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.logging.LogRecorder; +import org.apache.qpid.server.logging.RootMessageLogger; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; +import org.apache.qpid.server.model.adapter.BrokerAdapter; +import org.apache.qpid.server.model.adapter.PortFactory; +import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.security.group.GroupPrincipalAccessor; +import org.apache.qpid.server.stats.StatisticsGatherer; +import org.apache.qpid.server.virtualhost.VirtualHostRegistry; + +public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker> +{ + private final StatisticsGatherer _statisticsGatherer; + private final VirtualHostRegistry _virtualHostRegistry; + private final LogRecorder _logRecorder; + private final RootMessageLogger _rootMessageLogger; + private final AuthenticationProviderFactory _authenticationProviderFactory; + private final PortFactory _portFactory; + private final TaskExecutor _taskExecutor; + + public BrokerRecoverer(AuthenticationProviderFactory authenticationProviderFactory, PortFactory portFactory, + StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder, + RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor) + { + _portFactory = portFactory; + _authenticationProviderFactory = authenticationProviderFactory; + _statisticsGatherer = statisticsGatherer; + _virtualHostRegistry = virtualHostRegistry; + _logRecorder = logRecorder; + _rootMessageLogger = rootMessageLogger; + _taskExecutor = taskExecutor; + } + + @Override + public Broker create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) + { + StoreConfigurationChangeListener storeChangeListener = new StoreConfigurationChangeListener(entry.getStore()); + BrokerAdapter broker = new BrokerAdapter(entry.getId(), entry.getAttributes(), _statisticsGatherer, _virtualHostRegistry, + _logRecorder, _rootMessageLogger, _authenticationProviderFactory, _portFactory, _taskExecutor); + broker.addChangeListener(storeChangeListener); + Map<String, Collection<ConfigurationEntry>> childEntries = entry.getChildren(); + for (String type : childEntries.keySet()) + { + ConfiguredObjectRecoverer<?> recoverer = recovererProvider.getRecoverer(type); + if (recoverer == null) + { + throw new IllegalConfigurationException("Cannot recover entry for the type '" + type + "' from broker"); + } + Collection<ConfigurationEntry> entries = childEntries.get(type); + for (ConfigurationEntry childEntry : entries) + { + ConfiguredObject object = recoverer.create(recovererProvider, childEntry, broker); + if (object == null) + { + throw new IllegalConfigurationException("Cannot create configured object for the entry " + childEntry); + } + broker.recoverChild(object); + object.addChangeListener(storeChangeListener); + } + } + wireUpConfiguredObjects(broker, entry.getAttributes()); + + return broker; + } + + private void wireUpConfiguredObjects(BrokerAdapter broker, Map<String, Object> brokerAttributes) + { + AuthenticationProvider defaultAuthenticationProvider = null; + Collection<AuthenticationProvider> authenticationProviders = broker.getAuthenticationProviders(); + int numberOfAuthenticationProviders = authenticationProviders.size(); + if (numberOfAuthenticationProviders == 0) + { + throw new IllegalConfigurationException("No authentication provider was configured"); + } + else if (numberOfAuthenticationProviders == 1) + { + defaultAuthenticationProvider = authenticationProviders.iterator().next(); + } + else + { + String name = (String) brokerAttributes.get(Broker.DEFAULT_AUTHENTICATION_PROVIDER); + if (name == null) + { + throw new IllegalConfigurationException("Multiple authentication providers defined, but no default was configured."); + } + + defaultAuthenticationProvider = getAuthenticationProviderByName(broker, name); + } + broker.setDefaultAuthenticationProvider(defaultAuthenticationProvider); + + GroupPrincipalAccessor groupPrincipalAccessor = new GroupPrincipalAccessor(broker.getGroupProviders()); + for (AuthenticationProvider authenticationProvider : authenticationProviders) + { + authenticationProvider.setGroupAccessor(groupPrincipalAccessor); + } + + Collection<Port> ports = broker.getPorts(); + for (Port port : ports) + { + String authenticationProviderName = (String) port.getAttribute(Port.AUTHENTICATION_MANAGER); + AuthenticationProvider provider = null; + if (authenticationProviderName != null) + { + provider = getAuthenticationProviderByName(broker, authenticationProviderName); + } + else + { + provider = defaultAuthenticationProvider; + } + port.setAuthenticationProvider(provider); + } + } + + private AuthenticationProvider getAuthenticationProviderByName(BrokerAdapter broker, String authenticationProviderName) + { + AuthenticationProvider provider = broker.getAuthenticationProviderByName(authenticationProviderName); + if (provider == null) + { + throw new IllegalConfigurationException("Cannot find the authentication provider with name: " + + authenticationProviderName); + } + return provider; + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java new file mode 100644 index 0000000000..15cb229d8a --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java @@ -0,0 +1,112 @@ +/* + * + * 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.startup; + +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.logging.LogRecorder; +import org.apache.qpid.server.logging.RootMessageLogger; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.GroupProvider; +import org.apache.qpid.server.model.KeyStore; +import org.apache.qpid.server.model.Plugin; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.TrustStore; +import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory; +import org.apache.qpid.server.model.adapter.PortFactory; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; +import org.apache.qpid.server.plugin.GroupManagerFactory; +import org.apache.qpid.server.plugin.PluginFactory; +import org.apache.qpid.server.plugin.QpidServiceLoader; +import org.apache.qpid.server.stats.StatisticsGatherer; +import org.apache.qpid.server.virtualhost.VirtualHostRegistry; + +public class DefaultRecovererProvider implements RecovererProvider +{ + + private final StatisticsGatherer _brokerStatisticsGatherer; + private final VirtualHostRegistry _virtualHostRegistry; + private final LogRecorder _logRecorder; + private final RootMessageLogger _rootMessageLogger; + private final AuthenticationProviderFactory _authenticationProviderFactory; + private final PortFactory _portFactory; + private final QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader; + private final QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader; + private final TaskExecutor _taskExecutor; + + public DefaultRecovererProvider(StatisticsGatherer brokerStatisticsGatherer, VirtualHostRegistry virtualHostRegistry, + LogRecorder logRecorder, RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor) + { + _authenticationProviderFactory = new AuthenticationProviderFactory(new QpidServiceLoader<AuthenticationManagerFactory>()); + _portFactory = new PortFactory(); + _brokerStatisticsGatherer = brokerStatisticsGatherer; + _virtualHostRegistry = virtualHostRegistry; + _logRecorder = logRecorder; + _rootMessageLogger = rootMessageLogger; + _groupManagerServiceLoader = new QpidServiceLoader<GroupManagerFactory>(); + _pluginFactoryServiceLoader = new QpidServiceLoader<PluginFactory>(); + _taskExecutor = taskExecutor; + } + + @Override + public ConfiguredObjectRecoverer<?> getRecoverer(String type) + { + if (Broker.class.getSimpleName().equals(type)) + { + return new BrokerRecoverer(_authenticationProviderFactory, _portFactory, _brokerStatisticsGatherer, _virtualHostRegistry, + _logRecorder, _rootMessageLogger, _taskExecutor); + } + else if(VirtualHost.class.getSimpleName().equals(type)) + { + return new VirtualHostRecoverer(_brokerStatisticsGatherer); + } + else if(AuthenticationProvider.class.getSimpleName().equals(type)) + { + return new AuthenticationProviderRecoverer(_authenticationProviderFactory); + } + else if(Port.class.getSimpleName().equals(type)) + { + return new PortRecoverer(_portFactory); + } + else if(GroupProvider.class.getSimpleName().equals(type)) + { + return new GroupProviderRecoverer(_groupManagerServiceLoader); + } + else if(KeyStore.class.getSimpleName().equals(type)) + { + return new KeyStoreRecoverer(); + } + else if(TrustStore.class.getSimpleName().equals(type)) + { + return new TrustStoreRecoverer(); + } + else if(Plugin.class.getSimpleName().equals(type)) + { + return new PluginRecoverer(_pluginFactoryServiceLoader); + } + + return null; + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java new file mode 100644 index 0000000000..275a0c736c --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java @@ -0,0 +1,74 @@ +/* + * + * 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.startup; + +import java.util.Map; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.GroupProvider; +import org.apache.qpid.server.model.adapter.GroupProviderAdapter; +import org.apache.qpid.server.plugin.GroupManagerFactory; +import org.apache.qpid.server.plugin.QpidServiceLoader; +import org.apache.qpid.server.security.group.GroupManager; + +public class GroupProviderRecoverer implements ConfiguredObjectRecoverer<GroupProvider> +{ + private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader; + + public GroupProviderRecoverer(QpidServiceLoader<GroupManagerFactory> groupManagerServiceLoader) + { + super(); + _groupManagerServiceLoader = groupManagerServiceLoader; + } + + @Override + public GroupProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) + { + Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); + Map<String, Object> attributes = configurationEntry.getAttributes(); + GroupManager groupManager = createGroupManager(attributes); + if (groupManager == null) + { + throw new IllegalConfigurationException("Cannot create GroupManager from attributes : " + attributes); + } + GroupProviderAdapter groupProviderAdapter = new GroupProviderAdapter(configurationEntry.getId(), groupManager, broker); + return groupProviderAdapter; + } + + private GroupManager createGroupManager(Map<String, Object> attributes) + { + for(GroupManagerFactory factory : _groupManagerServiceLoader.instancesOf(GroupManagerFactory.class)) + { + GroupManager groupManager = factory.createInstance(attributes); + if (groupManager != null) + { + return groupManager; + } + } + return null; + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java new file mode 100644 index 0000000000..8efedd37b5 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java @@ -0,0 +1,40 @@ +/* + * + * 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.startup; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.KeyStore; +import org.apache.qpid.server.model.adapter.KeyStoreAdapter; + +public class KeyStoreRecoverer implements ConfiguredObjectRecoverer<KeyStore> +{ + @Override + public KeyStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) + { + Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); + return new KeyStoreAdapter(entry.getId(), broker, entry.getAttributes()); + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java new file mode 100644 index 0000000000..ddc4482953 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java @@ -0,0 +1,66 @@ +/* + * + * 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.startup; + +import java.util.Map; +import java.util.UUID; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.plugin.PluginFactory; +import org.apache.qpid.server.plugin.QpidServiceLoader; + +public class PluginRecoverer implements ConfiguredObjectRecoverer<ConfiguredObject> +{ + private QpidServiceLoader<PluginFactory> _serviceLoader; + + public PluginRecoverer(QpidServiceLoader<PluginFactory> serviceLoader) + { + _serviceLoader = serviceLoader; + } + + @Override + public ConfiguredObject create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) + { + Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); + Map<String, Object> attributes = configurationEntry.getAttributes(); + Iterable<PluginFactory> factories = _serviceLoader.instancesOf(PluginFactory.class); + for (PluginFactory pluginFactory : factories) + { + UUID configurationId = configurationEntry.getId(); + ConfiguredObject pluginObject = pluginFactory.createInstance(configurationId, attributes, broker); + if (pluginObject != null) + { + UUID pluginId = pluginObject.getId(); + if (!configurationId.equals(pluginId)) + { + throw new IllegalStateException("Plugin object id '" + pluginId + "' does not equal expected id " + configurationId); + } + return pluginObject; + } + } + throw new IllegalConfigurationException("Cannot create a plugin object for " + attributes + " with factories " + factories); + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java new file mode 100644 index 0000000000..147e835a8d --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java @@ -0,0 +1,52 @@ +/* + * + * 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.startup; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.adapter.BrokerAdapter; +import org.apache.qpid.server.model.adapter.PortFactory; + +public class PortRecoverer implements ConfiguredObjectRecoverer<Port> +{ + /** + * delegates to a {@link PortFactory} so that the logic can be shared by + * {@link BrokerAdapter} + */ + private final PortFactory _portFactory; + + public PortRecoverer(PortFactory portFactory) + { + _portFactory = portFactory; + } + + @Override + public Port create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents) + { + Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); + return _portFactory.createPort(configurationEntry.getId(), broker, configurationEntry.getAttributes()); + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java new file mode 100644 index 0000000000..b60c9c289f --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java @@ -0,0 +1,44 @@ +/* + * + * 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.startup; + +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; + +public class RecovererHelper +{ + public static Broker verifyOnlyBrokerIsParent(ConfiguredObject... parents) + { + if (parents == null || parents.length == 0) + { + throw new IllegalArgumentException("Broker parent is not passed!"); + } + if (parents.length != 1) + { + throw new IllegalArgumentException("Only one parent is expected!"); + } + if (!(parents[0] instanceof Broker)) + { + throw new IllegalArgumentException("Parent is not a broker"); + } + return (Broker)parents[0]; + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java new file mode 100644 index 0000000000..7e9428a4d6 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java @@ -0,0 +1,40 @@ +/* + * + * 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.startup; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.TrustStore; +import org.apache.qpid.server.model.adapter.TrustStoreAdapter; + +public class TrustStoreRecoverer implements ConfiguredObjectRecoverer<TrustStore> +{ + @Override + public TrustStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) + { + Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); + return new TrustStoreAdapter(entry.getId(), broker, entry.getAttributes()); + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java new file mode 100644 index 0000000000..4f863adfb5 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java @@ -0,0 +1,51 @@ +/* + * + * 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.startup; + + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.RecovererProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.server.model.adapter.VirtualHostAdapter; +import org.apache.qpid.server.stats.StatisticsGatherer; + +public class VirtualHostRecoverer implements ConfiguredObjectRecoverer<VirtualHost> +{ + private StatisticsGatherer _brokerStatisticsGatherer; + + public VirtualHostRecoverer(StatisticsGatherer brokerStatisticsGatherer) + { + super(); + _brokerStatisticsGatherer = brokerStatisticsGatherer; + } + + @Override + public VirtualHost create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents) + { + Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents); + + return new VirtualHostAdapter(entry.getId(), entry.getAttributes(), broker, _brokerStatisticsGatherer, broker.getTaskExecutor()); + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java new file mode 100644 index 0000000000..e11b63001a --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java @@ -0,0 +1,711 @@ +package org.apache.qpid.server.configuration.store; + +import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_NAME; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.UUID; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfigurationEntryStore; +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.model.UUIDGenerator; +import org.apache.qpid.util.FileUtils; +import org.apache.qpid.util.Strings; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.JsonParser; +import org.codehaus.jackson.JsonProcessingException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.node.ArrayNode; + +public class JsonConfigurationEntryStore implements ConfigurationEntryStore +{ + public static final String STORE_TYPE = "json"; + public static final String IN_MEMORY = ":memory:"; + + private static final String DEFAULT_BROKER_NAME = "Broker"; + private static final String ID = "id"; + private static final String TYPE = "@type"; + + private ObjectMapper _objectMapper; + private Map<UUID, ConfigurationEntry> _entries; + private File _storeFile; + private UUID _rootId; + private Map<String, Class<? extends ConfiguredObject>> _relationshipClasses; + + public JsonConfigurationEntryStore() + { + _objectMapper = new ObjectMapper(); + _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); + _objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + _entries = new HashMap<UUID, ConfigurationEntry>(); + _relationshipClasses = buildRelationshipClassMap(); + } + + @Override + public void open(String storeLocation) + { + if (_rootId != null) + { + throw new IllegalConfigurationException("The store has been opened alread"); + } + if (!IN_MEMORY.equals(storeLocation)) + { + _storeFile = new File(storeLocation); + } + createOrLoadStore(); + } + + @Override + public void open(String storeLocation, String initialStoreLocation) + { + if (_rootId != null) + { + throw new IllegalConfigurationException("The store has been opened already"); + } + if (!IN_MEMORY.equals(storeLocation)) + { + _storeFile = new File(storeLocation); + if ((!_storeFile.exists() || _storeFile.length() == 0) && initialStoreLocation != null) + { + copyInitialStoreFile(initialStoreLocation); + } + createOrLoadStore(); + } + else + { + if (initialStoreLocation == null) + { + createRootEntryIfNotExists(); + } + else + { + load(toURL(initialStoreLocation)); + } + } + } + + @Override + public void open(String storeLocation, ConfigurationEntryStore initialStore) + { + if (_rootId != null) + { + throw new IllegalConfigurationException("The store has been opened already"); + } + boolean copyStore = false; + if (IN_MEMORY.equals(storeLocation)) + { + copyStore = initialStore != null; + } + else + { + _storeFile = new File(storeLocation); + if ((!_storeFile.exists() || _storeFile.length() == 0) && initialStore != null) + { + createStoreFileIfNotExist(_storeFile); + copyStore = true; + } + } + if (copyStore) + { + ConfigurationEntry rootEntry = initialStore.getRootEntry(); + _rootId = rootEntry.getId(); + copyEntry(rootEntry.getId(), initialStore); + saveAsTree(); + } + else + { + createOrLoadStore(); + } + } + + @Override + public synchronized UUID[] remove(UUID... entryIds) + { + List<UUID> removedIds = new ArrayList<UUID>(); + boolean anyRemoved = false; + for (UUID uuid : entryIds) + { + if (_rootId.equals(uuid)) + { + throw new IllegalConfigurationException("Cannot remove root entry"); + } + } + for (UUID uuid : entryIds) + { + if (removeInternal(uuid)) + { + anyRemoved = true; + + // remove references to the entry from parent entries + for (ConfigurationEntry entry : _entries.values()) + { + if (entry.hasChild(uuid)) + { + Set<UUID> children = new HashSet<UUID>(entry.getChildrenIds()); + children.remove(uuid); + ConfigurationEntry referal = new ConfigurationEntry(entry.getId(), entry.getType(), + entry.getAttributes(), children, this); + _entries.put(entry.getId(), referal); + } + } + removedIds.add(uuid); + } + } + if (anyRemoved) + { + saveAsTree(); + } + return removedIds.toArray(new UUID[removedIds.size()]); + } + + @Override + public synchronized void save(ConfigurationEntry... entries) + { + boolean anySaved = false; + for (ConfigurationEntry entry : entries) + { + ConfigurationEntry oldEntry = _entries.put(entry.getId(), entry); + if (!entry.equals(oldEntry)) + { + anySaved = true; + } + } + if (anySaved) + { + saveAsTree(); + } + } + + @Override + public ConfigurationEntry getRootEntry() + { + return getEntry(_rootId); + } + + @Override + public synchronized ConfigurationEntry getEntry(UUID id) + { + return _entries.get(id); + } + + @Override + public void copyTo(String copyLocation) + { + if (_rootId == null) + { + throw new IllegalConfigurationException("The store has not been opened"); + } + File file = new File(copyLocation); + if (!file.exists()) + { + createStoreFileIfNotExist(file); + } + saveAsTree(_rootId, _entries, _objectMapper, file); + } + + @Override + public String toString() + { + return "JsonConfigurationEntryStore [_storeFile=" + _storeFile + ", _rootId=" + _rootId + "]"; + } + + private Map<String, Class<? extends ConfiguredObject>> buildRelationshipClassMap() + { + Map<String, Class<? extends ConfiguredObject>> relationships = new HashMap<String, Class<? extends ConfiguredObject>>(); + + Collection<Class<? extends ConfiguredObject>> children = Model.getInstance().getChildTypes(Broker.class); + for (Class<? extends ConfiguredObject> childClass : children) + { + String name = childClass.getSimpleName().toLowerCase(); + String relationshipName = name + (name.endsWith("s") ? "es" : "s"); + relationships.put(relationshipName, childClass); + } + return relationships; + } + + private void createOrLoadStore() + { + if (_storeFile != null) + { + if (!_storeFile.exists() || _storeFile.length() == 0) + { + createStoreFileIfNotExist(_storeFile); + } + else + { + load(fileToURL(_storeFile)); + } + } + + createRootEntryIfNotExists(); + } + + private void createRootEntryIfNotExists() + { + if (_rootId == null) + { + // create a root entry for an empty store + ConfigurationEntry brokerEntry = new ConfigurationEntry(UUIDGenerator.generateRandomUUID(), + Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), this); + _rootId = brokerEntry.getId(); + _entries.put(_rootId, brokerEntry); + } + } + + private void load(URL url) + { + InputStream is = null; + try + { + is = url.openStream(); + JsonNode node = loadJsonNodes(is, _objectMapper); + ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries); + _rootId = brokerEntry.getId(); + } + catch (IOException e) + { + throw new IllegalConfigurationException("Cannot load store from: " + url, e); + } + finally + { + if (is != null) + { + if (is != null) + { + try + { + is.close(); + } + catch (IOException e) + { + throw new IllegalConfigurationException("Cannot close input stream for: " + url, e); + } + } + } + } + } + + private void copyInitialStoreFile(String initialStoreLocation) + { + createStoreFileIfNotExist(_storeFile); + URL initialStoreURL = toURL(initialStoreLocation); + InputStream in = null; + try + { + in = initialStoreURL.openStream(); + FileUtils.copy(in, _storeFile); + } + catch (IOException e) + { + throw new IllegalConfigurationException("Cannot create store file " + _storeFile + " by copying initial store from " + initialStoreLocation , e); + } + finally + { + if (in != null) + { + try + { + in.close(); + } + catch (IOException e) + { + throw new IllegalConfigurationException("Cannot close initial store input stream: " + initialStoreLocation , e); + } + } + } + } + + private URL fileToURL(File storeFile) + { + URL storeURL = null; + try + { + storeURL = storeFile.toURI().toURL(); + } + catch (MalformedURLException e) + { + throw new IllegalConfigurationException("Cannot create URL for file " + storeFile, e); + } + return storeURL; + } + + private boolean removeInternal(UUID entryId) + { + ConfigurationEntry oldEntry = _entries.remove(entryId); + if (oldEntry != null) + { + Set<UUID> children = oldEntry.getChildrenIds(); + if (children != null && !children.isEmpty()) + { + for (UUID childId : children) + { + removeInternal(childId); + } + } + return true; + } + return false; + } + + private void saveAsTree() + { + if (_storeFile != null) + { + saveAsTree(_rootId, _entries, _objectMapper, _storeFile); + } + } + + private void saveAsTree(UUID rootId, Map<UUID, ConfigurationEntry> entries, ObjectMapper mapper, File file) + { + Map<String, Object> tree = toTree(rootId, entries); + try + { + mapper.writeValue(file, tree); + } + catch (JsonGenerationException e) + { + throw new IllegalConfigurationException("Cannot generate json!", e); + } + catch (JsonMappingException e) + { + throw new IllegalConfigurationException("Cannot map objects for json serialization!", e); + } + catch (IOException e) + { + throw new IllegalConfigurationException("Cannot save configuration into " + file + "!", e); + } + } + + private Map<String, Object> toTree(UUID rootId, Map<UUID, ConfigurationEntry> entries) + { + ConfigurationEntry entry = entries.get(rootId); + if (entry == null || !entry.getId().equals(rootId)) + { + throw new IllegalConfigurationException("Cannot find entry with id " + rootId + "!"); + } + Map<String, Object> tree = new TreeMap<String, Object>(); + Map<String, Object> attributes = entry.getAttributes(); + if (attributes != null) + { + tree.putAll(attributes); + } + tree.put(ID, entry.getId()); + tree.put(TYPE, entry.getType()); + Set<UUID> childrenIds = entry.getChildrenIds(); + if (childrenIds != null && !childrenIds.isEmpty()) + { + for (UUID relationship : childrenIds) + { + ConfigurationEntry child = entries.get(relationship); + if (child != null) + { + String relationshipName = child.getType().toLowerCase() + "s"; + + @SuppressWarnings("unchecked") + Collection<Map<String, Object>> children = (Collection<Map<String, Object>>) tree.get(relationshipName); + if (children == null) + { + children = new ArrayList<Map<String, Object>>(); + tree.put(relationshipName, children); + } + Map<String, Object> childAsMap = toTree(relationship, entries); + children.add(childAsMap); + } + } + } + return tree; + } + + private JsonNode loadJsonNodes(InputStream is, ObjectMapper mapper) + { + JsonNode root = null; + try + { + root = mapper.readTree(is); + } + catch (JsonProcessingException e) + { + throw new IllegalConfigurationException("Cannot parse json", e); + } + catch (IOException e) + { + throw new IllegalConfigurationException("Cannot read json", e); + } + return root; + } + + private ConfigurationEntry toEntry(JsonNode parent, Class<? extends ConfiguredObject> expectedConfiguredObjectClass, Map<UUID, ConfigurationEntry> entries) + { + Map<String, Object> attributes = null; + Set<UUID> childrenIds = new TreeSet<UUID>(); + Iterator<String> fieldNames = parent.getFieldNames(); + String type = null; + String idAsString = null; + while (fieldNames.hasNext()) + { + String fieldName = fieldNames.next(); + JsonNode fieldNode = parent.get(fieldName); + if (fieldName.equals(ID)) + { + idAsString = fieldNode.asText(); + } + else if (fieldName.equals(TYPE)) + { + type = fieldNode.asText(); + } + else if (fieldNode.isArray()) + { + // array containing either broker children or attribute values + Iterator<JsonNode> elements = fieldNode.getElements(); + List<Object> fieldValues = null; + while (elements.hasNext()) + { + JsonNode element = elements.next(); + if (element.isObject()) + { + Class<? extends ConfiguredObject> expectedChildConfiguredObjectClass = _relationshipClasses.get(fieldName); + // assuming it is a child node + ConfigurationEntry entry = toEntry(element, expectedChildConfiguredObjectClass, entries); + childrenIds.add(entry.getId()); + } + else + { + if (fieldValues == null) + { + fieldValues = new ArrayList<Object>(); + } + fieldValues.add(toObject(element)); + } + } + if (fieldValues != null) + { + Object[] array = fieldValues.toArray(new Object[fieldValues.size()]); + attributes.put(fieldName, array); + } + } + else if (fieldNode.isObject()) + { + // ignore, in-line objects are not supported yet + } + else + { + // primitive attribute + Object value = toObject(fieldNode); + if (attributes == null) + { + attributes = new HashMap<String, Object>(); + } + attributes.put(fieldName, value); + } + } + + if (type == null) + { + if (expectedConfiguredObjectClass == null) + { + throw new IllegalConfigurationException("Type attribute is not provided for configuration entry " + parent); + } + else + { + type = expectedConfiguredObjectClass.getSimpleName(); + } + } + String name = null; + if (attributes != null) + { + name = (String) attributes.get(ATTRIBUTE_NAME); + } + if ((name == null || "".equals(name))) + { + if (expectedConfiguredObjectClass == Broker.class) + { + name = DEFAULT_BROKER_NAME; + } + else + { + throw new IllegalConfigurationException("Name attribute is not provided for configuration entry " + parent); + } + } + UUID id = null; + if (idAsString == null) + { + if (expectedConfiguredObjectClass == Broker.class) + { + id = UUIDGenerator.generateRandomUUID(); + } + else + { + id = UUIDGenerator.generateBrokerChildUUID(type, name); + } + } + else + { + try + { + id = UUID.fromString(idAsString); + } + catch (Exception e) + { + throw new IllegalConfigurationException( + "ID attribute value does not conform to UUID format for configuration entry " + parent); + } + } + ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, childrenIds, this); + if (entries.containsKey(id)) + { + throw new IllegalConfigurationException("Duplicate id is found: " + id + + "! The following configuration entries have the same id: " + entries.get(id) + ", " + entry); + } + entries.put(id, entry); + return entry; + } + + private Object toObject(JsonNode node) + { + if (node.isValueNode()) + { + if (node.isBoolean()) + { + return node.asBoolean(); + } + else if (node.isDouble()) + { + return node.asDouble(); + } + else if (node.isInt()) + { + return node.asInt(); + } + else if (node.isLong()) + { + return node.asLong(); + } + else if (node.isNull()) + { + return null; + } + else + { + return Strings.expand(node.asText()); + } + } + else if (node.isArray()) + { + return toArray(node); + } + else if (node.isObject()) + { + return toMap(node); + } + else + { + throw new IllegalConfigurationException("Unexpected node: " + node); + } + } + + private Map<String, Object> toMap(JsonNode node) + { + Map<String, Object> object = new TreeMap<String, Object>(); + Iterator<String> fieldNames = node.getFieldNames(); + while (fieldNames.hasNext()) + { + String name = fieldNames.next(); + Object value = toObject(node.get(name)); + object.put(name, value); + } + return object; + } + + private Object toArray(JsonNode node) + { + ArrayNode arrayNode = (ArrayNode) node; + Object[] array = new Object[arrayNode.size()]; + Iterator<JsonNode> elements = arrayNode.getElements(); + for (int i = 0; i < array.length; i++) + { + array[i] = toObject(elements.next()); + } + return array; + } + + /* + * Initial store location can be URL or absolute path + */ + private URL toURL(String location) + { + URL url = null; + try + { + url = new URL(location); + } + catch (MalformedURLException e) + { + File locationFile = new File(location); + url = fileToURL(locationFile); + } + return url; + } + + private void createStoreFileIfNotExist(File file) + { + File parent = file.getParentFile(); + if (!parent.exists()) + { + if (!parent.mkdirs()) + { + throw new IllegalConfigurationException("Cannot create folders " + parent); + } + } + try + { + file.createNewFile(); + } + catch (IOException e) + { + throw new IllegalConfigurationException("Cannot create file " + file, e); + } + } + + private void copyEntry(UUID entryId, ConfigurationEntryStore initialStore) + { + ConfigurationEntry entry = initialStore.getEntry(entryId); + if (entry != null) + { + if (_entries.containsKey(entryId)) + { + throw new IllegalConfigurationException("Duplicate id is found: " + entryId + + "! The following configuration entries have the same id: " + _entries.get(entryId) + ", " + entry); + } + _entries.put(entryId, entry); + Set<UUID> children = entry.getChildrenIds(); + if (children != null) + { + for (UUID uuid : children) + { + copyEntry(uuid, initialStore); + } + } + } + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java new file mode 100644 index 0000000000..e7c474bf55 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java @@ -0,0 +1,327 @@ +package org.apache.qpid.server.configuration.store; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.apache.log4j.Logger; +import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfigurationEntryStore; +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Protocol; +import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.server.util.MapValueConverter; + +public class ManagementModeStoreHandler implements ConfigurationEntryStore +{ + private static final Logger LOGGER = Logger.getLogger(ManagementModeStoreHandler.class); + + private static final String MANAGEMENT_MODE_PORT_PREFIX = "MANAGEMENT-MODE-PORT-"; + private static final String PORT_TYPE = Port.class.getSimpleName(); + private static final String VIRTUAL_HOST_TYPE = VirtualHost.class.getSimpleName(); + private static final String ATTRIBUTE_STATE = VirtualHost.STATE; + + private final ConfigurationEntryStore _store; + private final Map<UUID, ConfigurationEntry> _cliEntries; + private final Map<UUID, Object> _quiescedEntries; + private final UUID _rootId; + + public ManagementModeStoreHandler(ConfigurationEntryStore store, BrokerOptions options) + { + ConfigurationEntry storeRoot = store.getRootEntry(); + _store = store; + _rootId = storeRoot.getId(); + _cliEntries = createPortsFromCommadLineOptions(options); + _quiescedEntries = quiesceEntries(storeRoot, options); + } + + @Override + public void open(String storeLocation) + { + throw new IllegalStateException("The store should be already opened"); + } + + @Override + public void open(String storeLocation, String initialStoreLocation) + { + throw new IllegalStateException("The store should be already opened"); + } + + @Override + public void open(String storeLocation, ConfigurationEntryStore initialStore) + { + throw new IllegalStateException("The store should be already opened"); + } + + @Override + public ConfigurationEntry getRootEntry() + { + return getEntry(_rootId); + } + + @Override + public ConfigurationEntry getEntry(UUID id) + { + synchronized (_store) + { + if (_cliEntries.containsKey(id)) + { + return _cliEntries.get(id); + } + + ConfigurationEntry entry = _store.getEntry(id); + if (_quiescedEntries.containsKey(id)) + { + entry = createEntryWithState(entry, State.QUIESCED); + } + else if (id == _rootId) + { + entry = createRootWithCLIEntries(entry); + } + return entry; + } + } + + @Override + public void save(ConfigurationEntry... entries) + { + synchronized (_store) + { + ConfigurationEntry[] entriesToSave = new ConfigurationEntry[entries.length]; + + for (int i = 0; i < entries.length; i++) + { + ConfigurationEntry entry = entries[i]; + UUID id = entry.getId(); + if (_cliEntries.containsKey(id)) + { + throw new IllegalConfigurationException("Cannot save configuration provided as command line argument:" + + entry); + } + else if (_quiescedEntries.containsKey(id)) + { + // save entry with the original state + entry = createEntryWithState(entry, _quiescedEntries.get(ATTRIBUTE_STATE)); + } + else if (_rootId.equals(id)) + { + // save root without command line entries + Set<UUID> childrenIds = new HashSet<UUID>(entry.getChildrenIds()); + if (!_cliEntries.isEmpty()) + { + childrenIds.removeAll(_cliEntries.entrySet()); + } + HashMap<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); + entry = new ConfigurationEntry(entry.getId(), entry.getType(), attributes, childrenIds, this); + } + entriesToSave[i] = entry; + } + + _store.save(entriesToSave); + } + } + + @Override + public UUID[] remove(UUID... entryIds) + { + synchronized (_store) + { + for (UUID id : entryIds) + { + if (_cliEntries.containsKey(id)) + { + throw new IllegalConfigurationException("Cannot change configuration for command line entry:" + + _cliEntries.get(id)); + } + } + UUID[] result = _store.remove(entryIds); + for (UUID id : entryIds) + { + if (_quiescedEntries.containsKey(id)) + { + _quiescedEntries.remove(id); + } + } + return result; + } + } + + @Override + public void copyTo(String copyLocation) + { + synchronized (_store) + { + _store.copyTo(copyLocation); + } + } + + private Map<UUID, ConfigurationEntry> createPortsFromCommadLineOptions(BrokerOptions options) + { + int managementModeRmiPort = options.getManagementModeRmiPort(); + if (managementModeRmiPort < 0) + { + throw new IllegalConfigurationException("Invalid rmi port is specified: " + managementModeRmiPort); + } + int managementModeConnectorPort = options.getManagementModeConnectorPort(); + if (managementModeConnectorPort < 0) + { + throw new IllegalConfigurationException("Invalid connector port is specified: " + managementModeConnectorPort); + } + int managementModeHttpPort = options.getManagementModeHttpPort(); + if (managementModeHttpPort < 0) + { + throw new IllegalConfigurationException("Invalid http port is specified: " + managementModeHttpPort); + } + Map<UUID, ConfigurationEntry> cliEntries = new HashMap<UUID, ConfigurationEntry>(); + if (managementModeRmiPort != 0) + { + ConfigurationEntry entry = createCLIPortEntry(managementModeRmiPort, Protocol.RMI); + cliEntries.put(entry.getId(), entry); + if (managementModeConnectorPort == 0) + { + ConfigurationEntry connectorEntry = createCLIPortEntry(managementModeRmiPort + 100, Protocol.JMX_RMI); + cliEntries.put(connectorEntry.getId(), connectorEntry); + } + } + if (managementModeConnectorPort != 0) + { + ConfigurationEntry entry = createCLIPortEntry(managementModeConnectorPort, Protocol.JMX_RMI); + cliEntries.put(entry.getId(), entry); + } + if (managementModeHttpPort != 0) + { + ConfigurationEntry entry = createCLIPortEntry(managementModeHttpPort, Protocol.HTTP); + cliEntries.put(entry.getId(), entry); + } + return cliEntries; + } + + private ConfigurationEntry createCLIPortEntry(int port, Protocol protocol) + { + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(Port.PORT, port); + attributes.put(Port.PROTOCOLS, Collections.singleton(protocol)); + attributes.put(Port.NAME, MANAGEMENT_MODE_PORT_PREFIX + protocol.name()); + ConfigurationEntry portEntry = new ConfigurationEntry(UUID.randomUUID(), PORT_TYPE, attributes, + Collections.<UUID> emptySet(), this); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Add management mode port configuration " + portEntry + " for port " + port + " and protocol " + + protocol); + } + return portEntry; + } + + private ConfigurationEntry createRootWithCLIEntries(ConfigurationEntry storeRoot) + { + Set<UUID> childrenIds = new HashSet<UUID>(storeRoot.getChildrenIds()); + if (!_cliEntries.isEmpty()) + { + childrenIds.addAll(_cliEntries.keySet()); + } + ConfigurationEntry root = new ConfigurationEntry(storeRoot.getId(), storeRoot.getType(), new HashMap<String, Object>( + storeRoot.getAttributes()), childrenIds, this); + return root; + } + + private Map<UUID, Object> quiesceEntries(ConfigurationEntry storeRoot, BrokerOptions options) + { + Map<UUID, Object> quiescedEntries = new HashMap<UUID, Object>(); + Set<UUID> childrenIds; + int managementModeRmiPort = options.getManagementModeRmiPort(); + int managementModeConnectorPort = options.getManagementModeConnectorPort(); + int managementModeHttpPort = options.getManagementModeHttpPort(); + childrenIds = storeRoot.getChildrenIds(); + for (UUID id : childrenIds) + { + ConfigurationEntry entry = _store.getEntry(id); + String entryType = entry.getType(); + Map<String, Object> attributes = entry.getAttributes(); + boolean quiesce = false; + if (VIRTUAL_HOST_TYPE.equals(entryType)) + { + quiesce = true; + } + else if (PORT_TYPE.equalsIgnoreCase(entryType)) + { + if (attributes == null) + { + throw new IllegalConfigurationException("Port attributes are not set in " + entry); + } + Set<Protocol> protocols = getPortProtocolsAttribute(attributes); + if (protocols == null) + { + quiesce = true; + } + else + { + for (Protocol protocol : protocols) + { + switch (protocol) + { + case JMX_RMI: + quiesce = managementModeConnectorPort > 0 || managementModeRmiPort > 0; + break; + case RMI: + quiesce = managementModeRmiPort > 0; + break; + case HTTP: + case HTTPS: + quiesce = managementModeHttpPort > 0; + break; + default: + quiesce = true; + } + } + } + } + if (quiesce) + { + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Management mode quiescing entry " + entry); + } + + // save original state + quiescedEntries.put(entry.getId(), attributes.get(ATTRIBUTE_STATE)); + } + } + return quiescedEntries; + } + + private Set<Protocol> getPortProtocolsAttribute(Map<String, Object> attributes) + { + Object object = attributes.get(Port.PROTOCOLS); + if (object == null) + { + return null; + } + return MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class); + } + + private ConfigurationEntry createEntryWithState(ConfigurationEntry entry, Object state) + { + Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); + if (state == null) + { + attributes.remove(ATTRIBUTE_STATE); + } + else + { + attributes.put(ATTRIBUTE_STATE, state); + } + Set<UUID> originalChildren = entry.getChildrenIds(); + Set<UUID> children = null; + if (originalChildren != null) + { + children = new HashSet<UUID>(originalChildren); + } + return new ConfigurationEntry(entry.getId(), entry.getType(), attributes, children, entry.getStore()); + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java new file mode 100644 index 0000000000..813702d0a6 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java @@ -0,0 +1,205 @@ +/* + * + * 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.store; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.TreeSet; +import java.util.UUID; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfigurationEntryStore; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfigurationChangeListener; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.VirtualHost; + +public class StoreConfigurationChangeListener implements ConfigurationChangeListener +{ + private ConfigurationEntryStore _store; + + public StoreConfigurationChangeListener(ConfigurationEntryStore store) + { + super(); + _store = store; + } + + @Override + public void stateChanged(ConfiguredObject object, State oldState, State newState) + { + if (newState == State.DELETED) + { + _store.remove(object.getId()); + object.removeChangeListener(this); + } + } + + @Override + public void childAdded(ConfiguredObject object, ConfiguredObject child) + { + // exclude VirtualHost children from storing in broker store + if (!(object instanceof VirtualHost)) + { + child.addChangeListener(this); + ConfigurationEntry parentEntry = toConfigurationEntry(object); + ConfigurationEntry childEntry = toConfigurationEntry(child); + _store.save(parentEntry, childEntry); + } + + } + + @Override + public void childRemoved(ConfiguredObject object, ConfiguredObject child) + { + _store.save(toConfigurationEntry(object)); + } + + @Override + public void attributeSet(ConfiguredObject object, String attrinuteName, Object oldAttributeValue, Object newAttributeValue) + { + _store.save(toConfigurationEntry(object)); + } + + private ConfigurationEntry toConfigurationEntry(ConfiguredObject object) + { + Class<? extends ConfiguredObject> objectType = getConfiguredObjectType(object); + Set<UUID> childrenIds = getChildernIds(object, objectType); + ConfigurationEntry entry = new ConfigurationEntry(object.getId(), objectType.getSimpleName(), + object.getActualAttributes(), childrenIds, _store); + return entry; + } + + private Set<UUID> getChildernIds(ConfiguredObject object, Class<? extends ConfiguredObject> objectType) + { + // Virtual Host children's IDs should not be stored in broker store + if (object instanceof VirtualHost) + { + return Collections.emptySet(); + } + Set<UUID> childrenIds = new TreeSet<UUID>(); + Collection<Class<? extends ConfiguredObject>> childClasses = Model.getInstance().getChildTypes(objectType); + if (childClasses != null) + { + for (Class<? extends ConfiguredObject> childClass : childClasses) + { + Collection<? extends ConfiguredObject> children = object.getChildren(childClass); + if (children != null) + { + for (ConfiguredObject childObject : children) + { + childrenIds.add(childObject.getId()); + } + } + } + } + return childrenIds; + } + + private Class<? extends ConfiguredObject> getConfiguredObjectType(ConfiguredObject object) + { + if (object instanceof Broker) + { + return Broker.class; + } + return getConfiguredObjectTypeFromImplementedInterfaces(object.getClass()); + } + + @SuppressWarnings("unchecked") + private Class<? extends ConfiguredObject> getConfiguredObjectTypeFromImplementedInterfaces(Class<?> objectClass) + { + // get all implemented interfaces extending ConfiguredObject + Set<Class<?>> interfaces = getImplementedInterfacesExtendingSuper(objectClass, ConfiguredObject.class); + + if (interfaces.size() == 0) + { + throw new RuntimeException("Can not identify the configured object type"); + } + + if (interfaces.size() == 1) + { + return (Class<? extends ConfiguredObject>)interfaces.iterator().next(); + } + + Set<Class<?>> superInterfaces = new HashSet<Class<?>>(); + + // find all super interfaces + for (Class<?> interfaceClass : interfaces) + { + for (Class<?> interfaceClass2 : interfaces) + { + if (interfaceClass != interfaceClass2) + { + if (interfaceClass.isAssignableFrom(interfaceClass2)) + { + superInterfaces.add(interfaceClass); + } + } + } + } + + // remove super interfaces + for (Class<?> superInterface : superInterfaces) + { + interfaces.remove(superInterface); + } + + if (interfaces.size() == 1) + { + return (Class<? extends ConfiguredObject>)interfaces.iterator().next(); + } + else + { + throw new RuntimeException("Can not identify the configured object type as an it implements" + + " more than one configured object interfaces: " + interfaces); + } + + } + + private Set<Class<?>> getImplementedInterfacesExtendingSuper(Class<?> classInstance, Class<?> superInterface) + { + Set<Class<?>> interfaces = new HashSet<Class<?>>(); + Class<?>[] classInterfaces = classInstance.getInterfaces(); + for (Class<?> interfaceClass : classInterfaces) + { + if (interfaceClass!= superInterface && superInterface.isAssignableFrom(interfaceClass)) + { + interfaces.add(interfaceClass); + } + } + Class<?> superClass = classInstance.getSuperclass(); + if (superClass != null) + { + Set<Class<?>> superClassInterfaces = getImplementedInterfacesExtendingSuper(superClass, superInterface); + interfaces.addAll(superClassInterfaces); + } + return interfaces; + } + + @Override + public String toString() + { + return "StoreConfigurationChangeListener [store=" + _store + "]"; + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObject.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java index ff4e38d9f7..e37e58b840 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObject.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java @@ -18,20 +18,24 @@ * under the License. * */ +package org.apache.qpid.server.configuration.store.factory; -package org.apache.qpid.server.configuration; +import org.apache.qpid.server.configuration.ConfigurationEntryStore; +import org.apache.qpid.server.configuration.ConfigurationStoreFactory; +import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore; -import java.util.UUID; - -public interface ConfiguredObject<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T, C>> +public class JsonConfigurationStoreFactory implements ConfigurationStoreFactory { - public UUID getQMFId(); - - public T getConfigType(); - - public ConfiguredObject<T,C> getParent(); + @Override + public ConfigurationEntryStore createStore() + { + return new JsonConfigurationEntryStore(); + } - public boolean isDurable(); + @Override + public String getStoreType() + { + return JsonConfigurationEntryStore.STORE_TYPE; + } - long getCreateTime(); } diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java new file mode 100644 index 0000000000..b6de1e136a --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java @@ -0,0 +1,67 @@ +/* + * + * 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.updater; + +import java.util.concurrent.Callable; + +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.State; + +public final class ChangeStateTask implements Callable<State> +{ + private ConfiguredObject _object; + private State _expectedState; + private State _desiredState; + + public ChangeStateTask(ConfiguredObject object, State expectedState, State desiredState) + { + _object = object; + _expectedState = expectedState; + _desiredState = desiredState; + } + + public ConfiguredObject getObject() + { + return _object; + } + + public State getExpectedState() + { + return _expectedState; + } + + public State getDesiredState() + { + return _desiredState; + } + + @Override + public State call() + { + return _object.setDesiredState(_expectedState, _desiredState); + } + + @Override + public String toString() + { + return "ChangeStateTask [object=" + _object + ", expectedState=" + _expectedState + ", desiredState=" + _desiredState + "]"; + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java new file mode 100644 index 0000000000..d3a8f5b797 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java @@ -0,0 +1,78 @@ +/* + * + * 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.updater; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.Callable; + +import org.apache.qpid.server.model.ConfiguredObject; + +public final class CreateChildTask implements Callable<ConfiguredObject> +{ + private ConfiguredObject _object; + private Class<? extends ConfiguredObject> _childClass; + private Map<String, Object> _attributes; + private ConfiguredObject[] _otherParents; + + public CreateChildTask(ConfiguredObject object, Class<? extends ConfiguredObject> childClass, Map<String, Object> attributes, + ConfiguredObject... otherParents) + { + _object = object; + _childClass = childClass; + _attributes = attributes; + _otherParents = otherParents; + } + + public ConfiguredObject getObject() + { + return _object; + } + + public Class<? extends ConfiguredObject> getChildClass() + { + return _childClass; + } + + public Map<String, Object> getAttributes() + { + return _attributes; + } + + public ConfiguredObject[] getOtherParents() + { + return _otherParents; + } + + @Override + public ConfiguredObject call() + { + return _object.createChild(_childClass, _attributes, _otherParents); + } + + @Override + public String toString() + { + return "CreateChildTask [object=" + _object + ", childClass=" + _childClass + ", attributes=" + _attributes + + ", otherParents=" + Arrays.toString(_otherParents) + "]"; + } + +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java new file mode 100644 index 0000000000..94649434e6 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java @@ -0,0 +1,74 @@ +/* + * + * 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.updater; + +import java.util.concurrent.Callable; + +import org.apache.qpid.server.model.ConfiguredObject; + +public final class SetAttributeTask implements Callable<Object> +{ + private ConfiguredObject _object; + private String _attributeName; + private Object _expectedValue; + private Object _desiredValue; + + public SetAttributeTask(ConfiguredObject object, String attributeName, Object expectedValue, Object desiredValue) + { + _object = object; + _attributeName = attributeName; + _expectedValue = expectedValue; + _desiredValue = desiredValue; + } + + public ConfiguredObject getObject() + { + return _object; + } + + public String getAttributeName() + { + return _attributeName; + } + + public Object getExpectedValue() + { + return _expectedValue; + } + + public Object getDesiredValue() + { + return _desiredValue; + } + + @Override + public Object call() + { + return _object.setAttribute(_attributeName, _expectedValue, _desiredValue); + } + + @Override + public String toString() + { + return "SetAttributeTask [object=" + _object + ", attributeName=" + _attributeName + ", expectedValue=" + _expectedValue + + ", desiredValue=" + _desiredValue + "]"; + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java new file mode 100644 index 0000000000..671104d413 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java @@ -0,0 +1,324 @@ +/* + * + * 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.updater; + +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.RunnableFuture; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import javax.security.auth.Subject; + +import org.apache.log4j.Logger; +import org.apache.qpid.server.logging.LogActor; +import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.model.State; +import org.apache.qpid.server.security.SecurityManager; + +public class TaskExecutor +{ + private static final String TASK_EXECUTION_THREAD_NAME = "Broker-Configuration-Thread"; + private static final Logger LOGGER = Logger.getLogger(TaskExecutor.class); + + private volatile Thread _taskThread; + private final AtomicReference<State> _state; + private volatile ExecutorService _executor; + + public TaskExecutor() + { + _state = new AtomicReference<State>(State.INITIALISING); + } + + public State getState() + { + return _state.get(); + } + + public void start() + { + if (_state.compareAndSet(State.INITIALISING, State.ACTIVE)) + { + LOGGER.debug("Starting task executor"); + _executor = Executors.newFixedThreadPool(1, new ThreadFactory() + { + @Override + public Thread newThread(Runnable r) + { + _taskThread = new Thread(r, TASK_EXECUTION_THREAD_NAME); + return _taskThread; + } + }); + LOGGER.debug("Task executor is started"); + } + } + + public void stopImmediately() + { + if (_state.compareAndSet(State.ACTIVE, State.STOPPED)) + { + ExecutorService executor = _executor; + if (executor != null) + { + LOGGER.debug("Stopping task executor immediately"); + List<Runnable> cancelledTasks = executor.shutdownNow(); + if (cancelledTasks != null) + { + for (Runnable runnable : cancelledTasks) + { + if (runnable instanceof RunnableFuture<?>) + { + ((RunnableFuture<?>) runnable).cancel(true); + } + } + } + _executor = null; + _taskThread = null; + LOGGER.debug("Task executor was stopped immediately. Number of unfinished tasks: " + cancelledTasks.size()); + } + } + } + + public void stop() + { + if (_state.compareAndSet(State.ACTIVE, State.STOPPED)) + { + ExecutorService executor = _executor; + if (executor != null) + { + LOGGER.debug("Stopping task executor"); + executor.shutdown(); + _executor = null; + _taskThread = null; + LOGGER.debug("Task executor is stopped"); + } + } + } + + Future<?> submit(Callable<?> task) + { + checkState(); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Submitting task: " + task); + } + Future<?> future = null; + if (isTaskExecutorThread()) + { + Object result = executeTaskAndHandleExceptions(task); + return new ImmediateFuture(result); + } + else + { + future = _executor.submit(new CallableWrapper(task)); + } + return future; + } + + public Object submitAndWait(Callable<?> task) throws CancellationException + { + try + { + Future<?> future = submit(task); + return future.get(); + } + catch (InterruptedException e) + { + throw new RuntimeException("Task execution was interrupted: " + task, e); + } + catch (ExecutionException e) + { + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) + { + throw (RuntimeException) cause; + } + else if (cause instanceof Exception) + { + throw new RuntimeException("Failed to execute user task: " + task, cause); + } + else if (cause instanceof Error) + { + throw (Error) cause; + } + else + { + throw new RuntimeException("Failed to execute user task: " + task, cause); + } + } + } + + public boolean isTaskExecutorThread() + { + return Thread.currentThread() == _taskThread; + } + + private void checkState() + { + if (_state.get() != State.ACTIVE) + { + throw new IllegalStateException("Task executor is not in ACTIVE state"); + } + } + + private Object executeTaskAndHandleExceptions(Callable<?> userTask) + { + try + { + return executeTask(userTask); + } + catch (Exception e) + { + if (e instanceof RuntimeException) + { + throw (RuntimeException) e; + } + throw new RuntimeException("Failed to execute user task: " + userTask, e); + } + } + + private Object executeTask(Callable<?> userTask) throws Exception + { + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Performing task " + userTask); + } + Object result = userTask.call(); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Task " + userTask + " is performed successfully with result:" + result); + } + return result; + } + + private class CallableWrapper implements Callable<Object> + { + private Callable<?> _userTask; + private Subject _securityManagerSubject; + private LogActor _actor; + private Subject _contextSubject; + + public CallableWrapper(Callable<?> userWork) + { + _userTask = userWork; + _securityManagerSubject = SecurityManager.getThreadSubject(); + _actor = CurrentActor.get(); + _contextSubject = Subject.getSubject(AccessController.getContext()); + } + + @Override + public Object call() throws Exception + { + SecurityManager.setThreadSubject(_securityManagerSubject); + CurrentActor.set(_actor); + + try + { + Object result = null; + try + { + result = Subject.doAs(_contextSubject, new PrivilegedExceptionAction<Object>() + { + @Override + public Object run() throws Exception + { + return executeTask(_userTask); + } + }); + } + catch (PrivilegedActionException e) + { + throw e.getException(); + } + return result; + } + finally + { + try + { + CurrentActor.remove(); + } + catch (Exception e) + { + LOGGER.warn("Unxpected exception on current actor removal", e); + } + try + { + SecurityManager.setThreadSubject(null); + } + catch (Exception e) + { + LOGGER.warn("Unxpected exception on nullifying of subject for a security manager", e); + } + } + } + } + + private class ImmediateFuture implements Future<Object> + { + private Object _result; + + public ImmediateFuture(Object result) + { + super(); + this._result = result; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) + { + return false; + } + + @Override + public boolean isCancelled() + { + return false; + } + + @Override + public boolean isDone() + { + return true; + } + + @Override + public Object get() + { + return _result; + } + + @Override + public Object get(long timeout, TimeUnit unit) + { + return get(); + } + } +} |