2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA 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.onap.pnfsimulator.netconfmonitor;
23 import com.tailf.jnc.JNCException;
24 import java.io.IOException;
25 import java.util.Timer;
26 import javax.annotation.PostConstruct;
27 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
28 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
29 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Service;
36 public class NetconfMonitorService {
37 private static final Logger LOGGER = LoggerFactory.getLogger(NetconfMonitorService.class);
38 private static final long timePeriod = 1000L;
39 private static final long startDelay = 0;
42 private NetconfConfigurationReader reader;
43 private NetconfConfigurationWriter writer;
44 private NetconfConfigurationCache cache;
47 public NetconfMonitorService(Timer timer,
48 NetconfConfigurationReader reader,
49 NetconfConfigurationWriter writer,
50 NetconfConfigurationCache cache) {
59 setStartConfiguration();
60 NetconfConfigurationCheckingTask task = new NetconfConfigurationCheckingTask(reader, writer, cache);
61 timer.scheduleAtFixedRate(task, startDelay, timePeriod);
64 private void setStartConfiguration() {
66 String configuration = reader.read();
67 writer.writeToFile(configuration);
68 cache.update(configuration);
69 } catch (IOException | JNCException e) {
70 LOGGER.warn("Error during configuration reading: {}", e.getMessage());