Package org.apache.cassandra.io.util
Class BufferManagingRebufferer
- java.lang.Object
-
- org.apache.cassandra.io.util.BufferManagingRebufferer
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,ReaderFileProxy
,Rebufferer
,Rebufferer.BufferHolder
- Direct Known Subclasses:
BufferManagingRebufferer.Aligned
,BufferManagingRebufferer.Unaligned
public abstract class BufferManagingRebufferer extends java.lang.Object implements Rebufferer, Rebufferer.BufferHolder
Buffer manager used for reading from a ChunkReader when cache is not in use. Instances of this class are reader-specific and thus do not need to be thread-safe since the reader itself isn't. The instances reuse themselves as the BufferHolder to avoid having to return a new object for each rebuffer call.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BufferManagingRebufferer.Aligned
static class
BufferManagingRebufferer.Unaligned
-
Nested classes/interfaces inherited from interface org.apache.cassandra.io.util.Rebufferer
Rebufferer.BufferHolder
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.ByteBuffer
buffer
protected long
offset
protected ChunkReader
source
-
Fields inherited from interface org.apache.cassandra.io.util.Rebufferer
EMPTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BufferManagingRebufferer(ChunkReader wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBuffer
buffer()
Returns a useable buffer (i.e.ChannelProxy
channel()
void
close()
void
closeReader()
Called when a reader is closed.long
fileLength()
double
getCrcCheckChance()
Needed for tests.long
offset()
Position in the file of the start of the buffer.Rebufferer.BufferHolder
rebuffer(long position)
Rebuffer (move on or seek to) a given position, and return a buffer that can be used there.void
release()
To be called when this buffer is no longer in use.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.io.util.Rebufferer.BufferHolder
floatBuffer, intBuffer
-
-
-
-
Field Detail
-
source
protected final ChunkReader source
-
buffer
protected final java.nio.ByteBuffer buffer
-
offset
protected long offset
-
-
Constructor Detail
-
BufferManagingRebufferer
protected BufferManagingRebufferer(ChunkReader wrapped)
-
-
Method Detail
-
closeReader
public void closeReader()
Description copied from interface:Rebufferer
Called when a reader is closed. Should clean up reader-specific data.- Specified by:
closeReader
in interfaceRebufferer
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceReaderFileProxy
-
channel
public ChannelProxy channel()
- Specified by:
channel
in interfaceReaderFileProxy
-
fileLength
public long fileLength()
- Specified by:
fileLength
in interfaceReaderFileProxy
-
rebuffer
public Rebufferer.BufferHolder rebuffer(long position)
Description copied from interface:Rebufferer
Rebuffer (move on or seek to) a given position, and return a buffer that can be used there. The only guarantee about the size of the returned data is that unless rebuffering at the end of the file, the buffer will not be empty and will contain the requested position, i.e.offset <= position < offset + bh.buffer().limit()
, but the buffer will not be positioned there.- Specified by:
rebuffer
in interfaceRebufferer
-
getCrcCheckChance
public double getCrcCheckChance()
Description copied from interface:ReaderFileProxy
Needed for tests. Returns the table's CRC check chance, which is only set for compressed tables.- Specified by:
getCrcCheckChance
in interfaceReaderFileProxy
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
buffer
public java.nio.ByteBuffer buffer()
Description copied from interface:Rebufferer.BufferHolder
Returns a useable buffer (i.e. one whose position and limit can be freely modified). Its limit will be set to the size of the available data in the buffer. The buffer must be treated as read-only.- Specified by:
buffer
in interfaceRebufferer.BufferHolder
-
offset
public long offset()
Description copied from interface:Rebufferer.BufferHolder
Position in the file of the start of the buffer.- Specified by:
offset
in interfaceRebufferer.BufferHolder
-
release
public void release()
Description copied from interface:Rebufferer.BufferHolder
To be called when this buffer is no longer in use. Must be called for all BufferHolders, or ChunkCache will not be able to free blocks.- Specified by:
release
in interfaceRebufferer.BufferHolder
-
-