Package org.apache.hadoop.fs.store
Class DataBlocks.DataBlock
java.lang.Object
org.apache.hadoop.fs.store.DataBlocks.DataBlock
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
- DataBlocks
This represents a block being uploaded.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidA block has been allocated.protected voidA block has been released.voidclose()abstract intdataSize()Return the current data size.protected booleanEnter the closed state.protected final voidAtomically enter a state, verifying current state.voidflush()Flush the output.longgetIndex()getState()Current state.protected BlockUploadStatisticsbooleanhasData()Predicate to check if there is data in the block.protected voidInner close logic for subclasses to implement.abstract intThe remaining capacity in the block before it is full.Switch to the upload state and return a stream for uploading.protected final voidverifyState(DataBlocks.DataBlock.DestState expected) Verify that the block is in the declared state.intwrite(byte[] buffer, int offset, int length) Write a series of bytes from the buffer, from the offset.
-
Constructor Details
-
DataBlock
-
-
Method Details
-
enterState
protected final void enterState(DataBlocks.DataBlock.DestState current, DataBlocks.DataBlock.DestState next) throws IllegalStateException Atomically enter a state, verifying current state.- Parameters:
current- current state. null means "no check"next- next state- Throws:
IllegalStateException- if the current state is not as expected
-
verifyState
protected final void verifyState(DataBlocks.DataBlock.DestState expected) throws IllegalStateException Verify that the block is in the declared state.- Parameters:
expected- expected state.- Throws:
IllegalStateException- if the DataBlock is in the wrong state
-
getState
Current state.- Returns:
- the current state.
-
dataSize
public abstract int dataSize()Return the current data size.- Returns:
- the size of the data.
-
hasData
public boolean hasData()Predicate to check if there is data in the block.- Returns:
- true if there is
-
remainingCapacity
public abstract int remainingCapacity()The remaining capacity in the block before it is full.- Returns:
- the number of bytes remaining.
-
write
Write a series of bytes from the buffer, from the offset. Returns the number of bytes written. Only valid in the stateWriting. Base class verifies the state but does no writing.- Parameters:
buffer- buffer.offset- offset.length- length of write.- Returns:
- number of bytes written.
- Throws:
IOException- trouble
-
flush
Flush the output. Only valid in the stateWriting. In the base class, this is a no-op- Throws:
IOException- any IO problem.
-
startUpload
Switch to the upload state and return a stream for uploading. Base class callsenterState(DestState, DestState)to manage the state machine.- Returns:
- the stream.
- Throws:
IOException- trouble
-
enterClosedState
protected boolean enterClosedState()Enter the closed state.- Returns:
- true if the class was in any other state, implying that the subclass should do its close operations.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
innerClose
Inner close logic for subclasses to implement.- Throws:
IOException- raised on errors performing I/O.
-
blockAllocated
protected void blockAllocated()A block has been allocated. -
blockReleased
protected void blockReleased()A block has been released. -
getStatistics
-
getIndex
public long getIndex()
-