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
FieldsModifier and TypeFieldDescriptionprotected final intprotected final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPagedOutputView(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
Modifier and TypeMethodDescriptionvoidadvance()Moves the output view to the next page.protected voidclear()Clears the internal state.intGets the current write position (the position where the next bytes will be written) in the current memory segment.org.apache.flink.core.memory.MemorySegmentGets the segment that the view currently writes to.intintGets 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) void
-
Field Details
-
segmentSize
protected final int segmentSize -
headerLength
protected final int headerLength
-
-
Constructor Details
-
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 Details
-
nextSegment
protected abstract org.apache.flink.core.memory.MemorySegment nextSegment(org.apache.flink.core.memory.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 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
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(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:
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
writeBoolean
- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeShort
- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeChar
- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeInt
- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeFloat
- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeDouble
- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeBytes
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChars
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeUTF
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
skipBytesToWrite
- 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
-