Package org.apache.bookkeeper.bookie
Class SlowBufferedChannel
- java.lang.Object
-
- org.apache.bookkeeper.bookie.BufferedChannelBase
-
- org.apache.bookkeeper.bookie.BufferedReadChannel
-
- org.apache.bookkeeper.bookie.BufferedChannel
-
- org.apache.bookkeeper.bookie.SlowBufferedChannel
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class SlowBufferedChannel extends BufferedChannel
Strictly for testing. Have to be alongside with prod code for Journal to inject in tests.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.bookkeeper.bookie.BufferedChannelBase
BufferedChannelBase.BufferedChannelClosedException
-
-
Field Summary
Fields Modifier and Type Field Description long
addDelay
long
flushDelay
long
getDelay
-
Fields inherited from class org.apache.bookkeeper.bookie.BufferedChannel
position, unpersistedBytes, unpersistedBytesBound, writeBuffer, writeBufferStartPosition, writeCapacity
-
Fields inherited from class org.apache.bookkeeper.bookie.BufferedReadChannel
cacheHitCount, invocationCount, readBuffer, readBufferStartPosition, readCapacity, sealed
-
Fields inherited from class org.apache.bookkeeper.bookie.BufferedChannelBase
fileChannel
-
-
Constructor Summary
Constructors Constructor Description SlowBufferedChannel(io.netty.buffer.ByteBufAllocator allocator, java.nio.channels.FileChannel fc, int capacity)
SlowBufferedChannel(io.netty.buffer.ByteBufAllocator allocator, java.nio.channels.FileChannel fc, int writeCapacity, int readCapacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
flush()
Write any data in the buffer to the file and advance the writeBufferPosition.long
forceWrite(boolean forceMetadata)
force a sync operation so that data is persisted to the disk.int
read(io.netty.buffer.ByteBuf dest, long pos)
Read as many bytes into dest as dest.capacity() starting at position pos in the FileChannel.void
setAddDelay(long delay)
void
setFlushDelay(long delay)
void
setGetDelay(long delay)
void
write(io.netty.buffer.ByteBuf src)
Write all the data in src to theFileChannel
.-
Methods inherited from class org.apache.bookkeeper.bookie.BufferedChannel
clear, close, flushAndForceWrite, flushAndForceWriteIfRegularFlush, getFileChannelPosition, getNumOfBytesInWriteBuffer, getUnpersistedBytes, position, read
-
Methods inherited from class org.apache.bookkeeper.bookie.BufferedReadChannel
size
-
Methods inherited from class org.apache.bookkeeper.bookie.BufferedChannelBase
validateAndGetFileChannel
-
-
-
-
Constructor Detail
-
SlowBufferedChannel
public SlowBufferedChannel(io.netty.buffer.ByteBufAllocator allocator, java.nio.channels.FileChannel fc, int capacity) throws java.io.IOException
- Throws:
java.io.IOException
-
SlowBufferedChannel
public SlowBufferedChannel(io.netty.buffer.ByteBufAllocator allocator, java.nio.channels.FileChannel fc, int writeCapacity, int readCapacity) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
setAddDelay
public void setAddDelay(long delay)
-
setGetDelay
public void setGetDelay(long delay)
-
setFlushDelay
public void setFlushDelay(long delay)
-
write
public void write(io.netty.buffer.ByteBuf src) throws java.io.IOException
Description copied from class:BufferedChannel
Write all the data in src to theFileChannel
. Note that this function can buffer or re-order writes based on the implementation. These writes will be flushed to the disk only when flush() is invoked.- Overrides:
write
in classBufferedChannel
- Parameters:
src
- The source ByteBuffer which contains the data to be written.- Throws:
java.io.IOException
- if a write operation fails.
-
flush
public void flush() throws java.io.IOException
Description copied from class:BufferedChannel
Write any data in the buffer to the file and advance the writeBufferPosition. Callers are expected to synchronize appropriately- Overrides:
flush
in classBufferedChannel
- Throws:
java.io.IOException
- if the write fails.
-
forceWrite
public long forceWrite(boolean forceMetadata) throws java.io.IOException
Description copied from class:BufferedChannel
force a sync operation so that data is persisted to the disk.- Overrides:
forceWrite
in classBufferedChannel
- Returns:
- Throws:
java.io.IOException
-
read
public int read(io.netty.buffer.ByteBuf dest, long pos) throws java.io.IOException
Description copied from class:BufferedReadChannel
Read as many bytes into dest as dest.capacity() starting at position pos in the FileChannel. This function can read from the buffer or the file channel depending on the implementation..- Overrides:
read
in classBufferedReadChannel
- Returns:
- The total number of bytes read. -1 if the given position is greater than or equal to the file's current size.
- Throws:
java.io.IOException
- if I/O error occurs
-
-