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 org.onap.dmaap.filemonitor;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Properties;
32 import javax.annotation.PostConstruct;
35 * ServicePropertyService class
36 * @author rajashree.khare
39 public class ServicePropertyService {
40 private boolean loadOnStartup;
41 private ServicePropertiesListener fileChangedListener;
42 private ServicePropertiesMap filePropertiesMap;
43 private String ssfFileMonitorPollingInterval;
44 private String ssfFileMonitorThreadpoolSize;
45 private List<File> fileList;
46 private static final String FILE_CHANGE_LISTENER_LOC = System
47 .getProperty("AJSC_CONF_HOME") + "/etc";
48 private static final String USER_CONFIG_FILE = "service-file-monitor.properties";
50 private static final EELFLogger logger = EELFManager.getInstance().getLogger(ServicePropertyService.class);
52 // do not remove the postConstruct annotation, init method will not be
53 // called after constructor
56 * @throws Exception ex
62 getFileList(FILE_CHANGE_LISTENER_LOC);
64 } catch (Exception ex) {
65 logger.error("Error creating property map ", ex);
70 private void getFileList(String dirName) throws IOException {
71 File directory = new File(dirName);
74 fileList = new ArrayList<>();
76 // get all the files that are ".json" or ".properties", from a directory
77 // & it's sub-directories
78 File[] fList = directory.listFiles();
80 for (File file : fList) {
81 // read service property files from the configuration file
82 if (file.isFile() && file.getPath().endsWith(USER_CONFIG_FILE)) {
83 try(FileInputStream fis = new FileInputStream(file)) {
85 Properties prop = new Properties();
88 for (String filePath : prop.stringPropertyNames()) {
89 fileList.add(new File(prop.getProperty(filePath)));
91 } catch (Exception ioe) {
92 logger.error("Error reading the file stream ", ioe);
94 } else if (file.isDirectory()) {
95 getFileList(file.getPath());
101 public void setLoadOnStartup(boolean loadOnStartup) {
102 this.loadOnStartup = loadOnStartup;
105 public void setSsfFileMonitorPollingInterval(
106 String ssfFileMonitorPollingInterval) {
107 this.ssfFileMonitorPollingInterval = ssfFileMonitorPollingInterval;
110 public void setSsfFileMonitorThreadpoolSize(
111 String ssfFileMonitorThreadpoolSize) {
112 this.ssfFileMonitorThreadpoolSize = ssfFileMonitorThreadpoolSize;
115 public boolean isLoadOnStartup() {
116 return loadOnStartup;
119 public String getSsfFileMonitorPollingInterval() {
120 return ssfFileMonitorPollingInterval;
123 public String getSsfFileMonitorThreadpoolSize() {
124 return ssfFileMonitorThreadpoolSize;
127 public ServicePropertiesListener getFileChangedListener() {
128 return fileChangedListener;
131 public void setFileChangedListener(
132 ServicePropertiesListener fileChangedListener) {
133 this.fileChangedListener = fileChangedListener;
136 public ServicePropertiesMap getFilePropertiesMap() {
137 return filePropertiesMap;
140 public void setFilePropertiesMap(ServicePropertiesMap filePropertiesMap) {
141 this.filePropertiesMap = filePropertiesMap;