Class ChannelWriterOutputView
- java.lang.Object
-
- org.apache.flink.runtime.memory.AbstractPagedOutputView
-
- org.apache.flink.runtime.io.disk.iomanager.ChannelWriterOutputView
-
- All Implemented Interfaces:
DataOutput
,DataOutputView
,MemorySegmentWritable
public final class ChannelWriterOutputView extends AbstractPagedOutputView
ADataOutputView
that is backed by aBlockChannelWriter
, making it effectively a data output stream. The view writes its data in blocks to the underlying channel, adding a minimal header to each block. The data can be re-read by aChannelReaderInputView
, if it uses the same block size.
-
-
Field Summary
Fields Modifier and Type Field Description protected static short
FLAG_LAST_BLOCK
The flag marking a block as the last block.protected static int
HEAD_BLOCK_LENGTH_OFFSET
The offset to the header field indicating the number of bytes in the blockprotected static int
HEADER_FLAGS_OFFSET
The offset to the flags in the header;protected static int
HEADER_LENGTH
The length of the header put into the blocks.protected static short
HEADER_MAGIC_NUMBER
The magic number that identifies blocks as blocks from a ChannelWriterOutputView.-
Fields inherited from class org.apache.flink.runtime.memory.AbstractPagedOutputView
headerLength, segmentSize
-
-
Constructor Summary
Constructors Constructor Description ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer, int segmentSize)
Creates an new ChannelWriterOutputView that writes to the given channel.ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer, List<MemorySegment> memory, int segmentSize)
Creates an new ChannelWriterOutputView that writes to the given channel and buffers data in the given memory segments.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<MemorySegment>
close()
Closes this OutputView, closing the underlying writer and returning all memory segments.int
getBlockCount()
Gets the number of blocks used by this view.long
getBytesMemoryUsed()
Gets the number of bytes used by this output view, including written bytes and header bytes.long
getBytesWritten()
Gets the number of pay-load bytes already written.protected MemorySegment
nextSegment(MemorySegment current, int posInSegment)
This method must return a segment.-
Methods inherited from class org.apache.flink.runtime.memory.AbstractPagedOutputView
advance, clear, getCurrentPositionInSegment, getCurrentSegment, getHeaderLength, getSegmentSize, seekOutput, skipBytesToWrite, write, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
-
-
-
Field Detail
-
HEADER_MAGIC_NUMBER
protected static final short HEADER_MAGIC_NUMBER
The magic number that identifies blocks as blocks from a ChannelWriterOutputView.- See Also:
- Constant Field Values
-
HEADER_LENGTH
protected static final int HEADER_LENGTH
The length of the header put into the blocks.- See Also:
- Constant Field Values
-
HEADER_FLAGS_OFFSET
protected static final int HEADER_FLAGS_OFFSET
The offset to the flags in the header;- See Also:
- Constant Field Values
-
HEAD_BLOCK_LENGTH_OFFSET
protected static final int HEAD_BLOCK_LENGTH_OFFSET
The offset to the header field indicating the number of bytes in the block- See Also:
- Constant Field Values
-
FLAG_LAST_BLOCK
protected static final short FLAG_LAST_BLOCK
The flag marking a block as the last block.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ChannelWriterOutputView
public ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer, List<MemorySegment> memory, int segmentSize)
Creates an new ChannelWriterOutputView that writes to the given channel and buffers data in the given memory segments. If the given memory segments are null, the writer takes its buffers directly from the return queue of the writer. Note that this variant locks if no buffers are contained in the return queue.- Parameters:
writer
- The writer to write to.memory
- The memory used to buffer data, or null, to utilize solely the return queue.segmentSize
- The size of the memory segments.
-
ChannelWriterOutputView
public ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer, int segmentSize)
Creates an new ChannelWriterOutputView that writes to the given channel. It uses only a single memory segment for the buffering, which it takes from the writer's return queue. Note that this variant locks if no buffers are contained in the return queue.- Parameters:
writer
- The writer to write to.segmentSize
- The size of the memory segments.
-
-
Method Detail
-
close
public List<MemorySegment> close() throws IOException
Closes this OutputView, closing the underlying writer and returning all memory segments.- Returns:
- A list containing all memory segments originally supplied to this view.
- Throws:
IOException
- Thrown, if the underlying writer could not be properly closed.
-
getBlockCount
public int getBlockCount()
Gets the number of blocks used by this view.- Returns:
- The number of blocks used.
-
getBytesWritten
public long getBytesWritten()
Gets the number of pay-load bytes already written. This excludes the number of bytes spent on headers in the segments.- Returns:
- The number of bytes that have been written to this output view.
-
getBytesMemoryUsed
public long getBytesMemoryUsed()
Gets the number of bytes used by this output view, including written bytes and header bytes.- Returns:
- The number of bytes that have been written to this output view.
-
nextSegment
protected final MemorySegment nextSegment(MemorySegment current, int posInSegment) throws IOException
Description copied from class:AbstractPagedOutputView
This method must return a segment. If no more segments are available, it must throw anEOFException
.- Specified by:
nextSegment
in classAbstractPagedOutputView
- Parameters:
current
- The current memory segmentposInSegment
- The position in the segment, one after the last valid byte.- Returns:
- The next memory segment.
- Throws:
IOException
-
-