Package org.h2.store.fs.niomem
Class FileNioMemData
- java.lang.Object
-
- org.h2.store.fs.niomem.FileNioMemData
-
class FileNioMemData extends java.lang.ObjectThis class contains the data of an in-memory random access file. Data compression using the LZF algorithm is supported as well.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classFileNioMemData.CompressItemRepresents a compressed item.(package private) static classFileNioMemData.CompressLaterCache<K,V>This small cache compresses the data if an element leaves the cache.
-
Field Summary
Fields Modifier and Type Field Description private static intBLOCK_SIZEprivate static intBLOCK_SIZE_MASKprivate static intBLOCK_SIZE_SHIFTprivate java.util.concurrent.atomic.AtomicReference<java.nio.ByteBuffer>[]buffersprivate static intCACHE_MIN_SIZEprivate booleancompressprivate static java.lang.ThreadLocal<byte[]>COMPRESS_OUT_BUF_THREAD_LOCALthe output buffer when compressingprivate static java.nio.ByteBufferCOMPRESSED_EMPTY_BLOCKprivate FileNioMemData.CompressLaterCache<FileNioMemData.CompressItem,FileNioMemData.CompressItem>compressLaterCacheprivate floatcompressLaterCachePercentprivate booleanisLockedExclusiveprivate booleanisReadOnlyprivate longlastModifiedprivate longlengthprivate static java.lang.ThreadLocal<CompressLZF>LZF_THREAD_LOCALprivate java.lang.Stringname(package private) intnameHashCodeThe hash code of the name.private java.util.concurrent.locks.ReentrantReadWriteLockrwLockprivate intsharedLockCount
-
Constructor Summary
Constructors Constructor Description FileNioMemData(java.lang.String name, boolean compress, float compressLaterCachePercent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddToCompressLaterCache(int page)(package private) booleancanWrite()Check whether writing is allowed.private voidchangeLength(long len)(package private) voidcompressPage(int page)Compress the data in a byte array.private java.nio.ByteBufferexpandPage(int page)(package private) longgetLastModified()Get the last modified time.(package private) java.lang.StringgetName()Get the file name(package private) longlength()Get the file length.(package private) booleanlockExclusive()Lock the file in exclusive mode if possible.(package private) booleanlockShared()Lock the file in shared mode if possible.(package private) longreadWrite(long pos, java.nio.ByteBuffer b, int off, int len, boolean write)Read or write.(package private) voidsetName(java.lang.String name)Set the file name.(package private) booleansetReadOnly()Set the read-only flag.(package private) voidtouch(boolean openReadOnly)Update the last modified time.(package private) voidtruncate(long newLength)Truncate the file.(package private) voidunlock()Unlock the file.
-
-
-
Field Detail
-
CACHE_MIN_SIZE
private static final int CACHE_MIN_SIZE
- See Also:
- Constant Field Values
-
BLOCK_SIZE_SHIFT
private static final int BLOCK_SIZE_SHIFT
- See Also:
- Constant Field Values
-
BLOCK_SIZE
private static final int BLOCK_SIZE
- See Also:
- Constant Field Values
-
BLOCK_SIZE_MASK
private static final int BLOCK_SIZE_MASK
- See Also:
- Constant Field Values
-
COMPRESSED_EMPTY_BLOCK
private static final java.nio.ByteBuffer COMPRESSED_EMPTY_BLOCK
-
LZF_THREAD_LOCAL
private static final java.lang.ThreadLocal<CompressLZF> LZF_THREAD_LOCAL
-
COMPRESS_OUT_BUF_THREAD_LOCAL
private static final java.lang.ThreadLocal<byte[]> COMPRESS_OUT_BUF_THREAD_LOCAL
the output buffer when compressing
-
nameHashCode
final int nameHashCode
The hash code of the name.
-
compressLaterCache
private final FileNioMemData.CompressLaterCache<FileNioMemData.CompressItem,FileNioMemData.CompressItem> compressLaterCache
-
name
private java.lang.String name
-
compress
private final boolean compress
-
compressLaterCachePercent
private final float compressLaterCachePercent
-
length
private volatile long length
-
buffers
private java.util.concurrent.atomic.AtomicReference<java.nio.ByteBuffer>[] buffers
-
lastModified
private long lastModified
-
isReadOnly
private boolean isReadOnly
-
isLockedExclusive
private boolean isLockedExclusive
-
sharedLockCount
private int sharedLockCount
-
rwLock
private final java.util.concurrent.locks.ReentrantReadWriteLock rwLock
-
-
Method Detail
-
lockExclusive
boolean lockExclusive()
Lock the file in exclusive mode if possible.- Returns:
- if locking was successful
-
lockShared
boolean lockShared()
Lock the file in shared mode if possible.- Returns:
- if locking was successful
-
unlock
void unlock()
Unlock the file.
-
addToCompressLaterCache
private void addToCompressLaterCache(int page)
-
expandPage
private java.nio.ByteBuffer expandPage(int page)
-
compressPage
void compressPage(int page)
Compress the data in a byte array.- Parameters:
page- which page to compress
-
touch
void touch(boolean openReadOnly)
Update the last modified time.- Parameters:
openReadOnly- if the file was opened in read-only mode
-
length
long length()
Get the file length.- Returns:
- the length
-
truncate
void truncate(long newLength)
Truncate the file.- Parameters:
newLength- the new length
-
changeLength
private void changeLength(long len)
-
readWrite
long readWrite(long pos, java.nio.ByteBuffer b, int off, int len, boolean write)Read or write.- Parameters:
pos- the positionb- the byte arrayoff- the offset within the byte arraylen- the number of byteswrite- true for writing- Returns:
- the new position
-
setName
void setName(java.lang.String name)
Set the file name.- Parameters:
name- the name
-
getName
java.lang.String getName()
Get the file name- Returns:
- the name
-
getLastModified
long getLastModified()
Get the last modified time.- Returns:
- the time
-
canWrite
boolean canWrite()
Check whether writing is allowed.- Returns:
- true if it is
-
setReadOnly
boolean setReadOnly()
Set the read-only flag.- Returns:
- true
-
-