?? cmpp3cell.java
字號(hào):
/*
* @(#)StoredCMPP3Submit.java 1.00 2007-12-5
*
* Copyright 2007 BCINFO. All Rights Reserved.
*/
package com.bci.commons.mmf.example;
import java.text.SimpleDateFormat;
import com.bci.cmpp.message.CMPPSubmit30;
import com.bci.commons.mmf.cell.AbstractCell;
import com.bci.commons.mmf.cell.MemoryMessageException;
import com.bci.commons.util.IOUtils;
/**
* 存儲(chǔ)CMPP3 Submit 消息的共享內(nèi)存結(jié)構(gòu)
*
* @author xuym
* @version 1.00, 2007-12-5
* @since JDK 1.5
*/
public class CMPP3Cell extends AbstractCell {
/**
* 消息單元長(zhǎng)度
*/
public static final int CELL_LENGTH = 381;
/**
* 內(nèi)部消息編號(hào) 與客戶(hù)端交互 遵循cmpp3中的msgid定義
*/
protected long interalId;
/**
* CMPP 2 Submit 消息
*/
protected CMPPSubmit30 message;
/**
* @return the interalId
*/
public long getInteralId() {
return interalId;
}
/**
* @param interalId
* the interalId to set
*/
public void setInteralId(long interalId) {
this.interalId = interalId;
}
/**
* @return the message
*/
public CMPPSubmit30 getMessage() {
return message;
}
/**
* @param message
* the message to set
*/
public void setMessage(CMPPSubmit30 message) {
this.message = message;
}
public CMPP3Cell() {
super();
this.setLength(CELL_LENGTH);
}
public CMPP3Cell(byte[] buf) throws MemoryMessageException {
this();
this.decode(buf, 0);
}
/*
* (non-Javadoc)
*
* @see com.bci.commons.mmf.cell.AbstractCell#encode()
*/
@Override
public byte[] encode() {
// TODO Auto-generated method stub
this.bytes = new byte[this.getLength()];
// used|inTime|opTime|status|interalId|cmppPacket
this.bytes[0] = used;
IOUtils.longToBytes(this.inTime, 8, this.bytes, 1);
IOUtils.longToBytes(this.opTime, 8, this.bytes, 9);
this.bytes[17] = status;
IOUtils.longToBytes(this.interalId, 8, this.bytes, 18);
System.arraycopy(message.getBytes(), 0, this.bytes, 26, message
.getTotalLength());
return this.bytes;
}
/*
* (non-Javadoc)
*
* @see com.bci.commons.mmf.cell.AbstractCell#decode(byte[], int)
*/
@Override
public void decode(byte[] buf, int offset) throws MemoryMessageException {
// TODO Auto-generated method stub
this.bytes = new byte[this.getLength()];
int len = buf.length - offset;
if (len > this.getLength())
len = this.getLength();
System.arraycopy(buf, offset, this.bytes, 0, len);
this.used = this.bytes[0];
this.inTime = IOUtils.bytesToLong(this.bytes, 1, 8);
this.opTime = IOUtils.bytesToLong(this.bytes, 9, 8);
this.status = this.bytes[17];
this.interalId = IOUtils.bytesToLong(this.bytes, 18, 8);
byte[] tmp = new byte[len - 26];
System.arraycopy(this.bytes, 26, tmp, 0, tmp.length);
try {
this.message = new CMPPSubmit30(tmp);
} catch (Exception e) {
throw new MemoryMessageException(e);
}
}
public String toString() {
SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
StringBuffer sb = new StringBuffer();
sb.append(datetime.format(getInTime())).append("\\s").append(
datetime.format(getOpTime())).append("\\s").append(getStatus())
.append("\\s").append(
com.bci.cmpp.util.CMPPIO.getMsgId(getInteralId()))
.append("\\s").append(message.toString());
return sb.toString();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -