Skip to content

Commit

Permalink
Added MastershipConfiguration for configuration management
Browse files Browse the repository at this point in the history
  • Loading branch information
mariomastrodicasa committed Mar 17, 2021
1 parent 0dd3c1e commit 3254f5d
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// The configuration class for mastership based on DataDistributionMastershipManager
/// </summary>
public class MastershipConfiguration : CommonConfiguration
{
/// <summary>
/// Base property name of all specific configuration key of <see cref="MastershipConfiguration"/>
/// </summary>
public const string MastershipGlobalConfigurationBasePropertyKey = "datadistributionmanager.mastership.";

/// <summary>
/// Duplicates a configuration
/// </summary>
/// <param name="originalConf"><see cref="IConfiguration"/> to duplicate</param>
public MastershipConfiguration(IConfiguration originalConf)
: base(originalConf)
{
#if DEBUG
MastershipLibrary = "DataDistributionMastershipManagerd.dll";
#else
MastershipLibrary = "DataDistributionMastershipManager.dll";
#endif
}

/// <summary>
/// Duplicates a configuration
/// </summary>
/// <param name="libraryName">The mastership library name (or full path) to use</param>
/// <param name="originalConf"><see cref="IConfiguration"/> to duplicate</param>
public MastershipConfiguration(string libraryName, IConfiguration originalConf)
: base(originalConf)
{
MastershipLibrary = libraryName;
}

/// <summary>
/// Generic setter/getter for all configuration properties
/// </summary>
/// <param name="property">The property name</param>
/// <returns>The property value</returns>
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Configuration\KafkaChannelConfiguration.cs" />
<Compile Include="Configuration\KafkaConfiguration.cs" />
<Compile Include="Configuration\OpenDDSChannelConfiguration.cs" />
<Compile Include="Configuration\MastershipConfiguration.cs" />
<Compile Include="Configuration\OpenDDSConfiguration.cs" />
<Compile Include="GlobalConfiguration.cs" />
<Compile Include="CommonConfiguration.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="BaseConfiguration.cs" />
<Compile Include="Configuration\KafkaChannelConfiguration.cs" />
<Compile Include="Configuration\KafkaConfiguration.cs" />
<Compile Include="Configuration\MastershipConfiguration.cs" />
<Compile Include="Configuration\OpenDDSChannelConfiguration.cs" />
<Compile Include="Configuration\OpenDDSConfiguration.cs" />
<Compile Include="GlobalConfiguration.cs" />
Expand Down

0 comments on commit 3254f5d

Please sign in to comment.