public class BufferManager extends Object
Buffers are acquired using createBuffer()
, and should be
disposed of using disposeBuffer(java.nio.ByteBuffer)
when no longer in use.
When none of the buffers are in use any more, close()
should
be called.
Note: the mapped buffer is unmapped using
the supplied Unmapper
when all created buffers have been disposed,
or when close() is called.
If any of the created buffers is used after this has happened,
and unmapping is actually attempted, very bad consequences may ensue.
Therefore this class, or at least its disposeBuffer(java.nio.ByteBuffer)
and
close()
methods, should be used with extreme caution,
or a null Unmapper should be supplied.
Constructor and Description |
---|
BufferManager(FileChannel channel,
long offset,
int leng,
String logLabel,
Unmapper unmapper)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Asserts that neither this manager, nor any of the buffers it has
supplied, will be used again.
|
ByteBuffer |
createBuffer()
Returns a new read-only ByteBuffer providing access to the
file region.
|
void |
disposeBuffer(ByteBuffer buf)
Asserts that the supplied buffer, originally acquired from
createBuffer() , will no longer be used. |
public BufferManager(FileChannel channel, long offset, int leng, String logLabel, Unmapper unmapper)
channel
- file channeloffset
- offset into file of start of mapped regionleng
- length of mapped regionlogLabel
- description of mapped region
suitable for use in logging messagesunmapper
- used to unmap buffers, may be null for safetypublic ByteBuffer createBuffer() throws IOException
disposeBuffer(java.nio.ByteBuffer)
after it is known that it will
no longer be used.IOException
public void disposeBuffer(ByteBuffer buf)
createBuffer()
, will no longer be used.
Resources may be reclaimed.buf
- previously created bufferpublic void close()
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.