2 * ============LICENSE_START=======================================================
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 org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
25 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
26 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Service;
30 import javax.annotation.PostConstruct;
31 import java.io.IOException;
32 import java.util.Timer;
35 public class NetconfMonitorService {
36 private static final long timePeriod = 1000L;
37 private static final long startDelay = 0;
40 private NetconfConfigurationReader reader;
41 private NetconfConfigurationWriter writer;
42 private NetconfConfigurationCache cache;
45 public NetconfMonitorService(Timer timer,
46 NetconfConfigurationReader reader,
47 NetconfConfigurationWriter writer,
48 NetconfConfigurationCache cache) {
56 public void start() throws IOException, JNCException {
57 setStartConfiguration();
58 NetconfConfigurationCheckingTask task = new NetconfConfigurationCheckingTask(reader, writer, cache);
59 timer.scheduleAtFixedRate(task, startDelay, timePeriod);
62 private void setStartConfiguration() throws IOException, JNCException {
63 String configuration = reader.read();
64 writer.writeToFile(configuration);
65 cache.update(configuration);