2 * ============LICENSE_START========================================================================
3 * ONAP : tr-069-adapter
4 * =================================================================================================
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
6 * =================================================================================================
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9 * may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14 * either express or implied. See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ===============LICENSE_END=======================================================================
19 package org.commscope.tr069adapter.vesagent.timer;
\r
21 import java.util.List;
\r
22 import java.util.concurrent.TimeUnit;
\r
24 import org.commscope.tr069adapter.vesagent.VesConfiguration;
\r
25 import org.commscope.tr069adapter.vesagent.async.AsyncRequestHandler;
\r
26 import org.commscope.tr069adapter.vesagent.controller.HeartBeatMessageHandler;
\r
27 import org.commscope.tr069adapter.vesagent.entity.DeviceDataEntity;
\r
28 import org.commscope.tr069adapter.vesagent.repository.VesDataRepository;
\r
29 import org.commscope.tr069adapter.vesagent.util.VesAgentConstants;
\r
30 import org.commscope.tr069adapter.vesagent.util.VesAgentUtils;
\r
31 import org.slf4j.Logger;
\r
32 import org.slf4j.LoggerFactory;
\r
33 import org.springframework.beans.factory.annotation.Autowired;
\r
35 public class HeartBeatTimeoutTask implements Runnable {
\r
36 private static final Logger logger = LoggerFactory.getLogger(HeartBeatTimeoutTask.class);
\r
39 VesDataRepository vesDataRepository;
\r
42 ScheduleTaskService timerService;
\r
45 AsyncRequestHandler asyncHandler;
\r
48 HeartBeatMessageHandler heartBeatMessageHandler;
\r
51 VesConfiguration config;
\r
53 private String deviceId;
\r
57 logger.debug("Timer task: checking device {} connectivity.", deviceId);
\r
58 List<DeviceDataEntity> deviceDataEntityList =
\r
59 vesDataRepository.findByDeviceIdAndAttrGroup(deviceId, VesAgentConstants.HEART_BEAT);
\r
61 if (VesAgentUtils.isNullOrEmpty(deviceDataEntityList)
\r
62 || VesAgentUtils.isNullOrEmpty(deviceDataEntityList.get(0).getAttributesMap())) {
\r
63 timerService.cancelSchedule(deviceId);
\r
67 DeviceDataEntity deviceDataEntity = deviceDataEntityList.get(0);
\r
68 String heartBeatPeriod =
\r
69 deviceDataEntity.getAttributesMap().get(VesAgentConstants.HEART_BEAT_PERIOD);
\r
71 if (VesAgentUtils.isNullOrEmpty(heartBeatPeriod)
\r
72 || heartBeatPeriod.equals(VesAgentConstants.REMOVE_HEART_BEAT_TIMER_VAL)) {
\r
73 timerService.cancelSchedule(deviceId);
\r
77 ScheduleInfo scheduleInfo = new ScheduleInfo();
\r
78 scheduleInfo.setInterval(Integer.parseInt(heartBeatPeriod));
\r
79 scheduleInfo.setTimeUnit(TimeUnit.MINUTES);
\r
81 timerService.schedule(deviceId, scheduleInfo, this);
\r
83 asyncHandler.initiateDeviceReachabilityCheck(deviceDataEntity);
\r
86 public HeartBeatTimeoutTask(String deviceId) {
\r
88 this.deviceId = deviceId;
\r
91 public String getDeviceId() {
\r
95 public void setDeviceId(String deviceId) {
\r
96 this.deviceId = deviceId;
\r