org.apache.hadoop.hdfs

## Class ReplicaAccessor

- java.lang.Object
- - org.apache.hadoop.hdfs.ReplicaAccessor

-     @InterfaceAudience.Public
       @InterfaceStability.Stable
      public abstract class ReplicaAccessor
      extends Object

  The public API for ReplicaAccessor objects.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReplicaAccessor()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `close()` Release the resources associated with the ReplicaAccessor.
    `int` | `getNetworkDistance()` Return the network distance between local machine and the remote machine.
    `abstract boolean` | `isLocal()` Return true if bytes read via this accessor should count towards the local byte count statistics.
    `abstract boolean` | `isShortCircuit()` Return true if bytes read via this accessor should count towards the short-circuit byte count statistics.
    `abstract int` | `read(long pos, byte[] buf, int off, int len)` Read bytes from the replica.
    `abstract int` | `read(long pos, ByteBuffer buf)` Read bytes from the replica.

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

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

- - ### Constructor Detail

    - #### ReplicaAccessor

          public ReplicaAccessor()

  - ### Method Detail

    - #### read

          public abstract int read(long pos,
                                   byte[] buf,
                                   int off,
                                   int len)
                            throws IOException

      Read bytes from the replica.
      Parameters:
        `pos` - The position in the replica to start reading at. Must not be negative.
        `buf` - The byte array to read into.
        `off` - The offset within buf to start reading into.
        `len` - The maximum length to read.
      Returns:
        The number of bytes read. If the read extends past the end of the replica, a short read count will be returned. We will should return -1 if EOF is reached and no bytes can be returned. We will never return a short read count unless EOF is reached.
      Throws:
        `IOException`

    - #### read

          public abstract int read(long pos,
                                   ByteBuffer buf)
                            throws IOException

      Read bytes from the replica.
      Parameters:
        `pos` - The position in the replica to start reading at. Must not be negative.
        `buf` - The byte buffer to read into. The amount to read will be dictated by the remaining bytes between the current position and the limit. The ByteBuffer may or may not be direct.
      Returns:
        The number of bytes read. If the read extends past the end of the replica, a short read count will be returned. We should return -1 if EOF is reached and no bytes can be returned. We will never return a short read count unless EOF is reached.
      Throws:
        `IOException`

    - #### close

          public abstract void close()
                              throws IOException

      Release the resources associated with the ReplicaAccessor. It is recommended that implementations never throw an IOException. The method is declared as throwing IOException in order to remain compatible with java.io.Closeable. If an exception is thrown, the ReplicaAccessor must still be closed when the function returns in order to prevent a resource leak.
      Throws:
        `IOException`

    - #### isLocal

          public abstract boolean isLocal()

      Return true if bytes read via this accessor should count towards the local byte count statistics.

    - #### isShortCircuit

          public abstract boolean isShortCircuit()

      Return true if bytes read via this accessor should count towards the short-circuit byte count statistics.

    - #### getNetworkDistance

          public int getNetworkDistance()

      Return the network distance between local machine and the remote machine.

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.