2 * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
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.vfc.nfvo.emsdriver.northbound.client;
18 import java.util.Properties;
20 import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
21 import org.onap.vfc.nfvo.emsdriver.commons.utils.DriverThread;
22 import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface;
23 import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannel;
24 import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannelFactory;
26 public class NorthMessageMgr extends DriverThread{
28 private MessageChannel alarmChannel = MessageChannelFactory.getMessageChannel(Constant.ALARM_CHANNEL_KEY);
29 private MessageChannel collectResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_CHANNEL_KEY);
30 private ConfigurationInterface configurationInterface ;
32 private boolean threadStop = false;
35 public void dispose() {
37 new AlarmMessageRecv().start();
39 new ResultMessageRecv().start();
43 class AlarmMessageRecv extends Thread{
44 long timeStamp = System.currentTimeMillis();
50 if(System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE){
51 timeStamp = System.currentTimeMillis();
53 log.debug("ALARM_CHANNEL Msg size :"+alarmChannel.size());
56 Object obj = alarmChannel.poll();
60 if(obj instanceof String){
62 Properties properties = configurationInterface.getProperties();
63 String msbAddress = properties.getProperty("msbAddress");
64 String url = properties.getProperty("alarm");
65 String postUrl = "http://"+msbAddress+url;
67 HttpClientUtil.doPost(postUrl, (String)obj, Constant.ENCODING_UTF8);
70 } catch (Exception e) {
71 log.error("AlarmMessageRecv exception",e);
77 class ResultMessageRecv extends Thread{
78 long timeStamp = System.currentTimeMillis();
84 if(System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE){
85 timeStamp = System.currentTimeMillis();
87 log.debug("COLLECT_RESULT_CHANNEL Msg size :"+collectResultChannel.size());
90 Object obj = collectResultChannel.poll();
94 if(obj instanceof String){
96 Properties properties = configurationInterface.getProperties();
97 String msbAddress = properties.getProperty("msbAddress");
98 String url = properties.getProperty("dataNotifyUrl");
99 String postUrl = "http://"+msbAddress+url;
100 HttpClientUtil.doPost(postUrl, (String)obj, Constant.ENCODING_UTF8);
103 } catch (Exception e) {
104 log.error("AlarmMessageRecv exception",e);
111 * @return the configurationInterface
113 public ConfigurationInterface getConfigurationInterface() {
114 return configurationInterface;
118 * @param configurationInterface the configurationInterface to set
120 public void setConfigurationInterface(
121 ConfigurationInterface configurationInterface) {
122 this.configurationInterface = configurationInterface;