diff --git a/src/DataDistributionManagerJava/src/org/mases/datadistributionmanager/configuration/MastershipConfiguration.java b/src/DataDistributionManagerJava/src/org/mases/datadistributionmanager/configuration/MastershipConfiguration.java new file mode 100644 index 00000000..2ec45e1b --- /dev/null +++ b/src/DataDistributionManagerJava/src/org/mases/datadistributionmanager/configuration/MastershipConfiguration.java @@ -0,0 +1,82 @@ +/* +* Copyright 2021 MASES s.r.l. +* +* Licensed 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. +* +* Refer to LICENSE for more information. +*/ + +package org.mases.datadistributionmanager.configuration; + +import org.mases.datadistributionmanager.CommonConfiguration; +import org.mases.datadistributionmanager.IConfiguration; + +/** + * The configuration class for mastership based on + * DataDistributionMastershipManager + */ +public class MastershipConfiguration extends CommonConfiguration { + public static final String MastershipGlobalConfigurationBasePropertyKey = "datadistributionmanager.mastership."; + + /** + * Duplicates a configuration + * + * @param originalConf {@link IConfiguration} to duplicate + */ + public MastershipConfiguration(IConfiguration originalConf) { + super(originalConf); + setMastershipLibrary("DataDistributionMastershipManager.dll"); + } + + /** + * Duplicates a configuration + * @param libraryName The mastership library name (or full path) to use + * @param originalConf {@link IConfiguration} to duplicate + */ + public MastershipConfiguration(String libraryName, IConfiguration originalConf) { + super(originalConf); + setMastershipLibrary("DataDistributionMastershipManager.dll"); + } + + /** + * Generic getter for all configuration properties + * + * @param property The property name + * @return The property value + */ + public String getProperty(String property) { + String value = ""; + if (property.startsWith(MastershipGlobalConfigurationBasePropertyKey)) { + if (keyValuePair.containsKey(property)) + value = keyValuePair.get(property); + } else { + if (keyValuePair.containsKey(MastershipGlobalConfigurationBasePropertyKey + property)) + value = keyValuePair.get(MastershipGlobalConfigurationBasePropertyKey + property); + } + return value; + } + + /** + * Generic setter for all configuration properties + * + * @param property The property name + * @param value The property value + */ + public void setProperty(String property, String value) { + if (property.startsWith(MastershipGlobalConfigurationBasePropertyKey)) { + keyValuePair.put(property, value); + } else { + keyValuePair.put(MastershipGlobalConfigurationBasePropertyKey + property, value); + } + } +} diff --git a/src/DataDistributionManagerNet/Configuration/MastershipConfiguration.cs b/src/DataDistributionManagerNet/Configuration/MastershipConfiguration.cs new file mode 100644 index 00000000..e8707d06 --- /dev/null +++ b/src/DataDistributionManagerNet/Configuration/MastershipConfiguration.cs @@ -0,0 +1,90 @@ +/* +* Copyright 2021 MASES s.r.l. +* +* Licensed 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. +* +* Refer to LICENSE for more information. +*/ + +namespace MASES.DataDistributionManager.Bindings.Configuration +{ + /// + /// The configuration class for mastership based on DataDistributionMastershipManager + /// + public class MastershipConfiguration : CommonConfiguration + { + /// + /// Base property name of all specific configuration key of + /// + public const string MastershipGlobalConfigurationBasePropertyKey = "datadistributionmanager.mastership."; + + /// + /// Duplicates a configuration + /// + /// to duplicate + public MastershipConfiguration(IConfiguration originalConf) + : base(originalConf) + { +#if DEBUG + MastershipLibrary = "DataDistributionMastershipManagerd.dll"; +#else + MastershipLibrary = "DataDistributionMastershipManager.dll"; +#endif + } + + /// + /// Duplicates a configuration + /// + /// The mastership library name (or full path) to use + /// to duplicate + public MastershipConfiguration(string libraryName, IConfiguration originalConf) + : base(originalConf) + { + MastershipLibrary = libraryName; + } + + /// + /// Generic setter/getter for all configuration properties + /// + /// The property name + /// The property value + public string this[string property] + { + get + { + string value = string.Empty; + if (property.StartsWith(MastershipGlobalConfigurationBasePropertyKey)) + { + keyValuePair.TryGetValue(property, out value); + } + else + { + keyValuePair.TryGetValue(MastershipGlobalConfigurationBasePropertyKey + property, out value); + } + return value; + } + set + { + if (property.StartsWith(MastershipGlobalConfigurationBasePropertyKey)) + { + keyValuePair[property] = value; + } + else + { + keyValuePair[MastershipGlobalConfigurationBasePropertyKey + property] = value; + } + EmitPropertyChanged(property); + } + } + } +} diff --git a/src/DataDistributionManagerNet/DataDistributionManagerNet.csproj b/src/DataDistributionManagerNet/DataDistributionManagerNet.csproj index 0bc64f5b..65cc7b53 100644 --- a/src/DataDistributionManagerNet/DataDistributionManagerNet.csproj +++ b/src/DataDistributionManagerNet/DataDistributionManagerNet.csproj @@ -60,6 +60,7 @@ + diff --git a/src/DataDistributionManagerNet/DataDistributionManagerNet5.csproj b/src/DataDistributionManagerNet/DataDistributionManagerNet5.csproj index ba18cf23..9c833899 100644 --- a/src/DataDistributionManagerNet/DataDistributionManagerNet5.csproj +++ b/src/DataDistributionManagerNet/DataDistributionManagerNet5.csproj @@ -23,6 +23,7 @@ +