Package org.apache.hadoop.hdfs
Class ReplicaAccessor
java.lang.Object
org.apache.hadoop.hdfs.ReplicaAccessor
The public API for ReplicaAccessor objects.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Release the resources associated with the ReplicaAccessor.intReturn the network distance between local machine and the remote machine.abstract booleanisLocal()Return true if bytes read via this accessor should count towards the local byte count statistics.abstract booleanReturn true if bytes read via this accessor should count towards the short-circuit byte count statistics.abstract intread(long pos, byte[] buf, int off, int len) Read bytes from the replica.abstract intread(long pos, ByteBuffer buf) Read bytes from the replica.
-
Constructor Details
-
ReplicaAccessor
public ReplicaAccessor()
-
-
Method Details
-
read
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
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
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.
-