aboutsummaryrefslogtreecommitdiffstats
path: root/common/openecomp-common-configuration-management/openecomp-configuration-management-core
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2017-10-22 19:03:46 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2017-10-23 12:38:26 +0300
commitb118cd814ea0a230486c4179d0bcdc27d39d92b1 (patch)
treee61517052aab52e3a99e399e979456a2ef60bafd /common/openecomp-common-configuration-management/openecomp-configuration-management-core
parent30e46525c1406fb3b10603606c4efcc033ee58c4 (diff)
Additinal fixes for resources not being released
More fixes for input streams not being properly closed, with unit tests and other minor improvements (code cleanup and coding conventions). Change-Id: I6751f924a1469d49b996e4f1d6c61371af6714b1 Issue-ID: SDC-291 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'common/openecomp-common-configuration-management/openecomp-configuration-management-core')
-rw-r--r--common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationChangeNotifier.java80
1 files changed, 42 insertions, 38 deletions
diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationChangeNotifier.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationChangeNotifier.java
index 5c3df4a56d..3922720d48 100644
--- a/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationChangeNotifier.java
+++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-core/src/main/java/org/openecomp/config/impl/ConfigurationChangeNotifier.java
@@ -24,10 +24,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ExecutorService;
@@ -44,15 +44,15 @@ import javax.management.ObjectName;
*/
public final class ConfigurationChangeNotifier {
- private HashMap<String, List<NotificationData>> store = new HashMap<>();
- private ScheduledExecutorService executor =
+ private final HashMap<String, List<NotificationData>> store = new HashMap<>();
+ private final ScheduledExecutorService executor =
Executors.newScheduledThreadPool(5, ConfigurationUtils.getThreadFactory());
- private ExecutorService notificationExcecutor =
+ private final ExecutorService notificationExecutor =
Executors.newCachedThreadPool(ConfigurationUtils.getThreadFactory());
- private Map<String, WatchService> watchServiceCollection =
+ private final Map<String, WatchService> watchServiceCollection =
Collections.synchronizedMap(new HashMap<>());
- {
+ static {
if (!Thread.currentThread().getStackTrace()[2].getClassName()
.equals(ConfigurationImpl.class.getName())) {
throw new RuntimeException("Illegal access.");
@@ -66,13 +66,13 @@ public final class ConfigurationChangeNotifier {
*/
public ConfigurationChangeNotifier(Map<String, AggregateConfiguration> inMemoryConfig) {
executor.scheduleWithFixedDelay(() -> this
- .pollFilesystemAndUpdateConfigurationIfREquired(inMemoryConfig,
+ .pollFilesystemAndUpdateConfigurationIfRequired(inMemoryConfig,
System.getProperty("config.location"), false), 1, 1, TimeUnit.MILLISECONDS);
executor.scheduleWithFixedDelay(() -> this
- .pollFilesystemAndUpdateConfigurationIfREquired(inMemoryConfig,
+ .pollFilesystemAndUpdateConfigurationIfRequired(inMemoryConfig,
System.getProperty("tenant.config.location"), true), 1, 1, TimeUnit.MILLISECONDS);
executor.scheduleWithFixedDelay(() -> this
- .pollFilesystemAndUpdateNodeSpecificConfigurationIfREquired(
+ .pollFilesystemAndUpdateNodeSpecificConfigurationIfRequired(
System.getProperty("node.config.location")), 1, 1, TimeUnit.MILLISECONDS);
}
@@ -91,13 +91,13 @@ public final class ConfigurationChangeNotifier {
}
/**
- * Poll filesystem and update configuration if r equired.
+ * Poll filesystem and update configuration if required.
*
* @param inMemoryConfig the in memory config
* @param location the location
* @param isTenantLocation the is tenant location
*/
- public void pollFilesystemAndUpdateConfigurationIfREquired(
+ public void pollFilesystemAndUpdateConfigurationIfRequired(
Map<String, AggregateConfiguration> inMemoryConfig, String location,
boolean isTenantLocation) {
try {
@@ -132,20 +132,19 @@ public final class ConfigurationChangeNotifier {
updateConfigurationValues(tenantNamespaceArray[0], tenantNamespaceArray[1], map);
}
} else {
- Iterator<String> repoKeys = inMemoryConfig.keySet().iterator();
- while (repoKeys.hasNext()) {
- repositoryKey = repoKeys.next();
+ for (String configKey : inMemoryConfig.keySet()) {
+ repositoryKey = configKey;
AggregateConfiguration config = inMemoryConfig.get(repositoryKey);
if (config.containsConfig(file)) {
LinkedHashMap origConfig = ConfigurationUtils.toMap(config.getFinalConfiguration());
config.removeConfig(file);
LinkedHashMap latestConfig =
- ConfigurationUtils.toMap(config.getFinalConfiguration());
+ ConfigurationUtils.toMap(config.getFinalConfiguration());
Map map = ConfigurationUtils.diff(origConfig, latestConfig);
String[] tenantNamespaceArray =
- repositoryKey.split(Constants.KEY_ELEMENTS_DELEMETER);
+ repositoryKey.split(Constants.KEY_ELEMENTS_DELEMETER);
updateConfigurationValues(tenantNamespaceArray[0], tenantNamespaceArray[1],
- map);
+ map);
}
}
}
@@ -169,26 +168,26 @@ public final class ConfigurationChangeNotifier {
}
/**
- * Poll filesystem and update node specific configuration if r equired.
+ * Poll filesystem and update node specific configuration if required.
*
* @param location the location
*/
- public void pollFilesystemAndUpdateNodeSpecificConfigurationIfREquired(String location) {
+ public void pollFilesystemAndUpdateNodeSpecificConfigurationIfRequired(String location) {
try {
Set<Path> paths = watchForChange(location);
if (paths != null) {
for (Path path : paths) {
File file = path.toAbsolutePath().toFile();
- String repositoryKey = null;
+
if (ConfigurationUtils.isConfig(file)) {
- repositoryKey = ConfigurationUtils.getConfigurationRepositoryKey(file);
+ String repositoryKey = ConfigurationUtils.getConfigurationRepositoryKey(file);
ConfigurationRepository.lookup().populateOverrideConfigurtaion(repositoryKey, file);
} else {
ConfigurationRepository.lookup().removeOverrideConfigurtaion(file);
}
}
}
- } catch (Throwable exception) {
+ } catch (Exception exception) {
exception.printStackTrace();
}
}
@@ -241,7 +240,7 @@ public final class ConfigurationChangeNotifier {
private void triggerScanning(String key) {
if (store.get(key) != null) {
- notificationExcecutor.submit(() -> scanForChanges(key));
+ notificationExecutor.submit(() -> scanForChanges(key));
} else {
throw new IllegalArgumentException("Notification service for " + key + " is suspended.");
}
@@ -250,13 +249,9 @@ public final class ConfigurationChangeNotifier {
private void scanForChanges(String key) {
List<NotificationData> list = store.get(key);
if (list != null) {
- int size = list.size();
- for (int i = 0; i < size; i++) {
- NotificationData notificationData = list.get(i);
- if (notificationData.isChanged()) {
- notificationExcecutor.submit(() -> sendNotification(notificationData));
- }
- }
+ list.stream()
+ .filter(NotificationData::isChanged)
+ .forEach(notificationData -> notificationExecutor.submit(() -> sendNotification(notificationData)));
}
}
@@ -321,24 +316,24 @@ public final class ConfigurationChangeNotifier {
/**
* The type Notification data.
*/
- class NotificationData {
+ static class NotificationData {
/**
* The Tenant.
*/
- String tenant;
+ final String tenant;
/**
* The Namespace.
*/
- String namespace;
+ final String namespace;
/**
* The Key.
*/
- String key;
+ final String key;
/**
* The Myself.
*/
- ConfigurationChangeListener myself;
+ final ConfigurationChangeListener myself;
/**
* The Current value.
*/
@@ -381,8 +376,17 @@ public final class ConfigurationChangeNotifier {
return false;
}
NotificationData nd = (NotificationData) obj;
- return tenant.equals(nd.tenant) && namespace.equals(nd.namespace) && key.equals(nd.key)
- && myself.equals(nd.myself);
+ return Objects.equals(tenant, nd.tenant)
+ && Objects.equals(namespace, nd.namespace)
+ && Objects.equals(key, nd.key)
+ && Objects.equals(myself, nd.myself)
+ && Objects.equals(currentValue, nd.currentValue) // it's either String or List<String>
+ && isArray == nd.isArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(tenant, namespace, key, myself, currentValue, isArray);
}
/**
@@ -424,7 +428,7 @@ public final class ConfigurationChangeNotifier {
Method method = null;
Vector<Object> parameters = null;
try {
- Object latestValue = null;
+ Object latestValue;
if (isArray) {
latestValue = ConfigurationManager.lookup().getAsStringValues(tenant, namespace, key);
} else {