Class DataBlocks.DataBlock

java.lang.Object
org.apache.hadoop.fs.store.DataBlocks.DataBlock
All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
DataBlocks

public abstract static class DataBlocks.DataBlock extends Object implements Closeable
This represents a block being uploaded.
  • Constructor Details

  • Method Details

    • enterState

      protected final void enterState(DataBlocks.DataBlock.DestState current, DataBlocks.DataBlock.DestState next) throws IllegalStateException
      Atomically enter a state, verifying current state.
      Parameters:
      current - current state. null means "no check"
      next - next state
      Throws:
      IllegalStateException - if the current state is not as expected
    • verifyState

      protected final void verifyState(DataBlocks.DataBlock.DestState expected) throws IllegalStateException
      Verify that the block is in the declared state.
      Parameters:
      expected - expected state.
      Throws:
      IllegalStateException - if the DataBlock is in the wrong state
    • getState

      public final DataBlocks.DataBlock.DestState getState()
      Current state.
      Returns:
      the current state.
    • dataSize

      public abstract int dataSize()
      Return the current data size.
      Returns:
      the size of the data.
    • hasData

      public boolean hasData()
      Predicate to check if there is data in the block.
      Returns:
      true if there is
    • remainingCapacity

      public abstract int remainingCapacity()
      The remaining capacity in the block before it is full.
      Returns:
      the number of bytes remaining.
    • write

      public int write(byte[] buffer, int offset, int length) throws IOException
      Write a series of bytes from the buffer, from the offset. Returns the number of bytes written. Only valid in the state Writing. Base class verifies the state but does no writing.
      Parameters:
      buffer - buffer.
      offset - offset.
      length - length of write.
      Returns:
      number of bytes written.
      Throws:
      IOException - trouble
    • flush

      public void flush() throws IOException
      Flush the output. Only valid in the state Writing. In the base class, this is a no-op
      Throws:
      IOException - any IO problem.
    • startUpload

      public DataBlocks.BlockUploadData startUpload() throws IOException
      Switch to the upload state and return a stream for uploading. Base class calls enterState(DestState, DestState) to manage the state machine.
      Returns:
      the stream.
      Throws:
      IOException - trouble
    • enterClosedState

      protected boolean enterClosedState()
      Enter the closed state.
      Returns:
      true if the class was in any other state, implying that the subclass should do its close operations.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • innerClose

      protected void innerClose() throws IOException
      Inner close logic for subclasses to implement.
      Throws:
      IOException - raised on errors performing I/O.
    • blockAllocated

      protected void blockAllocated()
      A block has been allocated.
    • blockReleased

      protected void blockReleased()
      A block has been released.
    • getStatistics

      protected BlockUploadStatistics getStatistics()
    • getIndex

      public long getIndex()