2 * Copyright 2017 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 lombok.extern.slf4j.Slf4j;
19 import org.glassfish.hk2.api.ServiceLocator;
20 import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
21 import org.onap.holmes.rulemgt.send.RuleAllocator;
22 import org.onap.holmes.rulemgt.send.Ip4AddingRule;
23 import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
25 import java.util.List;
26 import java.util.Timer;
27 import java.util.TimerTask;
31 public class MsbQuery {
33 private RuleAllocator ruleAllocator;
35 private Ip4AddingRule ip4AddingRule;
37 private EngineInsQueryTool engineInsQueryTool;
39 private RuleMgtWrapper ruleMgtWrapper;
41 private List<String> timerIpList;
44 ruleAllocator = new RuleAllocator();
46 ServiceLocator locator = ServiceLocatorHolder.getLocator();
47 ip4AddingRule = locator.getService(Ip4AddingRule.class);
48 engineInsQueryTool = locator.getService(EngineInsQueryTool.class);
49 ruleMgtWrapper = locator.getService(RuleMgtWrapper.class);
52 public void startTimer() {
55 } catch (Exception e) {
56 log.error("MSBQuery startTimer timer task failed !" + e.getMessage(), e);
59 } catch (InterruptedException e1) {
60 Thread.currentThread().interrupt();
67 public void timer() throws Exception {
68 Timer timer = new Timer();
69 timer.schedule(new TimerTask() {
73 timerIpList = engineInsQueryTool.getInstanceList();
74 log.info(String.format("There are %d engine instance(s) running currently.", timerIpList.size()));
76 ip4AddingRule.setIpList(timerIpList);
77 ruleAllocator.allocateRules(timerIpList);
78 } catch (Exception e) {
79 log.error("The timing query engine instance failed ", e);