📄 cmpp3submitmmf.java
字号:
/*
* @(#)CMPP3SubmitMap.java 1.00 2007-12-6
*
* Copyright 2007 BCINFO. All Rights Reserved.
*/
package com.bci.commons.mmf.example;
import org.apache.log4j.Logger;
import com.bci.commons.mmf.AbstractMMF;
import com.bci.commons.mmf.MemoryMapException;
import com.bci.commons.mmf.MemoryNotMappedException;
import com.bci.commons.mmf.MemoryReadException;
import java.util.TreeSet;
import java.util.concurrent.LinkedBlockingQueue;
/**
* CMPP 3.0提交消息的缓存
*
* @author xuym
* @version 1.00, 2007-12-6
* @since 1.5
*/
public class CMPP3SubmitMMF extends AbstractMMF {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(CMPP3SubmitMMF.class);
/**
* the map file's max length of data cell.
*/
private int cellCount = 0;
public CMPP3SubmitMMF() {
super();
}
public CMPP3SubmitMMF(String file, int _count) {
super();
load(file, _count);
}
/*
* (non-Javadoc)
*
* @see com.bci.commons.mmf.AbstractMMF#load(String, int)
*/
@Override
public void load(String file, int _count) throws MemoryMapException,
MemoryNotMappedException, MemoryReadException {
cellCount = _count;
super.load(file, cellCount * CMPP3Cell.CELL_LENGTH);
}
/*
* (non-Javadoc)
*
* @see com.bci.commons.mmf.AbstractMMF#initialize()
*/
@Override
public void initialize() throws MemoryNotMappedException,
MemoryReadException {
logger.debug("initializing the cmpp3 submit map...");
setCellLength(CMPP3Cell.CELL_LENGTH);
freeList = new LinkedBlockingQueue<Integer>();
usedList = new TreeSet<Integer>();
int pos = 0;
for (int i = 0; i < cellCount; i++) {
pos = i * CMPP3Cell.CELL_LENGTH;
byte b = readByte(pos);
if (b == 0) {
freeList.offer(pos);
} else {
usedList.add(pos);
}
}
logger.debug("this map has " + freeList.size() + " nodes.");
}
/*
* (non-Javadoc)
*
* @see com.bci.commons.mmf.AbstractMMF#read(int)
*/
@Override
public CMPP3Cell read(int desPos) throws MemoryMapException,
MemoryReadException {
try {
byte[] buf = readBytes(desPos, CMPP3Cell.CELL_LENGTH);
CMPP3Cell sSubmit = new CMPP3Cell(buf);
sSubmit.setPosition(desPos);
return sSubmit;
} catch (Exception e) {
throw new MemoryReadException(e);
}
}
/*
* (non-Javadoc)
*
* @see com.bci.commons.mmf.AbstractMMF#read(int)
*/
@Override
public CMPP3Cell dumpAndReset(int pos) {
CMPP3Cell cell = this.read(pos);
this.write(pos, new byte[CMPP3Cell.CELL_LENGTH]);
return cell;
}
public int getCellCount() {
return cellCount;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -