java.lang.Object
com.aoapps.persistence.PersistentCollections
A set of static utility methods to help in the selection, creation, and management
of persistent collections.
- Author:
- AO Industries, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
ensureZeros
(RandomAccessFile raf, long position, long count) Writes the requested number of zeros to the provided RandomAccessFile, but only if they do not already contain zeros.static boolean
ensureZeros
(ByteBuffer byteBuffer, int position, int count) Stores the requested number of zeros to the provided ByteBuffer, but only if they do not already contain zeros.static PersistentBlockBuffer
getPersistentBlockBuffer
(Serializer<?> serializer, PersistentBuffer pbuffer, long additionalBlockSpace) Gets the most efficientPersistentBlockBuffer
for the provided providedSerializer
.static PersistentBuffer
getPersistentBuffer
(long maximumCapacity) Selects the most efficient temporaryPersistentBuffer
for the current machine and the provided maximum buffer size.static PersistentBuffer
getPersistentBuffer
(RandomAccessFile raf, ProtectionLevel protectionLevel, long maximumCapacity) Selects the most efficientPersistentBuffer
for the current machine and the provided maximum buffer size.static <E> Serializer
<E> getSerializer
(Class<E> type) Selects the most efficientSerializer
for the provided class.
-
Method Details
-
ensureZeros
public static boolean ensureZeros(RandomAccessFile raf, long position, long count) throws IOException Writes the requested number of zeros to the provided RandomAccessFile, but only if they do not already contain zeros. This is to avoid unnecessary writes on flash media. This may also have a positive interaction with sparse files.- Returns:
- true when the byteBuffer was written to
- Throws:
IOException
-
ensureZeros
Stores the requested number of zeros to the provided ByteBuffer, but only if they do not already contain zeros. This is to avoid unnecessary writes on flash media. This may also have a positive interaction with sparse files.- Returns:
- true when the byteBuffer was written to
-
getPersistentBuffer
Selects the most efficient temporaryPersistentBuffer
for the current machine and the provided maximum buffer size. The buffer will be backed by a temporary file that will be deleted on buffer close or JVM shutdown. The protection level will beProtectionLevel.NONE
. The order of preference is:- Parameters:
maximumCapacity
- The maximum size of data that may be stored in the buffer. To ensure no limits, useLong.MAX_VALUE
.- Throws:
IOException
-
getPersistentBuffer
public static PersistentBuffer getPersistentBuffer(RandomAccessFile raf, ProtectionLevel protectionLevel, long maximumCapacity) throws IOException Selects the most efficientPersistentBuffer
for the current machine and the provided maximum buffer size. The order of preference is:- Parameters:
maximumCapacity
- The maximum size of data that may be stored in the buffer. If the random access file is larger than this value, the length of the file is used instead. To ensure no limits, useLong.MAX_VALUE
.- Throws:
IOException
-
getSerializer
Selects the most efficientSerializer
for the provided class. -
getPersistentBlockBuffer
public static PersistentBlockBuffer getPersistentBlockBuffer(Serializer<?> serializer, PersistentBuffer pbuffer, long additionalBlockSpace) throws IOException Gets the most efficientPersistentBlockBuffer
for the provided providedSerializer
. If using fixed record sizes, the size of the block buffer is rounded up to the nearest power of two, to help alignment with system page tables.- Parameters:
serializer
- TheSerializer
that will be used to write to the blockspbuffer
- ThePersistentBuffer
that will be wrapped by the block bufferadditionalBlockSpace
- The maximum additional space needed beyond the space used by the serializer. This may be used for linked list pointers, for example.- Throws:
IOException
-