2 * Copyright 2020 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.jvnet.hk2.annotations.Service;
20 import org.onap.holmes.common.engine.entity.EngineEntity;
21 import org.onap.holmes.common.engine.service.EngineEntityService;
23 import javax.annotation.PostConstruct;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import java.util.List;
27 import java.util.Timer;
28 import java.util.TimerTask;
30 import static java.util.concurrent.TimeUnit.MINUTES;
31 import static java.util.concurrent.TimeUnit.SECONDS;
34 public class EngineInstanceController extends TimerTask {
35 private static final long INTERVAL = SECONDS.toMillis(15);
36 private static final long THRESHOLD = 3 * INTERVAL;
37 private Timer timer = new Timer("EngineInstanceController", true);
40 private EngineEntityService engineEntityService;
43 public void initialize() {
44 timer.schedule(this, MINUTES.toMillis(1), INTERVAL);
49 List<EngineEntity> entityList = engineEntityService.getAllEntities();
50 for (EngineEntity entity : entityList) {
51 if (System.currentTimeMillis() - entity.getLastModified() > THRESHOLD) {
52 engineEntityService.deleteEntity(entity.getId());