Class BufferData

java.lang.Object
org.apache.hadoop.fs.impl.prefetch.BufferData

public final class BufferData extends Object
Holds the state of a ByteBuffer that is in use by CachingBlockManager. This class is not meant to be of general use. It exists into its own file due to its size. We use the term block and buffer interchangeably in this file because one buffer holds exactly one block of data. Holding all of the state associated with a block allows us to validate and control state transitions in a synchronized fashion.
  • Constructor Details

    • BufferData

      public BufferData(int blockNumber, ByteBuffer buffer)
      Constructs an instances of this class.
      Parameters:
      blockNumber - Number of the block associated with this buffer.
      buffer - The buffer associated with this block.
      Throws:
      IllegalArgumentException - if blockNumber is negative.
      IllegalArgumentException - if buffer is null.
  • Method Details

    • getBlockNumber

      public int getBlockNumber()
      Gets the id of this block.
      Returns:
      the id of this block.
    • getBuffer

      public ByteBuffer getBuffer()
      Gets the buffer associated with this block.
      Returns:
      the buffer associated with this block.
    • getState

      public BufferData.State getState()
      Gets the state of this block.
      Returns:
      the state of this block.
    • getChecksum

      public long getChecksum()
      Gets the checksum of data in this block.
      Returns:
      the checksum of data in this block.
    • getChecksum

      public static long getChecksum(ByteBuffer buffer)
      Computes CRC32 checksum of the given buffer's contents.
      Parameters:
      buffer - the buffer whose content's checksum is to be computed.
      Returns:
      the computed checksum.
    • getActionFuture

      public Future<Void> getActionFuture()
    • setPrefetch

      public void setPrefetch(Future<Void> actionFuture)
      Indicates that a prefetch operation is in progress.
      Parameters:
      actionFuture - the Future of a prefetch action.
      Throws:
      IllegalArgumentException - if actionFuture is null.
    • setCaching

      public void setCaching(Future<Void> actionFuture)
      Indicates that a caching operation is in progress.
      Parameters:
      actionFuture - the Future of a caching action.
      Throws:
      IllegalArgumentException - if actionFuture is null.
    • setReady

      public void setReady(BufferData.State... expectedCurrentState)
      Marks the completion of reading data into the buffer. The buffer cannot be modified once in this state.
      Parameters:
      expectedCurrentState - the collection of states from which transition to READY is allowed.
    • setDone

      public void setDone()
      Indicates that this block is no longer of use and can be reclaimed.
    • updateState

      public void updateState(BufferData.State newState, BufferData.State... expectedCurrentState)
      Updates the current state to the specified value. Asserts that the current state is as expected.
      Parameters:
      newState - the state to transition to.
      expectedCurrentState - the collection of states from which transition to newState is allowed.
      Throws:
      IllegalArgumentException - if newState is null.
      IllegalArgumentException - if expectedCurrentState is null.
    • throwIfStateIncorrect

      public void throwIfStateIncorrect(BufferData.State... states)
      Helper that asserts the current state is one of the expected values.
      Parameters:
      states - the collection of allowed states.
      Throws:
      IllegalArgumentException - if states is null.
    • stateEqualsOneOf

      public boolean stateEqualsOneOf(BufferData.State... states)
    • toString

      public String toString()
      Overrides:
      toString in class Object