美文网首页
store模块阅读7:SelectMappedBufferRes

store模块阅读7:SelectMappedBufferRes

作者: 赤子心_d709 | 来源:发表于2017-10-16 11:24 被阅读46次

说明

这个类就是描述选取MappedFile中,一部分ByteBuffer 的结果
即提供随机读的操作

和MappedFile关系如下

和MappedFile关系

MappedFile在后面再讲

属性

    //开始位置,是绝对偏移,20位long型
    private final long startOffset;

    //对应的byteBuffer
    private final ByteBuffer byteBuffer;

    //对应的byteBuffer的大小
    private int size;

    //属于哪个mappedFile的一部分
    private MappedFile mappedFile;

方法

比较简单直接贴

    public SelectMappedBufferResult(long startOffset, ByteBuffer byteBuffer, int size, MappedFile mappedFile) {
        this.startOffset = startOffset;
        this.byteBuffer = byteBuffer;
        this.size = size;
        this.mappedFile = mappedFile;
    }

    public ByteBuffer getByteBuffer() {
        return byteBuffer;
    }

    public int getSize() {
        return size;
    }

    public void setSize(final int s) {
        this.size = s;
        this.byteBuffer.limit(this.size);
    }

    public MappedFile getMappedFile() {
        return mappedFile;
    }

//    @Override
//    protected void finalize() {
//        if (this.mappedFile != null) {
//            this.release();
//        }
//    }

    public synchronized void release() {//释放mappedFile引用
        if (this.mappedFile != null) {
            this.mappedFile.release();
            this.mappedFile = null;
        }
    }

    public long getStartOffset() {
        return startOffset;
    }

注意

setSize涉及buffer的处理
release是释放mappedFile引用,之后再讲

相关文章

网友评论

      本文标题:store模块阅读7:SelectMappedBufferRes

      本文链接:https://www.haomeiwen.com/subject/ldrkuxtx.html