2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.common.impl;
23 import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
24 import org.openecomp.sdc.common.api.ConfigurationSource;
33 public class ExternalConfiguration {
35 public static final int FILESYSTEM_MONITOR_INTERVAL = 1000;
36 private static String appName;
37 private static String appVersion;
38 private static String configDir;
39 private static ConfigurationSource configurationSource;
41 private static FilesystemAlterationMonitor fam = null;
43 private static ConfigFileChangeListener changeListener = new ConfigFileChangeListener();
45 private static boolean enableReconfigure = true;
47 public static String getAppName() {
51 public static void setAppName(String appName) {
52 ExternalConfiguration.appName = appName;
55 public static String getAppVersion() {
59 public static void setAppVersion(String appVersion) {
60 ExternalConfiguration.appVersion = appVersion;
63 public static String getConfigDir() {
67 public static void setConfigDir(String configDir) {
68 ExternalConfiguration.configDir = configDir;
71 public static ConfigurationSource getConfigurationSource() {
72 return configurationSource;
75 public static void setConfigurationSource(ConfigurationSource configurationSource) {
76 ExternalConfiguration.configurationSource = configurationSource;
79 public static ConfigFileChangeListener getChangeListener() {
80 return changeListener;
83 public static void listenForChanges() {
85 String watchingDir = configDir + File.separator + appName;
86 if (enableReconfigure) {
88 fam = new FilesystemAlterationMonitor();
89 fam.setInterval(FILESYSTEM_MONITOR_INTERVAL);
90 fam.addListener(new File(watchingDir), changeListener);
96 public static void stopListenForFileChanges() {
97 if (enableReconfigure) {