use of org.apache.commons.configuration.FileConfiguration in project distributedlog by twitter.
the class ConfigurationSubscription method reload.
@VisibleForTesting
void reload() {
// No-op if already loaded.
if (!initConfig()) {
return;
}
// Reload if config exists.
Set<String> confKeys = Sets.newHashSet();
for (FileConfiguration fileConfig : fileConfigs) {
LOG.debug("Check and reload config, file={}, lastModified={}", fileConfig.getFile(), fileConfig.getFile().lastModified());
fileConfig.reload();
// load keys
Iterator keyIter = fileConfig.getKeys();
while (keyIter.hasNext()) {
String key = (String) keyIter.next();
confKeys.add(key);
}
}
// clear unexisted keys
Iterator viewIter = viewConfig.getKeys();
while (viewIter.hasNext()) {
String key = (String) viewIter.next();
if (!confKeys.contains(key)) {
clearViewProperty(key);
}
}
LOG.info("Reload features : {}", confKeys);
// load keys from files
for (FileConfiguration fileConfig : fileConfigs) {
try {
loadView(fileConfig);
} catch (Exception ex) {
if (!fileNotFound(ex)) {
LOG.error("Config reload failed for file {}", fileConfig.getFileName(), ex);
}
}
}
for (ConfigurationListener listener : confListeners) {
listener.onReload(viewConfig);
}
}
use of org.apache.commons.configuration.FileConfiguration in project distributedlog by twitter.
the class ConfigurationSubscription method initConfig.
private boolean initConfig() {
if (fileConfigs.isEmpty()) {
try {
for (FileConfigurationBuilder fileConfigBuilder : fileConfigBuilders) {
FileConfiguration fileConfig = fileConfigBuilder.getConfiguration();
FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
reloadingStrategy.setRefreshDelay(0);
fileConfig.setReloadingStrategy(reloadingStrategy);
fileConfigs.add(fileConfig);
}
} catch (ConfigurationException ex) {
if (!fileNotFound(ex)) {
LOG.error("Config init failed {}", ex);
}
}
}
return !fileConfigs.isEmpty();
}
use of org.apache.commons.configuration.FileConfiguration in project zaproxy by zaproxy.
the class OptionsParamApiUnitTest method shouldUseDefaultValuesWhenLoadingFileConfigurationWithInvalidValues.
@Test
public void shouldUseDefaultValuesWhenLoadingFileConfigurationWithInvalidValues() {
// Given
OptionsParamApi param = new OptionsParamApi();
FileConfiguration config = createTestConfigWithInvalidValues();
// When
param.load(config);
// Then
assertThat(param.isEnabled(), is(equalTo(true)));
assertThat(param.isSecureOnly(), is(equalTo(false)));
assertThat(param.isDisableKey(), is(equalTo(false)));
assertThat(param.isIncErrorDetails(), is(equalTo(false)));
assertThat(param.isAutofillKey(), is(equalTo(false)));
assertThat(param.isEnableJSONP(), is(equalTo(false)));
assertThat(param.getRealKey(), is(equalTo("")));
}
use of org.apache.commons.configuration.FileConfiguration in project zaproxy by zaproxy.
the class ExtensionParamUnitTest method shouldParseLoadedFileConfiguration.
@Test
public void shouldParseLoadedFileConfiguration() {
// Given
ExtensionParam param = new ExtensionParam();
FileConfiguration config = createTestConfig(false, true, false, true, true);
// When
param.load(config);
// Then
assertThat(param.isExtensionEnabled("Extension 1"), is(equalTo(false)));
assertThat(param.isExtensionEnabled("Extension 2"), is(equalTo(true)));
assertThat(param.isExtensionEnabled("Extension 3"), is(equalTo(false)));
assertThat(param.isExtensionEnabled("Extension 4"), is(equalTo(true)));
assertThat(param.isExtensionEnabled("Extension 5"), is(equalTo(true)));
}
use of org.apache.commons.configuration.FileConfiguration in project zaproxy by zaproxy.
the class ExtensionParamUnitTest method shouldNotPersistNullExtensionNamesOrNullEnabledState.
@Test
public void shouldNotPersistNullExtensionNamesOrNullEnabledState() {
// Given
ExtensionParam param = new ExtensionParam();
FileConfiguration config = createTestConfig();
param.load(config);
Map<String, Boolean> states = new HashMap<>();
states.put(null, Boolean.FALSE);
states.put("Extension 2", null);
// When
param.setExtensionsState(states);
// Then
assertThat(param.getConfig().getKeys().hasNext(), is(equalTo(false)));
}
Aggregations