Package com.automation_pros.odva.util
Class ByteBuffersSoftCache
- java.lang.Object
-
- com.automation_pros.odva.util.SizedSoftCache<java.nio.ByteBuffer>
-
- com.automation_pros.odva.util.ByteBuffersSoftCache
-
public class ByteBuffersSoftCache extends SizedSoftCache<java.nio.ByteBuffer>
-
-
Field Summary
-
Fields inherited from class com.automation_pros.odva.util.SizedSoftCache
FullName, identity, minimum, sizedCaches, sLogger, traceIndex
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.nio.ByteBuffer
create(int size)
When the cache runs empty, further allocations must create new objects.protected int
dynamicEach(int size)
Implementations must provide a function that estimates the GC impact of an instance of a given size.static java.nio.ByteBuffer
get(int size)
Obtain a ByteBuffer instance with a capacity at least the given size.protected boolean
qualified(java.nio.ByteBuffer recycled)
An item returned from a user might have been changed in a way that makes it unsuitable for reuse.static void
release(java.nio.ByteBuffer recycle)
protected int
sizeOf(java.nio.ByteBuffer recycle)
When an object is freed for recycling, its size must be examined to determine the appropriate nested cache to use, and whether it exactly matches that cache.-
Methods inherited from class com.automation_pros.odva.util.SizedSoftCache
allocate, free, normalizedSize
-
-
-
-
Method Detail
-
get
public static java.nio.ByteBuffer get(int size)
Obtain a ByteBuffer instance with a capacity at least the given size. It will be recycled back into this cache by the garbage collector if memory pressure permits.As this library mostly deals with little-endian data, the returned ByteBuffer is configured with that order.
- Parameters:
size
-- Returns:
-
release
public static void release(java.nio.ByteBuffer recycle)
-
dynamicEach
protected int dynamicEach(int size)
Description copied from class:SizedSoftCache
Implementations must provide a function that estimates the GC impact of an instance of a given size.- Specified by:
dynamicEach
in classSizedSoftCache<java.nio.ByteBuffer>
- Returns:
-
sizeOf
protected int sizeOf(java.nio.ByteBuffer recycle)
Description copied from class:SizedSoftCache
When an object is freed for recycling, its size must be examined to determine the appropriate nested cache to use, and whether it exactly matches that cache.- Specified by:
sizeOf
in classSizedSoftCache<java.nio.ByteBuffer>
- Returns:
- The actual size of the object to recycle.
-
qualified
protected boolean qualified(java.nio.ByteBuffer recycled)
Description copied from class:SizedSoftCache
An item returned from a user might have been changed in a way that makes it unsuitable for reuse. This method gives the implementation a chance to verify that and/or make corrections.- Specified by:
qualified
in classSizedSoftCache<java.nio.ByteBuffer>
- Parameters:
recycled
- The subject item that is to be placed back in this cache's fast access list.- Returns:
- True if ready for re-use, false if to be discarded.
-
create
protected java.nio.ByteBuffer create(int size)
Description copied from class:SizedSoftCache
When the cache runs empty, further allocations must create new objects. Since the queue is based on soft references, the garbage collector can throw some away at will.- Specified by:
create
in classSizedSoftCache<java.nio.ByteBuffer>
- Returns:
-
-