亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? memorymappedfile.java

?? java的共享內存管理.基于MMF設計。封裝了java.nio.MappedByteBuffer.在大流量實時業務系統時
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * @(#)MemoryMappedFile.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.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.bci.commons.mmf.cell.AbstractCell;
import com.bci.commons.util.IOUtils;

/**
 * 共享內存讀寫類,對java.nio.MappedByteBuffer封裝,提供簡單的讀寫操作。
 * 采用java.util.concurrent.locks.Lock加鎖機制支持多線程安全。
 * 
 * @author xuym
 * @version 1.00, 2007-12-5
 * @since JDK 1.5
 * @see java.nio.MappedByteBuffer
 */

public abstract class MemoryMappedFile {
	/**
	 * Logger for this class
	 */
	// private static final Logger logger =
	// Logger.getLogger(SharedMemory.class);
	protected MappedByteBuffer mapBuf = null;

	protected String file = null;

	protected long capacity;

	protected ReadWriteLock lock = new ReentrantReadWriteLock();

	protected Lock readLock = lock.readLock();

	protected Lock writeLock = lock.writeLock();

	/**
	 * Load the map file into memory.
	 * 
	 * @param file
	 *            The file name to be load.
	 * @param size
	 *            The file's size or the max map size.
	 * @throws MemoryMapException
	 *             If some exception occurs when loading the file
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryReadException
	 *             If some exception occurs when reading the memory.
	 */
	public void load(String file, int size) throws MemoryMapException,
			MemoryNotMappedException, MemoryReadException {
		this.file = file;
		this.capacity = size;
		// logger.debug("loading the file " + this.file + " into memory...");
		try {
			RandomAccessFile RAFile = new RandomAccessFile(this.file, "rw");
			FileChannel fc = RAFile.getChannel();
			mapBuf = fc.map(FileChannel.MapMode.READ_WRITE, 0, size);
			mapBuf.load();
			fc.close();
			RAFile.close();
		} catch (FileNotFoundException e) {
			throw new MemoryMapException(e);
		} catch (IOException e) {
			throw new MemoryMapException(e);
		}
	}

	/**
	 * 在內存映象的指定位置寫入對象
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @param message
	 *            The message object.
	 * @return The boolean value if successed.
	 * @see com.bci.commons.mmf.cell.AbstractCell
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryWriteException
	 *             If some exception occurs when write the object.
	 */
	public MemoryMappedFile write(int desPos, AbstractCell message)
			throws MemoryNotMappedException, MemoryWriteException {
		if (message == null)
			throw new MemoryWriteException("The input object is null.");

		return write(desPos, message.getBytes());
	}

	/**
	 * 在內存映象的指定位置寫入字節數組
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @param buf
	 *            The byte array to be writen.
	 * @return The boolean value if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryWriteException
	 *             If some exception occurs when write the object.
	 */
	public MemoryMappedFile write(int desPos, byte[] buf)
			throws MemoryNotMappedException, MemoryWriteException {
		if (buf == null)
			throw new MemoryWriteException("The input data is null.");

		return write(desPos, buf, 0, buf.length);
	}

	/**
	 * 在內存映象的指定位置寫入字節數組
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @param buf
	 *            The byte array to be writen.
	 * @param srcPos
	 *            The start position of the source byte array.
	 * @param len
	 *            The bytes length.
	 * @return The boolean value if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryWriteException
	 *             If some exception occurs when write the object.
	 */
	public MemoryMappedFile write(int desPos, byte[] buf, int srcPos, int len)
			throws MemoryNotMappedException, MemoryWriteException {
		if (buf == null)
			throw new MemoryWriteException("the input data is null.");
		if (mapBuf == null)
			throw new MemoryNotMappedException(
					"the file not mapped into memory.");
		if (desPos < 0)
			throw new MemoryWriteException("the memory map is underflow.");
		if (desPos >= this.capacity - len)
			throw new MemoryWriteException("the memory map is overflow.");
		writeLock.lock();
		try {
			// logger.debug(Thread.currentThread().getId() + ".writing...pos:"
			// + desPos + ",data:" + com.bci.imas.util.IOUtils.encodeHex(buf));
			mapBuf.position(desPos);
			mapBuf.put(buf, srcPos, len);
			// mapBuf.force();
		} finally {
			writeLock.unlock();
		}
		return this;
	}

	/**
	 * 在內存映象的指定位置寫入一個字節
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @param b
	 *            The byte value to be writen.
	 * @return The boolean value if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryWriteException
	 *             If some exception occurs when write the object.
	 */
	public MemoryMappedFile write(int desPos, byte b)
			throws MemoryNotMappedException, MemoryWriteException {
		if (mapBuf == null)
			throw new MemoryNotMappedException(
					"the file not mapped into memory.");
		if (desPos < 0)
			throw new MemoryWriteException("the memory map is underflow.");
		if (desPos >= this.capacity)
			throw new MemoryWriteException("the memory map is overflow.");
		writeLock.lock();
		try {
			mapBuf.position(desPos);
			mapBuf.put(b);
			// mapBuf.force();
		} finally {
			writeLock.unlock();
		}
		return this;
	}

	/**
	 * 在內存映象的指定位置寫入一個整數
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @param i
	 *            The integer number to be writen.
	 * @param len
	 *            The integer's byte length.
	 * @return The boolean value if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryWriteException
	 *             If some exception occurs when write the object.
	 */
	public MemoryMappedFile write(int desPos, int i, int len)
			throws MemoryNotMappedException, MemoryWriteException {
		if (mapBuf == null)
			throw new MemoryNotMappedException(
					"the file not mapped into memory.");
		if (desPos < 0)
			throw new MemoryWriteException("the memory map is underflow.");
		if (desPos >= this.capacity - len)
			throw new MemoryWriteException("the memory map is overflow.");
		writeLock.lock();
		try {
			mapBuf.position(desPos);
			byte[] buf = new byte[len];
			buf = IOUtils.intToBytes(i, len);
			// logger.debug(Thread.currentThread().getId() + ".writing...pos:"
			// + desPos + ",data:" + com.bci.imas.util.IOUtils.encodeHex(buf));
			mapBuf.put(buf);
			// mapBuf.force();
		} finally {
			writeLock.unlock();
		}
		return this;
	}

	/**
	 * 在內存映象的指定位置寫入一個長整數
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @param value
	 *            The long number to be writen.
	 * @param len
	 *            The long number's byte length.
	 * @return The boolean value if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryWriteException
	 *             If some exception occurs when write the object.
	 */
	public MemoryMappedFile write(int desPos, long value, int len)
			throws MemoryNotMappedException, MemoryWriteException {
		if (mapBuf == null)
			throw new MemoryNotMappedException(
					"the file not mapped into memory.");
		if (desPos < 0)
			throw new MemoryWriteException("the memory map is underflow.");
		if (desPos >= this.capacity - len)
			throw new MemoryWriteException("the memory map is overflow.");
		writeLock.lock();
		try {
			mapBuf.position(desPos);
			byte[] buf = new byte[len];
			buf = IOUtils.longToBytes(value, len);
			// logger.debug(Thread.currentThread().getId() + ".writing...pos:"
			// + desPos + ",data:" + com.bci.imas.util.IOUtils.encodeHex(buf));
			mapBuf.put(buf);
			// mapBuf.force();
		} finally {
			writeLock.unlock();
		}
		return this;

	}

	/**
	 * 在內存映象的指定位置寫入一個字符串
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @param s
	 *            The string to be writen.
	 * @return The boolean value if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryWriteException
	 *             If some exception occurs when writting the data
	 */
	public MemoryMappedFile write(int desPos, String s)
			throws MemoryWriteException, MemoryNotMappedException {
		if (s == null)
			throw new MemoryWriteException("the input data is null.");

		if (mapBuf == null)
			throw new MemoryNotMappedException(
					"the file not mapped into memory.");
		if (desPos < 0)
			throw new MemoryWriteException("the memory map is underflow.");
		if (desPos >= this.capacity - s.length())
			throw new MemoryWriteException("the memory map is overflow.");
		writeLock.lock();
		try {
			mapBuf.position(desPos);
			byte[] buf = s.getBytes();
			// logger.debug(Thread.currentThread().getId() + ".writing...pos:"
			// + desPos + ",data:" + com.bci.imas.util.IOUtils.encodeHex(buf));
			mapBuf.put(buf);
			// mapBuf.force();
		} finally {
			writeLock.unlock();
		}
		return this;
	}

	/**
	 * 從內存映象的指定位置讀取對象
	 * 
	 * @param desPos
	 *            The dest position of the memory map.
	 * @return The StoredMessage object.
	 * @see com.bci.commons.mmf.cell.AbstractCell
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryReadException
	 *             If some exception occurs when reading the memory.
	 */
	public abstract AbstractCell read(int desPos) throws MemoryMapException,
			MemoryReadException;

	/**
	 * 在內存映象的指定位置讀取一個字節數據
	 * 
	 * @param pos
	 *            The dest position of the memory map.
	 * @return The byte value if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryReadException
	 *             If some exception occurs when reading the memory.
	 */
	public byte readByte(int pos) throws MemoryNotMappedException,
			MemoryReadException {
		if (mapBuf == null)
			throw new MemoryNotMappedException(
					"the file not mapped into memory.");
		if (pos < 0)
			throw new MemoryReadException("the memory map is underflow.");
		if (pos > this.capacity - 1)
			throw new MemoryReadException("the memory map is overflow.");
		readLock.lock();
		try {
			mapBuf.position(pos);
			return mapBuf.get();
		} finally {
			readLock.unlock();
		}
	}

	/**
	 * 在內存映象的指定位置讀取一個短整數
	 * 
	 * @param pos
	 *            The dest position of the memory map.
	 * @return The short nubmer if successed.
	 * @throws MemoryNotMappedException
	 *             If the file not mapped into memory
	 * @throws MemoryReadException
	 *             If some exception occurs when reading the memory.
	 */
	public short readShort(int pos) throws MemoryNotMappedException,
			MemoryReadException {
		if (mapBuf == null)
			throw new MemoryNotMappedException(
					"the file not mapped into memory.");
		if (pos < 0)
			throw new MemoryReadException("the memory map is underflow.");
		if (pos > this.capacity - 2)
			throw new MemoryReadException("the memory map is overflow.");
		readLock.lock();
		try {
			mapBuf.position(pos);
			return mapBuf.getShort();
		} finally {
			readLock.unlock();
		}
	}

	/**
	 * 在內存映象的指定位置讀取一個整數
	 * 
	 * @param pos
	 *            The dest position of the memory map.
	 * @return The integer nubmer if successed.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产视频一区二区在线观看| 91久久免费观看| 99riav一区二区三区| 欧美日韩国产首页| 亚洲色图制服诱惑 | 男女视频一区二区| 色综合亚洲欧洲| 久久久噜噜噜久噜久久综合| 一区二区三国产精华液| 国产91富婆露脸刺激对白| 在线成人免费观看| 一区二区视频在线| 成人久久18免费网站麻豆 | 国内精品国产成人国产三级粉色| 色播五月激情综合网| 国产清纯美女被跳蛋高潮一区二区久久w | 欧美成人猛片aaaaaaa| 亚洲精品五月天| 99久久精品免费看国产免费软件| 亚洲精品在线观看网站| 免费成人在线网站| 91精品欧美福利在线观看| 亚洲自拍偷拍图区| 99国产精品国产精品毛片| 国产精品国产三级国产三级人妇 | 欧美少妇bbb| 一区二区三区免费网站| av激情成人网| 日韩美女啊v在线免费观看| 成人免费观看视频| 亚洲国产精品v| 国产mv日韩mv欧美| 欧美韩国一区二区| 成人免费毛片片v| 国产精品久久久久影院| 97久久精品人人做人人爽| 国产精品传媒视频| 色综合久久综合| 亚洲精品大片www| 欧美日韩精品欧美日韩精品| 亚洲www啪成人一区二区麻豆| 欧美午夜电影一区| 奇米精品一区二区三区四区| 日韩欧美123| 国产麻豆91精品| 中文字幕日韩欧美一区二区三区| 99久久精品情趣| 亚洲bdsm女犯bdsm网站| 91精品国产综合久久国产大片| 日本va欧美va瓶| xnxx国产精品| 91亚洲国产成人精品一区二三| 亚洲永久精品国产| 日韩你懂的电影在线观看| 九一久久久久久| 国产精品久久久久一区| 欧美午夜精品久久久久久超碰| 日日夜夜免费精品| 久久这里只有精品首页| 不卡欧美aaaaa| 天天综合网天天综合色| 久久免费美女视频| 在线观看视频一区二区| 精品系列免费在线观看| 中文字幕一区二区三区蜜月| 欧美人成免费网站| 国产91精品在线观看| 亚洲一区成人在线| 久久久蜜桃精品| 欧美日韩一区二区不卡| 国产美女精品人人做人人爽| 亚洲精品亚洲人成人网在线播放| 日韩精品最新网址| 91麻豆免费视频| 国产一区二区在线影院| 亚洲午夜一二三区视频| 国产婷婷一区二区| 91精品在线观看入口| 91丨porny丨户外露出| 国产一区二区免费视频| 亚洲精品视频在线观看网站| 精品国产乱码久久| 欧美精品久久天天躁| 成人免费看片app下载| 青娱乐精品在线视频| 一区二区不卡在线播放| 国产色婷婷亚洲99精品小说| 日韩午夜激情免费电影| 欧美色倩网站大全免费| 94-欧美-setu| 国产激情91久久精品导航| 青青草91视频| 亚洲第一精品在线| 亚洲免费资源在线播放| 中文字幕精品三区| 久久久久成人黄色影片| 欧美v日韩v国产v| 69久久99精品久久久久婷婷 | 丁香婷婷深情五月亚洲| 奇米影视一区二区三区小说| 一二三区精品视频| 国产精品免费久久| 国产亚洲欧美中文| 久久久久久麻豆| 欧美成人免费网站| 精品久久久久久亚洲综合网| 制服丝袜亚洲精品中文字幕| 成人av综合在线| 国产精品亚洲视频| 国产资源精品在线观看| 久久电影网站中文字幕| 日本美女一区二区三区视频| 亚洲成av人片一区二区梦乃| 香蕉久久一区二区不卡无毒影院| 亚洲一区中文在线| 亚洲成a人v欧美综合天堂下载 | av在线不卡网| 不卡av在线免费观看| 不卡的av网站| 成人动漫中文字幕| av一区二区三区| 91免费版在线| 欧美羞羞免费网站| 3d动漫精品啪啪1区2区免费| 日韩一区和二区| 欧美精品一区二区三区四区 | 午夜亚洲国产au精品一区二区| 亚洲综合精品久久| 免费看精品久久片| 国产一区不卡精品| heyzo一本久久综合| 在线观看视频一区二区欧美日韩| 欧美日韩午夜在线视频| 欧美伊人久久大香线蕉综合69| 欧美美女直播网站| 亚洲精品在线免费播放| 国产精品电影一区二区| 亚洲国产成人tv| 国产精品自在在线| 日本黄色一区二区| 日韩欧美的一区二区| 国产精品久久久久久久裸模| 亚洲天堂中文字幕| 视频一区二区欧美| 成人高清视频免费观看| 欧美日韩国产欧美日美国产精品| 精品剧情v国产在线观看在线| 欧美国产精品中文字幕| 国产高清精品久久久久| 99re热这里只有精品免费视频| 在线欧美日韩国产| 精品国产免费视频| 一区二区三区视频在线观看| 日韩不卡一二三区| www.亚洲在线| 日韩免费性生活视频播放| 1024成人网色www| 蜜桃视频一区二区三区| av日韩在线网站| 26uuu色噜噜精品一区二区| 日韩美女啊v在线免费观看| 精品一区二区在线播放| 在线观看免费成人| 国产精品三级av| 激情小说亚洲一区| 欧美网站大全在线观看| 国产人成一区二区三区影院| 男男视频亚洲欧美| 欧美性感一区二区三区| 国产欧美视频一区二区三区| 日韩国产一二三区| 在线观看91视频| 国产精品美女久久久久久2018| 蜜臀va亚洲va欧美va天堂| 欧美中文字幕一二三区视频| 国产精品丝袜在线| 国产主播一区二区三区| 91麻豆精品国产91久久久久久久久| 亚洲欧美日韩在线| 成人一区二区三区视频在线观看 | 国产一本一道久久香蕉| 日韩欧美在线影院| 五月激情综合婷婷| 欧美午夜不卡在线观看免费| 久久99国产精品免费网站| 欧美做爰猛烈大尺度电影无法无天| 久久久久88色偷偷免费| 日本美女一区二区三区视频| 欧美性感一类影片在线播放| 国产精品福利影院| 成人妖精视频yjsp地址| 26uuu色噜噜精品一区| 精品一区二区三区影院在线午夜| 欧美二区三区91| 亚洲精品国产一区二区精华液| 成人av免费网站| 国产精品久久影院| 97久久人人超碰| 国产拍欧美日韩视频二区| 国产成人在线观看|