2 * Copyright 2017-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.
16 package org.onap.holmes.rulemgt.msb;
18 import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
19 import org.onap.holmes.rulemgt.send.Ip4AddingRule;
20 import org.onap.holmes.rulemgt.send.RuleAllocator;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import java.util.List;
25 import java.util.Timer;
26 import java.util.TimerTask;
28 import static java.util.concurrent.TimeUnit.SECONDS;
30 public class MsbQuery {
32 static final private Logger log = LoggerFactory.getLogger(MsbQuery.class);
33 final private RuleAllocator ruleAllocator;
34 private Ip4AddingRule ip4AddingRule;
35 private EngineInsQueryTool engineInsQueryTool;
38 ruleAllocator = new RuleAllocator();
39 ip4AddingRule = ServiceLocatorHolder.getLocator().getService(Ip4AddingRule.class);
40 engineInsQueryTool = ServiceLocatorHolder.getLocator().getService(EngineInsQueryTool.class);
43 public void startTimer() {
45 new Timer().schedule(new TimerTask() {
49 List<String> timerIpList = engineInsQueryTool.getInstanceList();
50 log.info(String.format("There are %d engine instance(s) running currently.", timerIpList.size()));
52 ip4AddingRule.setIpList(timerIpList);
53 ruleAllocator.allocateRules(timerIpList);
54 } catch (Exception e) {
55 log.error("The timing query engine instance failed ", e);
59 }, SECONDS.toMillis(10), SECONDS.toMillis(30));
60 } catch (Exception e) {
61 log.error("MSBQuery startTimer timer task failed !" + e.getMessage(), e);
64 } catch (InterruptedException e1) {
65 Thread.currentThread().interrupt();