- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
AbstractPersistentBlockBuffer,DynamicPersistentBlockBuffer,FixedPersistentBlockBuffer
TODO: Link to RandomAccessPersistentBlockBuffer
interface.- Author:
- AO Industries, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionlongallocate(long minimumSize) Allocates a new block buffer that is at least as large as the requested space.voidbarrier(boolean force) Ensures that all writes before this barrier occur before all writes after this barrier.voidclose()Closes this buffer.voiddeallocate(long id) Deallocates the block with the provided id.voidget(long id, long offset, byte[] buff, int off, int len) Gets bytes from this block.longgetBlockSize(long id) Gets the block size for the provided id.getInputStream(long id, long offset, long length) Gets an input stream that reads from this buffer.intgetInt(long id, long offset) Gets an integer from this block.longgetLong(long id, long offset) Gets a long from this block.getOutputStream(long id, long offset, long length) Gets an output stream that writes to this buffer.Gets the protection level currently implemented by the buffer.booleanisClosed()Checks if this buffer is closed.Iterates over the allocated block IDs in no specific order, with one exception: the first block allocated must be the first block iterated.voidput(long id, long offset, byte[] buff, int off, int len) Puts bytes to this block.voidputInt(long id, long offset, int value) Puts an integer to this block.voidputLong(long id, long offset, long value) Puts a long to this block.
-
Method Details
-
isClosed
boolean isClosed()Checks if this buffer is closed. -
close
Closes this buffer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getProtectionLevel
ProtectionLevel getProtectionLevel()Gets the protection level currently implemented by the buffer.- See Also:
-
barrier
Ensures that all writes before this barrier occur before all writes after this barrier. Ifforceistrue, will also commit to physical media synchronously before returning. This request may be ignored or force downgraded to barrier-only depending on the current protection level.- Throws:
IOException- See Also:
-
iterateBlockIds
Iterates over the allocated block IDs in no specific order, with one exception: the first block allocated must be the first block iterated. This block may contain critical higher-level data structure meta data. If all blocks are deallocated, then the first one added has this same requirement.The
Iterator.remove()method may be used from the iterator in order to deallocate a block. The block allocation should not be modified during the iteration through any means other than the iterator itself. An attempt will be made to throwConcurrentModificationExceptionin this case, but this is only intended to catch bugs.- Throws:
IOException
-
allocate
Allocates a new block buffer that is at least as large as the requested space. The id should always be>= 0, higher level data structures may use the negative values for other purposes, such as indicatingnullwith-1.In order to ensure the block allocation is completely in persistent storage,
barriermust be called. This allows the contents of the block to be written and combined into a singlebarrier(boolean)call. If the system fails beforebarrier(boolean)is called, the block may either be allocated or deallocated - it is up to higher-level data structures to determine which is the case. In no event, however, will failing to callbarrier(boolean)afterallocate(long)cause corruption beyond that just described.This call may fail after the id is allocated and before the id is returned. This will manifest itself as an extra allocated block after recovery.
- Throws:
IOException
-
deallocate
Deallocates the block with the provided id. The ids of other blocks will not be altered. The space may later be reallocated with the same, or possibly different id. The space may also be reclaimed.barrierdoes not need to be called after a deallocation, but if not called previously deallocated blocks may reappear after a system failure. It is up to higher-level data structures to detect this. In no event, however, will failing to callbarrier(boolean)afterdeallocate(long)cause corruption beyond that just described.- Throws:
IllegalStateException- if the block is not allocated.IOException
-
getBlockSize
Gets the block size for the provided id.- Throws:
IOException
-
get
Gets bytes from this block. Bounds checking is performed only when assertions are enabled.- Throws:
IOException
-
getInt
Gets an integer from this block. Bounds checking is performed only when assertions are enabled.- Throws:
IOException
-
getLong
Gets a long from this block. Bounds checking is performed only when assertions are enabled.- Throws:
IOException
-
getInputStream
Gets an input stream that reads from this buffer. Bounds checking is performed only when assertions are enabled.- Throws:
IOException
-
put
Puts bytes to this block. Bounds checking is performed only when assertions are enabled.- Throws:
BufferOverflowException- when out of rangeIOException
-
putInt
Puts an integer to this block. Bounds checking is performed only when assertions are enabled.- Throws:
BufferOverflowException- when out of rangeIOException
-
putLong
Puts a long to this block. Bounds checking is performed only when assertions are enabled.- Throws:
BufferOverflowException- when out of rangeIOException
-
getOutputStream
Gets an output stream that writes to this buffer. Bounds checking is performed only when assertions are enabled.- Throws:
BufferOverflowException- when out of rangeIOException
-
