Modify package structure and pom file
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / vfc / nfvo / emsdriver / northbound / client / NorthMessageMgr.java
1 /**
2  * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.vfc.nfvo.emsdriver.northbound.client;
17
18 import java.util.Properties;
19
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;
25
26 public class NorthMessageMgr extends DriverThread{
27
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 ;
31         
32         private boolean threadStop = false;
33         
34         @Override
35         public void dispose() {
36                 //
37                 new AlarmMessageRecv().start();
38                 
39                 new ResultMessageRecv().start();
40         }
41         
42         
43         class AlarmMessageRecv extends Thread{
44                 long timeStamp = System.currentTimeMillis();
45                 
46                 public void run() {
47                         while(!threadStop){
48                                 
49                                 try {
50                                         if(System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE){
51                                                 timeStamp = System.currentTimeMillis();
52                                                 
53                                                 log.debug("ALARM_CHANNEL Msg size :"+alarmChannel.size());
54                                         }
55                                         
56                                         Object obj = alarmChannel.poll();
57                                         if(obj == null){
58                                                 continue;
59                                         }
60                                         if(obj instanceof String){
61                                                 //http
62                                                 Properties properties = configurationInterface.getProperties();
63                                                 String msbAddress = properties.getProperty("msbAddress");
64                                                 String url = properties.getProperty("alarm");
65                                                 String postUrl = "http://"+msbAddress+url;
66                                                 
67                                                 HttpClientUtil.doPost(postUrl, (String)obj, Constant.ENCODING_UTF8);
68                                         }
69                                         
70                                 } catch (Exception e) {
71                                         log.error("AlarmMessageRecv exception",e);
72                                 }
73                         }
74                 }
75         }
76
77         class ResultMessageRecv extends Thread{
78                 long timeStamp = System.currentTimeMillis();
79                 
80                 public void run() {
81                         while(!threadStop){
82                                 
83                                 try {
84                                         if(System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE){
85                                                 timeStamp = System.currentTimeMillis();
86                                                 
87                                                 log.debug("COLLECT_RESULT_CHANNEL Msg size :"+collectResultChannel.size());
88                                         }
89                                         
90                                         Object obj = collectResultChannel.poll();
91                                         if(obj == null){
92                                                 continue;
93                                         }
94                                         if(obj instanceof String){
95                                                 //http
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);
101                                         }
102                                         
103                                 } catch (Exception e) {
104                                         log.error("AlarmMessageRecv exception",e);
105                                 }
106                         }
107                 }
108         }
109
110         /**
111          * @return the configurationInterface
112          */
113         public ConfigurationInterface getConfigurationInterface() {
114                 return configurationInterface;
115         }
116
117         /**
118          * @param configurationInterface the configurationInterface to set
119          */
120         public void setConfigurationInterface(
121                         ConfigurationInterface configurationInterface) {
122                 this.configurationInterface = configurationInterface;
123         }
124         
125 }