2 * Copyright 2020-2021 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.holmes.rulemgt.controller;
19 import org.onap.holmes.common.engine.entity.EngineEntity;
20 import org.onap.holmes.common.engine.service.EngineEntityService;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Service;
24 import javax.annotation.PostConstruct;
25 import java.util.List;
26 import java.util.Timer;
27 import java.util.TimerTask;
29 import static java.util.concurrent.TimeUnit.MINUTES;
30 import static java.util.concurrent.TimeUnit.SECONDS;
33 public class EngineInstanceController extends TimerTask {
34 private static final long INTERVAL = SECONDS.toMillis(15);
35 private static final long THRESHOLD = 3 * INTERVAL;
36 private Timer timer = new Timer("EngineInstanceController", true);
39 private EngineEntityService engineEntityService;
42 public void initialize() {
43 timer.schedule(this, MINUTES.toMillis(1), INTERVAL);
48 List<EngineEntity> entityList = engineEntityService.getAllEntities();
49 for (EngineEntity entity : entityList) {
50 if (System.currentTimeMillis() - entity.getLastModified() > THRESHOLD) {
51 engineEntityService.deleteEntity(entity.getId());