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;
21 import java.util.List;
22 import java.util.concurrent.TimeUnit;
23 import java.util.function.Function;
25 import javax.annotation.PostConstruct;
27 import org.commscope.tr069adapter.vesagent.entity.DeviceDataEntity;
28 import org.commscope.tr069adapter.vesagent.repository.VesDataRepository;
29 import org.commscope.tr069adapter.vesagent.util.VesAgentConstants;
30 import org.commscope.tr069adapter.vesagent.util.VesAgentUtils;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
37 public class StartupTimerService {
38 private static final Logger logger = LoggerFactory.getLogger(StartupTimerService.class);
41 private Function<String, HeartBeatTimeoutTask> beanFactory;
43 public HeartBeatTimeoutTask getBeanInstance(String name) {
44 return beanFactory.apply(name);
48 VesDataRepository vesDataRepository;
51 ScheduleTaskService timerService;
54 public void initializeDeviceReachabilityCheckTimers() {
55 logger.debug("Initializing all device connectivity check timer tasks.");
56 List<DeviceDataEntity> deviceDataEntityList =
57 vesDataRepository.findByAttrGroup(VesAgentConstants.HEART_BEAT);
59 if (VesAgentUtils.isNullOrEmpty(deviceDataEntityList)) {
60 logger.debug("No device reachability check timer tasks exist.");
64 for (DeviceDataEntity deviceDataEntity : deviceDataEntityList) {
65 String heartBeatPeriod = null;
67 if (null != deviceDataEntity.getAttributesMap()) {
69 deviceDataEntity.getAttributesMap().get(VesAgentConstants.HEART_BEAT_PERIOD);
71 if (heartBeatPeriod == null) {
72 logger.info("Heartbeat is null");
75 if (!VesAgentUtils.isNullOrEmpty(heartBeatPeriod)
76 && !heartBeatPeriod.equals(VesAgentConstants.REMOVE_HEART_BEAT_TIMER_VAL)) {
77 logger.info("Creating device connectivity check timer tasks for device {}.",
78 deviceDataEntity.getDeviceId());
79 ScheduleInfo scheduleInfo = new ScheduleInfo();
80 scheduleInfo.setInterval(Integer.parseInt(heartBeatPeriod));
81 scheduleInfo.setTimeUnit(TimeUnit.SECONDS);
83 HeartBeatTimeoutTask callbackTask = getBeanInstance(deviceDataEntity.getDeviceId());
85 timerService.schedule(deviceDataEntity.getDeviceId(), scheduleInfo, callbackTask);