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.collector.alarm;
18 import java.io.UnsupportedEncodingException;
20 import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
25 public static short StartSign = (short)0xffff;
27 public final static String reqLoginAlarm = "reqLoginAlarm;user=%s;key=%s;type=%s";
29 public final static String reqHeartBeat = "reqHeartBeat;reqId=%s";
30 public final static String disconnectMsg = "closeConnAlarm";
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";
39 private MsgType msgType;
40 private int timeStamp = 0;
41 private int lenOfBody = 0;
42 private String body = null;
44 public Msg(String body,MsgType msgType ){
46 this.setMsgType(msgType);
49 public void newBodyfromBytes(byte b[]) throws UnsupportedEncodingException{
50 this.body = new String(b,Constant.ENCODING_UTF8);
52 public static int creatMsgTimeStamp(){
53 return (int)System.currentTimeMillis()/1000;
56 public int getBodyLenNow(){
57 return getBody().getBytes().length;
61 public void setTimeStamp(int timeStamp) {
62 this.timeStamp = timeStamp;
65 public int getTimeStamp() {
69 public void setLenOfBody(int lenOfBody) {
70 this.lenOfBody = lenOfBody;
73 public int getLenOfBody() {
77 public byte[] getBodyBytes() throws UnsupportedEncodingException {
78 return getBody().getBytes(Constant.ENCODING_UTF8);
81 public void setBody(String body) {
85 public String getBody() {
89 public void setMsgType(MsgType msgType) {
90 this.msgType = msgType;
93 public MsgType getMsgType() {
97 public String toString(boolean isRead){
98 StringBuilder sb = new StringBuilder();
99 sb.append("StartSign[").append(StartSign).append("]msgType[").append(msgType.value).append("]timeStamp[");
101 sb.append(timeStamp).append("]lenOfBody[").append(lenOfBody);
103 sb.append(creatMsgTimeStamp()).append("]lenOfBody[").append(getBodyLenNow());
105 sb.append("]body[").append(body).append("]");
106 return sb.toString();