Package org.apache.flink.runtime.memory
Class AbstractPagedOutputView
- java.lang.Object
-
- org.apache.flink.runtime.memory.AbstractPagedOutputView
-
- All Implemented Interfaces:
DataOutput
,DataOutputView
,MemorySegmentWritable
- Direct Known Subclasses:
AbstractChannelWriterOutputView
,BinaryHashPartition.BuildSideBuffer
,ChannelWriterOutputView
,FileChannelOutputView
,HashPartition.BuildSideBuffer
,RandomAccessOutputView
,SerializedUpdateBuffer
,SimpleCollectingOutputView
,SpillingBuffer
public abstract class AbstractPagedOutputView extends Object implements DataOutputView, MemorySegmentWritable
The base class for all output views that are backed by multiple memory pages. This base class contains all encoding methods to write data to a page and detect page boundary crossing. The concrete sub classes must implement the methods to collect the current page and provide the next memory page once the boundary is crossed.The paging assumes that all memory segments are of the same size.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
headerLength
protected int
segmentSize
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPagedOutputView(int segmentSize, int headerLength)
protected
AbstractPagedOutputView(MemorySegment initialSegment, int segmentSize, int headerLength)
Creates a new output view that writes initially to the given initial segment.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
advance()
Moves the output view to the next page.protected void
clear()
Clears the internal state.int
getCurrentPositionInSegment()
Gets the current write position (the position where the next bytes will be written) in the current memory segment.MemorySegment
getCurrentSegment()
Gets the segment that the view currently writes to.int
getHeaderLength()
int
getSegmentSize()
Gets the size of the segments used by this view.protected abstract MemorySegment
nextSegment(MemorySegment current, int positionInCurrent)
This method must return a segment.protected void
seekOutput(MemorySegment seg, int position)
Sets the internal state to the given memory segment and the given position within the segment.void
skipBytesToWrite(int numBytes)
SkipsnumBytes
bytes memory.void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
void
write(DataInputView source, int numBytes)
CopiesnumBytes
bytes from the source to this view.void
write(MemorySegment segment, int off, int len)
Writeslen
bytes from memory segmentsegment
starting at offsetoff
, in order, to the output.void
writeBoolean(boolean v)
void
writeByte(int v)
void
writeBytes(String s)
void
writeChar(int v)
void
writeChars(String s)
void
writeDouble(double v)
void
writeFloat(float v)
void
writeInt(int v)
void
writeLong(long v)
void
writeShort(int v)
void
writeUTF(String str)
-
-
-
Constructor Detail
-
AbstractPagedOutputView
protected AbstractPagedOutputView(MemorySegment initialSegment, int segmentSize, int headerLength)
Creates a new output view that writes initially to the given initial segment. All segments in the view have to be of the givensegmentSize
. A header of lengthheaderLength
is left at the beginning of each segment.- Parameters:
initialSegment
- The segment that the view starts writing to.segmentSize
- The size of the memory segments.headerLength
- The number of bytes to skip at the beginning of each segment for the header.
-
AbstractPagedOutputView
protected AbstractPagedOutputView(int segmentSize, int headerLength)
- Parameters:
segmentSize
- The size of the memory segments.headerLength
- The number of bytes to skip at the beginning of each segment for the header.
-
-
Method Detail
-
nextSegment
protected abstract MemorySegment nextSegment(MemorySegment current, int positionInCurrent) throws IOException
This method must return a segment. If no more segments are available, it must throw anEOFException
.- Parameters:
current
- The current memory segmentpositionInCurrent
- The position in the segment, one after the last valid byte.- Returns:
- The next memory segment.
- Throws:
IOException
-
getCurrentSegment
public MemorySegment getCurrentSegment()
Gets the segment that the view currently writes to.- Returns:
- The segment the view currently writes to.
-
getCurrentPositionInSegment
public int getCurrentPositionInSegment()
Gets the current write position (the position where the next bytes will be written) in the current memory segment.- Returns:
- The current write offset in the current memory segment.
-
getSegmentSize
public int getSegmentSize()
Gets the size of the segments used by this view.- Returns:
- The memory segment size.
-
advance
public void advance() throws IOException
Moves the output view to the next page. This method invokes internally thenextSegment(MemorySegment, int)
method to give the current memory segment to the concrete subclass' implementation and obtain the next segment to write to. Writing will continue inside the new segment after the header.- Throws:
IOException
- Thrown, if the current segment could not be processed or a new segment could not be obtained.
-
getHeaderLength
public int getHeaderLength()
- Returns:
- header length.
-
seekOutput
protected void seekOutput(MemorySegment seg, int position)
Sets the internal state to the given memory segment and the given position within the segment.- Parameters:
seg
- The memory segment to write the next bytes to.position
- The position to start writing the next bytes to.
-
clear
protected void clear()
Clears the internal state. Any successive write calls will fail until eitheradvance()
orseekOutput(MemorySegment, int)
is called.- See Also:
advance()
,seekOutput(MemorySegment, int)
-
write
public void write(int b) throws IOException
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
public void write(byte[] b) throws IOException
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean v) throws IOException
- Specified by:
writeBoolean
in interfaceDataOutput
- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException
- Specified by:
writeByte
in interfaceDataOutput
- Throws:
IOException
-
writeShort
public void writeShort(int v) throws IOException
- Specified by:
writeShort
in interfaceDataOutput
- Throws:
IOException
-
writeChar
public void writeChar(int v) throws IOException
- Specified by:
writeChar
in interfaceDataOutput
- Throws:
IOException
-
writeInt
public void writeInt(int v) throws IOException
- Specified by:
writeInt
in interfaceDataOutput
- Throws:
IOException
-
writeLong
public void writeLong(long v) throws IOException
- Specified by:
writeLong
in interfaceDataOutput
- Throws:
IOException
-
writeFloat
public void writeFloat(float v) throws IOException
- Specified by:
writeFloat
in interfaceDataOutput
- Throws:
IOException
-
writeDouble
public void writeDouble(double v) throws IOException
- Specified by:
writeDouble
in interfaceDataOutput
- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Specified by:
writeBytes
in interfaceDataOutput
- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Specified by:
writeChars
in interfaceDataOutput
- Throws:
IOException
-
writeUTF
public void writeUTF(String str) throws IOException
- Specified by:
writeUTF
in interfaceDataOutput
- Throws:
IOException
-
skipBytesToWrite
public void skipBytesToWrite(int numBytes) throws IOException
Description copied from interface:DataOutputView
SkipsnumBytes
bytes memory. If some program reads the memory that was skipped over, the results are undefined.- Specified by:
skipBytesToWrite
in interfaceDataOutputView
- Parameters:
numBytes
- The number of bytes to skip.- Throws:
IOException
- Thrown, if any I/O related problem occurred such that the view could not be advanced to the desired position.
-
write
public void write(DataInputView source, int numBytes) throws IOException
Description copied from interface:DataOutputView
CopiesnumBytes
bytes from the source to this view.- Specified by:
write
in interfaceDataOutputView
- Parameters:
source
- The source to copy the bytes from.numBytes
- The number of bytes to copy.- Throws:
IOException
- Thrown, if any I/O related problem occurred, such that either the input view could not be read, or the output could not be written.
-
write
public void write(MemorySegment segment, int off, int len) throws IOException
Description copied from interface:MemorySegmentWritable
Writeslen
bytes from memory segmentsegment
starting at offsetoff
, in order, to the output.- Specified by:
write
in interfaceMemorySegmentWritable
- Parameters:
segment
- memory segment to copy the bytes from.off
- the start offset in the memory segment.len
- The number of bytes to copy.- Throws:
IOException
- if an I/O error occurs.
-
-