?? abstractmmf.java
字號:
/*
* @(#)AbatractMMF.java 1.00 2007-12-5
*
* Copyright 2007 BCINFO. All Rights Reserved.
*
* Programmer: Xuym.
*/
package com.bci.commons.mmf;
// import org.apache.log4j.Logger;
import java.util.Queue;
import java.util.Set;
import com.bci.commons.mmf.cell.AbstractCell;
/**
* 共享內(nèi)存管理類,繼承自MemoryMappedFile,增加定長cell劃分管理。
*
* @author xuym
* @version 1.00, 2007-12-5
* @since JDK 1.5
* @see java.nio.MappedByteBuffer
* @see com.bci.commons.mmf.MemoryMappedFile
*/
public abstract class AbstractMMF extends MemoryMappedFile {
/**
* Logger for this class
*/
// private static final Logger logger =
// Logger.getLogger(SharedMemory.class);
protected int cellLength;
/**
* 空閑節(jié)點(diǎn)隊列
*/
protected Queue<Integer> freeList = null;
/**
* 占用節(jié)點(diǎn)隊列
*/
protected Set<Integer> usedList = null;
/**
* 初始化內(nèi)存映象 應(yīng)用程序需要在這里生成占用節(jié)點(diǎn)隊列和空閑節(jié)點(diǎn)隊列
*
* @throws MemoryNotMappedException
* If the file not mapped into memory
* @throws MemoryReadException
* If some exception occurs when reading the memory.
*/
public abstract void initialize() throws MemoryNotMappedException,
MemoryReadException;
/**
* 在內(nèi)存映象中申請一個空閑的消息單元
*
* @throws MemoryNotMappedException
* If the file not mapped into memory
* @throws MemoryReadException
* If some exception occurs when reading the memory.
* @return the free cell's position. Returns -1 if request failure.
*/
public int request() throws MemoryNotMappedException, MemoryReadException {
if (freeList == null)
this.initialize();
if (freeList.size() <= 0)
return -1;
int ret = freeList.poll();
usedList.add(ret);
return ret;
}
/**
* 在內(nèi)存映象中釋放指定位置的消息單元 這里假設(shè)每個cell的第一個字節(jié)為是否占用的標(biāo)識
*
* @param pos
* the position of cell.
* @throws MemoryWriteException
* @throws MemoryNotMappedException
*/
public void release(int pos) throws MemoryNotMappedException,
MemoryWriteException {
this.write(pos, (byte) 0);
freeList.offer(pos);
}
/**
* 取在內(nèi)存中占用的節(jié)點(diǎn)集合
*
* @return A set of the positions
*/
public Set<Integer> getUsedList() {
if (usedList == null)
this.initialize();
return usedList;
}
/**
* 取在內(nèi)存中空閑的節(jié)點(diǎn)隊列
*
* @return A queue of the positions.
*/
public Queue<Integer> getFreeList() {
if (freeList == null)
this.initialize();
return freeList;
}
/**
* @return the cellLength
*/
public int getCellLength() {
return cellLength;
}
/**
* @param cellLength
* the cellLength to set
*/
public void setCellLength(int cellLength) {
this.cellLength = cellLength;
}
/**
* 重新設(shè)置整個cell數(shù)據(jù)
*
* @param pos
* The dest position of the memory map.
* @return The old value at the given position.
* @throws MemoryNotMappedException
* If the file not mapped into memory
* @throws MemoryReadException
* If some exception occurs when reading the memory.
*/
public abstract AbstractCell dumpAndReset(int pos);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -