BlockManager (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.fs.impl.prefetch, class: BlockManager

Package org.apache.hadoop.fs.impl.prefetch

# Class BlockManager

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

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

Direct Known Subclasses:
  `CachingBlockManager`

public abstract class BlockManager extends Object implements Closeable
Provides read access to the underlying file one block at a time. This class is the simplest form of a `BlockManager` that does perform prefetching or caching.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BlockManager(BlockData blockData)`
  Constructs an instance of `BlockManager`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `cancelPrefetches()`
  Requests cancellation of any previously issued prefetch requests.
  `void`
  `close()`
  `BufferData`
  `get(int blockNumber)`
  Gets the block having the given `blockNumber`.
  `BlockData`
  `getBlockData()`
  Gets block data information.
  `abstract int`
  `read(ByteBuffer buffer, long startOffset, int size)`
  Reads into the given `buffer` `size` bytes from the underlying file starting at `startOffset`.
  `void`
  `release(BufferData data)`
  Releases resources allocated to the given block.
  `void`
  `requestCaching(BufferData data)`
  Requests that the given block should be copied to the cache.
  `void`
  `requestPrefetch(int blockNumber)`
  Requests optional prefetching of the given block.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### BlockManager

    public BlockManager(BlockData blockData)
    Constructs an instance of `BlockManager`.
    Parameters:
      `blockData` - information about each block of the underlying file.
    Throws:
      `IllegalArgumentException` - if blockData is null.

- ## Method Details

  - ### getBlockData

    public BlockData getBlockData()
    Gets block data information.
    Returns:
      instance of `BlockData`.

  - ### get

    public BufferData get(int blockNumber) throws IOException
    Gets the block having the given `blockNumber`. The entire block is read into memory and returned as a `BufferData`. The blocks are treated as a limited resource and must be released when one is done reading them.
    Parameters:
      `blockNumber` - the number of the block to be read and returned.
    Returns:
      `BufferData` having data from the given block.
    Throws:
      `IOException` - if there an error reading the given block.
      `IllegalArgumentException` - if blockNumber is negative.

  - ### read

    public abstract int read(ByteBuffer buffer, long startOffset, int size) throws IOException
    Reads into the given `buffer` `size` bytes from the underlying file starting at `startOffset`.
    Parameters:
      `buffer` - the buffer to read data in to.
      `startOffset` - the offset at which reading starts.
      `size` - the number bytes to read.
    Returns:
      number of bytes read.
    Throws:
      `IOException` - if there an error reading the given block.

  - ### release

    public void release(BufferData data)
    Releases resources allocated to the given block.
    Parameters:
      `data` - the `BufferData` to release.
    Throws:
      `IllegalArgumentException` - if data is null.

  - ### requestPrefetch

    public void requestPrefetch(int blockNumber)
    Requests optional prefetching of the given block.
    Parameters:
      `blockNumber` - the id of the block to prefetch.
    Throws:
      `IllegalArgumentException` - if blockNumber is negative.

  - ### cancelPrefetches

    public void cancelPrefetches()
    Requests cancellation of any previously issued prefetch requests.

  - ### requestCaching

    public void requestCaching(BufferData data)
    Requests that the given block should be copied to the cache. Optional operation.
    Parameters:
      `data` - the `BufferData` instance to optionally cache.

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`