java.lang.Object
com.aoapps.persistence.AbstractPersistentBlockBuffer
- All Implemented Interfaces:
PersistentBlockBuffer
,Closeable
,AutoCloseable
- Direct Known Subclasses:
DynamicPersistentBlockBuffer
,FixedPersistentBlockBuffer
Base class for any implementation that treats a
PersistentBuffer
as a set of allocatable blocks.- Author:
- AO Industries, Inc.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
barrier
(boolean force) Ensures that all writes before this barrier occur before all writes after this barrier.protected void
checkBounds
(long id, long offset, long len) Checks that a request is within the bounds of the block.void
close()
Closes this buffer.protected abstract void
ensureCapacity
(long capacity) Ensures the underlying persistent buffer is of adequate capacity.void
get
(long id, long offset, byte[] buff, int off, int len) Gets bytes from this block.protected abstract long
getBlockAddress
(long id) Gets the address of the block in the underlying persistent buffer.getInputStream
(long id, long offset, long length) Gets an input stream that reads from this buffer.int
getInt
(long id, long offset) Gets an integer from this block.long
getLong
(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.boolean
isClosed()
Checks if this buffer is closed.void
put
(long id, long offset, byte[] buff, int off, int len) Puts bytes to this block.void
putInt
(long id, long offset, int value) Puts an integer to this block.void
putLong
(long id, long offset, long value) Puts a long to this block.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.aoapps.persistence.PersistentBlockBuffer
allocate, deallocate, getBlockSize, iterateBlockIds
-
Field Details
-
pbuffer
-
-
Constructor Details
-
AbstractPersistentBlockBuffer
-
-
Method Details
-
isClosed
public boolean isClosed()Description copied from interface:PersistentBlockBuffer
Checks if this buffer is closed.- Specified by:
isClosed
in interfacePersistentBlockBuffer
-
close
Description copied from interface:PersistentBlockBuffer
Closes this buffer.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfacePersistentBlockBuffer
- Throws:
IOException
-
getProtectionLevel
Description copied from interface:PersistentBlockBuffer
Gets the protection level currently implemented by the buffer.- Specified by:
getProtectionLevel
in interfacePersistentBlockBuffer
- See Also:
-
barrier
Description copied from interface:PersistentBlockBuffer
Ensures that all writes before this barrier occur before all writes after this barrier. Ifforce
istrue
, 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.- Specified by:
barrier
in interfacePersistentBlockBuffer
- Throws:
IOException
- See Also:
-
checkBounds
protected void checkBounds(long id, long offset, long len) throws IllegalArgumentException, IOException Checks that a request is within the bounds of the block.- Throws:
IllegalArgumentException
IOException
-
get
Description copied from interface:PersistentBlockBuffer
Gets bytes from this block. Bounds checking is performed only when assertions are enabled.- Specified by:
get
in interfacePersistentBlockBuffer
- Throws:
IOException
-
getInt
Description copied from interface:PersistentBlockBuffer
Gets an integer from this block. Bounds checking is performed only when assertions are enabled.- Specified by:
getInt
in interfacePersistentBlockBuffer
- Throws:
IOException
-
getLong
Description copied from interface:PersistentBlockBuffer
Gets a long from this block. Bounds checking is performed only when assertions are enabled.- Specified by:
getLong
in interfacePersistentBlockBuffer
- Throws:
IOException
-
getInputStream
Description copied from interface:PersistentBlockBuffer
Gets an input stream that reads from this buffer. Bounds checking is performed only when assertions are enabled.- Specified by:
getInputStream
in interfacePersistentBlockBuffer
- Throws:
IOException
-
put
Description copied from interface:PersistentBlockBuffer
Puts bytes to this block. Bounds checking is performed only when assertions are enabled.- Specified by:
put
in interfacePersistentBlockBuffer
- Throws:
IOException
-
putInt
Description copied from interface:PersistentBlockBuffer
Puts an integer to this block. Bounds checking is performed only when assertions are enabled.- Specified by:
putInt
in interfacePersistentBlockBuffer
- Throws:
IOException
-
putLong
Description copied from interface:PersistentBlockBuffer
Puts a long to this block. Bounds checking is performed only when assertions are enabled.- Specified by:
putLong
in interfacePersistentBlockBuffer
- Throws:
IOException
-
getOutputStream
Description copied from interface:PersistentBlockBuffer
Gets an output stream that writes to this buffer. Bounds checking is performed only when assertions are enabled.- Specified by:
getOutputStream
in interfacePersistentBlockBuffer
- Throws:
IOException
-
getBlockAddress
Gets the address of the block in the underlying persistent buffer. This should only be called for allocated blocks, implementations should check this with assertions.- Throws:
IOException
-
ensureCapacity
Ensures the underlying persistent buffer is of adequate capacity. Grows the underlying storage if needed.- Throws:
IOException
-