Modify groupId for ems driver
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / nfvo / emsdriver / collector / alarm / Msg.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.nfvo.emsdriver.collector.alarm;
17
18 import java.io.UnsupportedEncodingException;
19
20 import org.onap.nfvo.emsdriver.commons.constant.Constant;
21
22
23 public class Msg {
24
25         public static short StartSign = (short)0xffff;
26         
27         public final static String reqLoginAlarm = "reqLoginAlarm;user=%s;key=%s;type=%s";
28         
29         public final static String reqHeartBeat = "reqHeartBeat;reqId=%s";
30         public final static String disconnectMsg = "closeConnAlarm";
31         
32         public final static String syncAlarmMessageMsg = "reqSyncAlarmMsg;reqID=%s;alarmSeq=%s";
33         public final static String syncAlarmMessageByalarmSeq = "reqSyncAlarmFile;reqID=%s;alarmSeq=%s;syncSource=1";
34         public final static String syncActiveAlarmFileMsg = "reqSyncAlarmFile;reqID=%s;startTime=%s;endTime=%s;syncSource=0";
35         public final static String syncAlarmFileMsg = "reqSyncAlarmFile;reqID=%s;startTime=%s;endTime=%s;syncSource=1";
36         
37         
38         
39         private MsgType msgType;
40         private int timeStamp = 0;
41         private int lenOfBody = 0;
42         private String body = null;
43         public Msg(){}
44         public Msg(String body,MsgType msgType ){
45                 this.body = body;
46                 this.setMsgType(msgType);
47         }
48         
49         public void newBodyfromBytes(byte b[]) throws UnsupportedEncodingException{
50                 this.body = new String(b,Constant.ENCODING_UTF8);
51         }
52         public static int creatMsgTimeStamp(){
53                 return (int)System.currentTimeMillis()/1000;
54         }
55         
56         public int getBodyLenNow(){
57                 return getBody().getBytes().length;
58         } 
59         
60
61         public void setTimeStamp(int timeStamp) {
62                 this.timeStamp = timeStamp;
63         }
64
65         public int getTimeStamp() {
66                 return timeStamp;
67         }
68
69         public void setLenOfBody(int lenOfBody) {
70                 this.lenOfBody = lenOfBody;
71         }
72         
73         public int getLenOfBody() {
74                 return lenOfBody;
75         }
76
77         public byte[] getBodyBytes() throws UnsupportedEncodingException {
78                 return getBody().getBytes(Constant.ENCODING_UTF8);
79         }
80
81         public void setBody(String body) {
82                 this.body = body;
83         }
84
85         public String getBody() {
86                 return body;
87         }
88
89         public void setMsgType(MsgType msgType) {
90                 this.msgType = msgType;
91         }
92
93         public MsgType getMsgType() {
94                 return msgType;
95         }
96         
97         public String toString(boolean isRead){
98                 StringBuilder sb = new StringBuilder();
99                 sb.append("StartSign[").append(StartSign).append("]msgType[").append(msgType.value).append("]timeStamp[");
100                 if(isRead){
101                         sb.append(timeStamp).append("]lenOfBody[").append(lenOfBody);
102                 }else{
103                         sb.append(creatMsgTimeStamp()).append("]lenOfBody[").append(getBodyLenNow());
104                 }
105                 sb.append("]body[").append(body).append("]");
106                 return sb.toString();
107         }
108 }