Class ReplicaAccessor

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

@Public @Stable public abstract class ReplicaAccessor extends Object
The public API for ReplicaAccessor objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Release the resources associated with the ReplicaAccessor.
    int
    Return the network distance between local machine and the remote machine.
    abstract boolean
    Return true if bytes read via this accessor should count towards the local byte count statistics.
    abstract boolean
    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 Details

    • ReplicaAccessor

      public ReplicaAccessor()
  • Method Details

    • 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.