fixing warnings from checkstyle in common-app-api
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / impl / ExternalConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.common.impl;
22
23 import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
24 import org.openecomp.sdc.common.api.ConfigurationSource;
25
26 import java.io.File;
27
28 /**
29  * Save the
30  *
31  * @author esofer
32  */
33 public class ExternalConfiguration {
34
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;
40
41     private static FilesystemAlterationMonitor fam = null;
42
43     private static ConfigFileChangeListener changeListener = new ConfigFileChangeListener();
44
45     private static boolean enableReconfigure = true;
46
47     public static String getAppName() {
48         return appName;
49     }
50
51     public static void setAppName(String appName) {
52         ExternalConfiguration.appName = appName;
53     }
54
55     public static String getAppVersion() {
56         return appVersion;
57     }
58
59     public static void setAppVersion(String appVersion) {
60         ExternalConfiguration.appVersion = appVersion;
61     }
62
63     public static String getConfigDir() {
64         return configDir;
65     }
66
67     public static void setConfigDir(String configDir) {
68         ExternalConfiguration.configDir = configDir;
69     }
70
71     public static ConfigurationSource getConfigurationSource() {
72         return configurationSource;
73     }
74
75     public static void setConfigurationSource(ConfigurationSource configurationSource) {
76         ExternalConfiguration.configurationSource = configurationSource;
77     }
78
79     public static ConfigFileChangeListener getChangeListener() {
80         return changeListener;
81     }
82
83     public static void listenForChanges() {
84
85         String watchingDir = configDir + File.separator + appName;
86         if (enableReconfigure) {
87             if (fam == null) {
88                 fam = new FilesystemAlterationMonitor();
89                 fam.setInterval(FILESYSTEM_MONITOR_INTERVAL);
90                 fam.addListener(new File(watchingDir), changeListener);
91                 fam.start();
92             }
93         }
94     }
95
96     public static void stopListenForFileChanges() {
97         if (enableReconfigure) {
98             if (fam != null) {
99                 fam.stop();
100                 fam = null;
101             }
102         }
103     }
104
105 }