1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package com.att.nsa.dmaap.filemonitor;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.lang.reflect.Method;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Properties;
32 import javax.annotation.PostConstruct;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
38 //import com.att.ssf.filemonitor.FileChangedListener;
39 //import com.att.ssf.filemonitor.FileMonitor;
42 * ServicePropertyService class
46 public class ServicePropertyService {
47 private boolean loadOnStartup;
48 private ServicePropertiesListener fileChangedListener;
49 private ServicePropertiesMap filePropertiesMap;
50 private String ssfFileMonitorPollingInterval;
51 private String ssfFileMonitorThreadpoolSize;
52 private List<File> fileList;
53 private static final String FILE_CHANGE_LISTENER_LOC = System
54 .getProperty("AJSC_CONF_HOME") + "/etc";
55 private static final String USER_CONFIG_FILE = "service-file-monitor.properties";
57 private static final EELFLogger logger = EELFManager.getInstance().getLogger(ServicePropertyService.class);
59 // do not remove the postConstruct annotation, init method will not be
60 // called after constructor
63 * @throws Exception ex
66 public void init() throws Exception {
69 getFileList(FILE_CHANGE_LISTENER_LOC);
71 // for (File file : fileList) {
72 // FileChangedListener fileChangedListener = this.fileChangedListener;
73 // Object filePropertiesMap = this.filePropertiesMap;
74 // Method m = filePropertiesMap.getClass().getMethod(
75 // "refresh", File.class);
76 // m.invoke(filePropertiesMap, file);
77 // FileMonitor fm = FileMonitor.getInstance();
78 // fm.addFileChangedListener(file, fileChangedListener,
82 } catch (Exception ex) {
83 logger.error("Error creating property map ", ex);
88 private void getFileList(String dirName) throws IOException {
89 File directory = new File(dirName);
90 FileInputStream fis = null;
93 fileList = new ArrayList<File>();
95 // get all the files that are ".json" or ".properties", from a directory
96 // & it's sub-directories
97 File[] fList = directory.listFiles();
99 for (File file : fList) {
100 // read service property files from the configuration file
101 if (file.isFile() && file.getPath().endsWith(USER_CONFIG_FILE)) {
103 fis = new FileInputStream(file);
104 Properties prop = new Properties();
107 for (String filePath : prop.stringPropertyNames()) {
108 fileList.add(new File(prop.getProperty(filePath)));
110 } catch (Exception ioe) {
111 logger.error("Error reading the file stream ", ioe);
115 } else if (file.isDirectory()) {
116 getFileList(file.getPath());
122 public void setLoadOnStartup(boolean loadOnStartup) {
123 this.loadOnStartup = loadOnStartup;
126 public void setSsfFileMonitorPollingInterval(
127 String ssfFileMonitorPollingInterval) {
128 this.ssfFileMonitorPollingInterval = ssfFileMonitorPollingInterval;
131 public void setSsfFileMonitorThreadpoolSize(
132 String ssfFileMonitorThreadpoolSize) {
133 this.ssfFileMonitorThreadpoolSize = ssfFileMonitorThreadpoolSize;
136 public boolean isLoadOnStartup() {
137 return loadOnStartup;
140 public String getSsfFileMonitorPollingInterval() {
141 return ssfFileMonitorPollingInterval;
144 public String getSsfFileMonitorThreadpoolSize() {
145 return ssfFileMonitorThreadpoolSize;
148 public ServicePropertiesListener getFileChangedListener() {
149 return fileChangedListener;
152 public void setFileChangedListener(
153 ServicePropertiesListener fileChangedListener) {
154 this.fileChangedListener = fileChangedListener;
157 public ServicePropertiesMap getFilePropertiesMap() {
158 return filePropertiesMap;
161 public void setFilePropertiesMap(ServicePropertiesMap filePropertiesMap) {
162 this.filePropertiesMap = filePropertiesMap;