All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapdb.volume.ByteBufferMemoryVolSingle Maven / Gradle / Ivy

Go to download

MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap memory. It is a fast, scalable and easy to use embedded Java database.

There is a newer version: 3.1.0
Show newest version
package org.mapdb.volume;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;

/**
 * Created by jan on 3/13/16.
 */
public final class ByteBufferMemoryVolSingle extends ByteBufferVolSingle {

    protected final boolean useDirectBuffer;

    @Override
    public String toString() {
        return super.toString() + ",direct=" + useDirectBuffer;
    }

    public ByteBufferMemoryVolSingle(final boolean useDirectBuffer, final long maxSize, boolean cleanerHackEnabled) {
        super(false, maxSize, cleanerHackEnabled);
        this.useDirectBuffer = useDirectBuffer;
        this.buffer = useDirectBuffer ?
                ByteBuffer.allocateDirect((int) maxSize) :
                ByteBuffer.allocate((int) maxSize);
    }

    @Override
    public void truncate(long size) {
        //TODO truncate
    }

    @Override
    synchronized public void close() {
        if (closed)
            return;

        if (cleanerHackEnabled && buffer instanceof MappedByteBuffer) {
            ByteBufferVol.unmap((MappedByteBuffer) buffer);
        }
        buffer = null;
        closed = true;
    }

    @Override
    public void sync() {
    }

    @Override
    public long length() {
        return maxSize;
    }

    @Override
    public boolean isReadOnly() {
        return false;
    }

    @Override
    public File getFile() {
        return null;
    }

    @Override
    public boolean getFileLocked() {
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy