Class BufferData
java.lang.Object
org.apache.hadoop.fs.impl.prefetch.BufferData
Holds the state of a ByteBuffer that is in use by
CachingBlockManager.
This class is not meant to be of general use. It exists into its own file due to its size.
We use the term block and buffer interchangeably in this file because one buffer
holds exactly one block of data.
Holding all of the state associated with a block allows us to validate and control
state transitions in a synchronized fashion.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionBufferData(int blockNumber, ByteBuffer buffer) Constructs an instances of this class. -
Method Summary
Modifier and TypeMethodDescriptionintGets the id of this block.Gets the buffer associated with this block.longGets the checksum of data in this block.static longgetChecksum(ByteBuffer buffer) Computes CRC32 checksum of the given buffer's contents.getState()Gets the state of this block.voidsetCaching(Future<Void> actionFuture) Indicates that a caching operation is in progress.voidsetDone()Indicates that this block is no longer of use and can be reclaimed.voidsetPrefetch(Future<Void> actionFuture) Indicates that a prefetch operation is in progress.voidsetReady(BufferData.State... expectedCurrentState) Marks the completion of reading data into the buffer.booleanstateEqualsOneOf(BufferData.State... states) voidthrowIfStateIncorrect(BufferData.State... states) Helper that asserts the current state is one of the expected values.toString()voidupdateState(BufferData.State newState, BufferData.State... expectedCurrentState) Updates the current state to the specified value.
-
Constructor Details
-
BufferData
Constructs an instances of this class.- Parameters:
blockNumber- Number of the block associated with this buffer.buffer- The buffer associated with this block.- Throws:
IllegalArgumentException- if blockNumber is negative.IllegalArgumentException- if buffer is null.
-
-
Method Details
-
getBlockNumber
public int getBlockNumber()Gets the id of this block.- Returns:
- the id of this block.
-
getBuffer
Gets the buffer associated with this block.- Returns:
- the buffer associated with this block.
-
getState
Gets the state of this block.- Returns:
- the state of this block.
-
getChecksum
public long getChecksum()Gets the checksum of data in this block.- Returns:
- the checksum of data in this block.
-
getChecksum
Computes CRC32 checksum of the given buffer's contents.- Parameters:
buffer- the buffer whose content's checksum is to be computed.- Returns:
- the computed checksum.
-
getActionFuture
-
setPrefetch
Indicates that a prefetch operation is in progress.- Parameters:
actionFuture- theFutureof a prefetch action.- Throws:
IllegalArgumentException- if actionFuture is null.
-
setCaching
Indicates that a caching operation is in progress.- Parameters:
actionFuture- theFutureof a caching action.- Throws:
IllegalArgumentException- if actionFuture is null.
-
setReady
Marks the completion of reading data into the buffer. The buffer cannot be modified once in this state.- Parameters:
expectedCurrentState- the collection of states from which transition to READY is allowed.
-
setDone
public void setDone()Indicates that this block is no longer of use and can be reclaimed. -
updateState
Updates the current state to the specified value. Asserts that the current state is as expected.- Parameters:
newState- the state to transition to.expectedCurrentState- the collection of states from which transition tonewStateis allowed.- Throws:
IllegalArgumentException- if newState is null.IllegalArgumentException- if expectedCurrentState is null.
-
throwIfStateIncorrect
Helper that asserts the current state is one of the expected values.- Parameters:
states- the collection of allowed states.- Throws:
IllegalArgumentException- if states is null.
-
stateEqualsOneOf
-
toString
-