Package org.apache.flink.runtime.memory
Class AbstractPagedOutputView
- java.lang.Object
-
- org.apache.flink.runtime.memory.AbstractPagedOutputView
-
- All Implemented Interfaces:
DataOutput,org.apache.flink.core.memory.DataOutputView,org.apache.flink.core.memory.MemorySegmentWritable
- Direct Known Subclasses:
AbstractChannelWriterOutputView,ChannelWriterOutputView,FileChannelOutputView,HashPartition.BuildSideBuffer,RandomAccessOutputView,SerializedUpdateBuffer,SimpleCollectingOutputView,SpillingBuffer
public abstract class AbstractPagedOutputView extends Object implements org.apache.flink.core.memory.DataOutputView, org.apache.flink.core.memory.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 intheaderLengthprotected intsegmentSize
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractPagedOutputView(int segmentSize, int headerLength)protectedAbstractPagedOutputView(org.apache.flink.core.memory.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 voidadvance()Moves the output view to the next page.protected voidclear()Clears the internal state.intgetCurrentPositionInSegment()Gets the current write position (the position where the next bytes will be written) in the current memory segment.org.apache.flink.core.memory.MemorySegmentgetCurrentSegment()Gets the segment that the view currently writes to.intgetHeaderLength()intgetSegmentSize()Gets the size of the segments used by this view.protected abstract org.apache.flink.core.memory.MemorySegmentnextSegment(org.apache.flink.core.memory.MemorySegment current, int positionInCurrent)This method must return a segment.protected voidseekOutput(org.apache.flink.core.memory.MemorySegment seg, int position)Sets the internal state to the given memory segment and the given position within the segment.voidskipBytesToWrite(int numBytes)voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwrite(org.apache.flink.core.memory.DataInputView source, int numBytes)voidwrite(org.apache.flink.core.memory.MemorySegment segment, int off, int len)voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(String s)voidwriteChar(int v)voidwriteChars(String s)voidwriteDouble(double v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(String str)
-
-
-
Constructor Detail
-
AbstractPagedOutputView
protected AbstractPagedOutputView(org.apache.flink.core.memory.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 lengthheaderLengthis 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 org.apache.flink.core.memory.MemorySegment nextSegment(org.apache.flink.core.memory.MemorySegment current, int positionInCurrent) throws IOExceptionThis 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 org.apache.flink.core.memory.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 IOExceptionMoves 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(org.apache.flink.core.memory.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:
writein interfaceDataOutput- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean v) throws IOException- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeShort
public void writeShort(int v) throws IOException- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeChar
public void writeChar(int v) throws IOException- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeInt
public void writeInt(int v) throws IOException- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
public void writeLong(long v) throws IOException- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeFloat
public void writeFloat(float v) throws IOException- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeDouble
public void writeDouble(double v) throws IOException- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeUTF
public void writeUTF(String str) throws IOException
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
skipBytesToWrite
public void skipBytesToWrite(int numBytes) throws IOException- Specified by:
skipBytesToWritein interfaceorg.apache.flink.core.memory.DataOutputView- Throws:
IOException
-
write
public void write(org.apache.flink.core.memory.DataInputView source, int numBytes) throws IOException- Specified by:
writein interfaceorg.apache.flink.core.memory.DataOutputView- Throws:
IOException
-
write
public void write(org.apache.flink.core.memory.MemorySegment segment, int off, int len) throws IOException- Specified by:
writein interfaceorg.apache.flink.core.memory.MemorySegmentWritable- Throws:
IOException
-
-