⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmpp3cell.java

📁 java的共享内存管理.基于MMF设计。封装了java.nio.MappedByteBuffer.在大流量实时业务系统时
💻 JAVA
字号:
/*
 * @(#)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;

/**
 * 存储CMPP3 Submit 消息的共享内存结构
 * 
 * @author xuym
 * @version 1.00, 2007-12-5
 * @since JDK 1.5
 */
public class CMPP3Cell extends AbstractCell {

	/**
	 * 消息单元长度
	 */
	public static final int CELL_LENGTH = 381;

	/**
	 * 内部消息编号 与客户端交互 遵循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();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -