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 final int
     
    protected final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractPagedOutputView(int segmentSize, int headerLength)
     
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Moves the output view to the next page.
    protected void
    Clears the internal state.
    int
    Gets the current write position (the position where the next bytes will be written) in the current memory segment.
    org.apache.flink.core.memory.MemorySegment
    Gets the segment that the view currently writes to.
    int
     
    int
    Gets the size of the segments used by this view.
    protected abstract org.apache.flink.core.memory.MemorySegment
    nextSegment(org.apache.flink.core.memory.MemorySegment current, int positionInCurrent)
    This method must return a segment.
    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.
    void
    skipBytesToWrite(int numBytes)
     
    void
    write(byte[] b)
     
    void
    write(byte[] b, int off, int len)
     
    void
    write(int b)
     
    void
    write(org.apache.flink.core.memory.DataInputView source, int numBytes)
     
    void
    write(org.apache.flink.core.memory.MemorySegment segment, int off, int len)
     
    void
    writeBoolean(boolean v)
     
    void
    writeByte(int v)
     
    void
     
    void
    writeChar(int v)
     
    void
     
    void
    writeDouble(double v)
     
    void
    writeFloat(float v)
     
    void
    writeInt(int v)
     
    void
    writeLong(long v)
     
    void
    writeShort(int v)
     
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 given segmentSize. A header of length headerLength 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 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 an EOFException.
      Parameters:
      current - The current memory segment
      positionInCurrent - 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 IOException
      Moves the output view to the next page. This method invokes internally the nextSegment(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 either advance() or seekOutput(MemorySegment, int) is called.
      See Also:
    • write

      public void write(int b) throws IOException
      Specified by:
      write in interface DataOutput
      Throws:
      IOException
    • write

      public void write(byte[] b) throws IOException
      Specified by:
      write in interface DataOutput
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Specified by:
      write in interface DataOutput
      Throws:
      IOException
    • writeBoolean

      public void writeBoolean(boolean v) throws IOException
      Specified by:
      writeBoolean in interface DataOutput
      Throws:
      IOException
    • writeByte

      public void writeByte(int v) throws IOException
      Specified by:
      writeByte in interface DataOutput
      Throws:
      IOException
    • writeShort

      public void writeShort(int v) throws IOException
      Specified by:
      writeShort in interface DataOutput
      Throws:
      IOException
    • writeChar

      public void writeChar(int v) throws IOException
      Specified by:
      writeChar in interface DataOutput
      Throws:
      IOException
    • writeInt

      public void writeInt(int v) throws IOException
      Specified by:
      writeInt in interface DataOutput
      Throws:
      IOException
    • writeLong

      public void writeLong(long v) throws IOException
      Specified by:
      writeLong in interface DataOutput
      Throws:
      IOException
    • writeFloat

      public void writeFloat(float v) throws IOException
      Specified by:
      writeFloat in interface DataOutput
      Throws:
      IOException
    • writeDouble

      public void writeDouble(double v) throws IOException
      Specified by:
      writeDouble in interface DataOutput
      Throws:
      IOException
    • writeBytes

      public void writeBytes(String s) throws IOException
      Specified by:
      writeBytes in interface DataOutput
      Throws:
      IOException
    • writeChars

      public void writeChars(String s) throws IOException
      Specified by:
      writeChars in interface DataOutput
      Throws:
      IOException
    • writeUTF

      public void writeUTF(String str) throws IOException
      Specified by:
      writeUTF in interface DataOutput
      Throws:
      IOException
    • skipBytesToWrite

      public void skipBytesToWrite(int numBytes) throws IOException
      Specified by:
      skipBytesToWrite in interface org.apache.flink.core.memory.DataOutputView
      Throws:
      IOException
    • write

      public void write(org.apache.flink.core.memory.DataInputView source, int numBytes) throws IOException
      Specified by:
      write in interface org.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:
      write in interface org.apache.flink.core.memory.MemorySegmentWritable
      Throws:
      IOException