Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public class FixedPersistentBlockBuffer extends AbstractPersistentBlockBuffer
Treats a PersistentBuffer as a set of allocatable blocks.
Each block is stored in a block of fixed size. The first block has an id
of zero, and the blocks go up by ones. The storage address is determined
from this logical id on the fly. The storage address and the block address
are not the same.
One block of free space map preceeds a set of blocks. However, with exceptionally large block sizes, the free space map will be smaller. The free space map is the maximum size of the block size and 2^n, where n+(ceil(log(2)(blockSize)))=63. The result is that the minimum free space map size will be used to address the entire 2^63-1 address space.
The switchover point is at one gigabyte block size (2^30). The total of 2^63 address space may contain a maximum of 2^33 of these blocks. Each block consumes one bit of the space, the 2^30 bitmap block may contain a total of 2^33 bits, an exact match for the number of blocks.
A final example is for a 16 GB block size (2^34). The total of 2^63 address space may contain a maximum of 2^29 of these blocks. Each block consumes one bit of the space, thus the free space map only needs to contain 2^26 bytes to cover the entire address space.
pbuffer| Constructor and Description |
|---|
FixedPersistentBlockBuffer(PersistentBuffer pbuffer,
long blockSize)
Creates a persistent buffer with the provided block size.
|
| Modifier and Type | Method and Description |
|---|---|
long |
allocate(long minimumSize)
Allocates a block.
|
void |
deallocate(long id)
Deallocates the block for the provided id.
|
protected void |
ensureCapacity(long capacity)
This class takes a lazy approach on allocating buffer space.
|
protected void |
expandCapacity(long oldCapacity,
long newCapacity) |
protected long |
getBlockAddress(long id)
Gets the address that stores the beginning of the block with the provided id.
|
long |
getBlockSize(long id)
Gets the block size for the provided id.
|
Iterator<Long> |
iterateBlockIds()
Iterates over the allocated block IDs in no specific order, with one
exception: the first block allocated must be the first block iterated.
|
barrier, close, get, getInputStream, getInt, getLong, getOutputStream, getProtectionLevel, isClosed, isInBounds, put, putInt, putLongpublic FixedPersistentBlockBuffer(PersistentBuffer pbuffer, long blockSize) throws IOException
pbuffer - blockSize - IOExceptionprotected long getBlockAddress(long id)
getBlockAddress in class AbstractPersistentBlockBufferpublic long allocate(long minimumSize)
throws IOException
barriers.IOExceptionpublic void deallocate(long id)
throws IOException
barriers.IOExceptionpublic Iterator<Long> iterateBlockIds()
PersistentBlockBufferIterates 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 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 throw ConcurrentModificationException
in this case, but this is only intended to catch bugs.
public long getBlockSize(long id)
PersistentBlockBufferprotected void expandCapacity(long oldCapacity,
long newCapacity)
throws IOException
IOExceptionprotected void ensureCapacity(long capacity)
throws IOException
ensureCapacity in class AbstractPersistentBlockBufferIOExceptionCopyright © 2000–2016 AO Industries, Inc.. All rights reserved.