Class PhantomReferenceLimitedPageSource
- java.lang.Object
-
- org.terracotta.offheapstore.paging.PhantomReferenceLimitedPageSource
-
- All Implemented Interfaces:
PageSource
public class PhantomReferenceLimitedPageSource extends java.lang.Object implements PageSource
APhantomReferencebased limited byte buffer source.This buffer source tracks 'freeing' of allocated byte buffers using phantom references to the allocated buffers and an associated reference queue. An
AtomicLongis then used to track number of available bytes for allocation.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ref.ReferenceQueue<java.nio.ByteBuffer>allocatedBuffersprivate java.util.Map<java.lang.ref.PhantomReference<java.nio.ByteBuffer>,java.lang.Integer>bufferSizesprivate java.util.concurrent.atomic.AtomicLongmax
-
Constructor Summary
Constructors Constructor Description PhantomReferenceLimitedPageSource(long max)Create a source that will allocate at mostmaxbytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pageallocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner)Allocates a byte buffer of the given size.voidfree(Page buffer)Frees the supplied buffer.private voidprocessQueue()java.lang.StringtoString()
-
-
-
Method Detail
-
allocate
public Page allocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner)
Allocates a byte buffer of the given size.This
BufferSourceplaces no restrictions on the requested size of the buffer.- Specified by:
allocatein interfacePageSource- Parameters:
size- size of page to allocatethief-trueif the allocation can steal space from victimsvictim-trueif the allocated page should be eligible for stealingowner- owner from which subsequent steal should occur- Returns:
- an allocated page, or
nullin the case of failure
-
free
public void free(Page buffer)
Frees the supplied buffer.This implementation is a no-op, no validation of the supplied buffer is attempted, as freeing of allocated buffers is monitored via phantom references.
- Specified by:
freein interfacePageSource
-
processQueue
private void processQueue()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-