1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. 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 distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.config;
21 import java.io.IOException;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile.ConfigurationException;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.AaiConfig;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.DcaeConfig;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.EsConfig;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.PmConfig;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.ToggleAlarmConfig;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.util.ConfigFileObserver;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class HtDevicemanagerConfiguration {
35 private static final long FILE_POLL_INTERVAL_MS = 1000;
37 private static final Logger LOG = LoggerFactory.getLogger(HtDevicemanagerConfiguration.class);
39 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
40 private static final String CONFIGURATIONTESTFILE = "test.properties"; // for
43 private static HtDevicemanagerConfiguration mObj;
44 private static HtDevicemanagerConfiguration mObjTest;
45 private static IniConfigurationFile mConfig;
46 private final ISubConfigHandler subconfigHandler = () -> mConfig.save();
48 private final ConfigFileObserver fileObserver;
51 private HtDevicemanagerConfiguration(String filename) {
54 this.mFile = new File(filename);
55 if (!this.mFile.exists()) {
56 if (!this.mFile.createNewFile()) {
57 LOG.error("Can not create file {}", filename);
60 if (mConfig == null) {
61 mConfig = new IniConfigurationFile(this.mFile);
65 } catch (ConfigurationException e) {
66 LOG.error("Problem loading config values: {}", e.getMessage());
67 } catch (IOException e) {
68 LOG.error("Problem loading config file {} : {}", filename, e.getMessage());
71 this.fileObserver = new ConfigFileObserver(filename, FILE_POLL_INTERVAL_MS, mConfig);
72 this.fileObserver.start();
76 public static HtDevicemanagerConfiguration getConfiguration() {
78 mObj = new HtDevicemanagerConfiguration(CONFIGURATIONFILE);
83 public static HtDevicemanagerConfiguration getTestConfiguration() {
84 return getTestConfiguration(CONFIGURATIONTESTFILE);
87 public static HtDevicemanagerConfiguration getTestConfiguration(final String filename) {
88 if (mObjTest == null) {
89 mObjTest = new HtDevicemanagerConfiguration(filename);
94 public IniConfigurationFile getMConfig() {
98 public void registerConfigChangedListener(IConfigChangedListener l) {
99 this.fileObserver.registerConfigChangedListener(l);
102 public void unregisterConfigChangedListener(IConfigChangedListener l) {
103 this.fileObserver.unregisterConfigChangedListener(l);
107 protected void finalize() throws Throwable {
108 if (this.fileObserver != null) {
109 this.fileObserver.interrupt();
114 public DcaeConfig getDcae() {
115 return DcaeConfig.getDcae(mConfig, this.subconfigHandler);
118 public AaiConfig getAai() {
119 return AaiConfig.getAai(mConfig, this.subconfigHandler);
122 public EsConfig getEs() {
123 return EsConfig.getEs(mConfig, this.subconfigHandler);
126 public PmConfig getPm() {
127 return PmConfig.getPm(mConfig, this.subconfigHandler);
130 public ToggleAlarmConfig getToggleAlarm() {
131 return ToggleAlarmConfig.getTa(mConfig, this.subconfigHandler);
134 public ISubConfigHandler getSubconfigHandler() {
135 return subconfigHandler;
138 public static void clear() {
145 ToggleAlarmConfig.clear();