Package one.nio.mem
Class OffheapMap<K,V>
- java.lang.Object
-
- one.nio.mem.OffheapMap<K,V>
-
- All Implemented Interfaces:
OffheapMapMXBean
- Direct Known Subclasses:
OffheapBlobMap,SharedMemoryMap
public abstract class OffheapMap<K,V> extends Object implements OffheapMapMXBean
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classOffheapMap.BasicCleanupstatic classOffheapMap.Record<K,V>classOffheapMap.SamplingCleanupstatic interfaceOffheapMap.Visitor<K,V>static classOffheapMap.WritableRecord<K,V>static interfaceOffheapMap.WritableVisitor<K,V>
-
Field Summary
Fields Modifier and Type Field Description protected static longbyteArrayOffsetprotected intcapacityprotected longcleanupIntervalprotected OffheapMap.BasicCleanupcleanupThreadprotected doublecleanupThresholdprotected static intCONCURRENCY_LEVELprotected AtomicIntegercountprotected AtomicLongexpirationsprotected static intHASH_OFFSETprotected static intHEADER_SIZEprotected RWLock[]locksprotected longlockWaitTimeprotected static org.slf4j.Loggerlogprotected longmapBaseprotected intmaxSamplesprotected static longMBprotected longminTimeToLiveprotected static intNEXT_OFFSETprotected static intTIME_OFFSETprotected longtimeToLiveprotected static sun.misc.Unsafeunsafe
-
Constructor Summary
Constructors Modifier Constructor Description protectedOffheapMap(int capacity)protectedOffheapMap(int capacity, long address)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract longallocateEntry(K key, long hashCode, int size)protected longbucketFor(long hashCode)voidclear()voidclose()protected voidcloseInternal()protected abstract voiddestroyEntry(long entry)intentriesToClean()protected abstract booleanequalsAt(long entry, K key)Vget(K key)intgetCapacity()longgetCleanupInterval()doublegetCleanupThreshold()intgetCount()longgetExpirations()longgetLockWaitTime()intgetMaxSamples()longgetMinTimeToLive()longgetTimeToLive()protected abstract longhashCode(K key)protected booleanisExpired(long entry, boolean touch)voiditerate(OffheapMap.Visitor<K,V> visitor)voiditerate(OffheapMap.Visitor<K,V> visitor, int workers)voiditerate(OffheapMap.Visitor<K,V> visitor, int start, int end, int step)voiditerate(OffheapMap.WritableVisitor<K,V> visitor)voiditerate(OffheapMap.WritableVisitor<K,V> visitor, int workers)voiditerate(OffheapMap.WritableVisitor<K,V> visitor, int start, int end, int step)protected KkeyAt(long entry)protected RWLocklockFor(long hashCode)OffheapMap.Record<K,V>lockRecordForRead(K key)OffheapMap.Record<K,V>lockRecordForRead(K key, long timeout)OffheapMap.WritableRecord<K,V>lockRecordForWrite(K key, boolean create)OffheapMap.WritableRecord<K,V>lockRecordForWrite(K key, long timeout, boolean create)booleanput(K key, V value)booleanputIfAbsent(K key, V value)booleanremove(K key)intremoveExpired(long expirationAge)protected booleanreuseEntry(long entry, int newSize)voidsetCleanupInterval(long cleanupInterval)voidsetCleanupThreshold(double cleanupThreshold)voidsetLockWaitTime(long lockWaitTime)voidsetMaxSamples(int maxSamples)voidsetMinTimeToLive(long minTimeToLive)protected voidsetTimeAt(long entry)protected voidsetTimeAt(long entry, long time)voidsetTimeToLive(long timeToLive)protected abstract voidsetValueAt(long entry, V value)protected booleanshouldCleanup(long entry, long expirationTime)protected abstract intsizeOf(long entry)protected abstract intsizeOf(V value)protected longtimeAt(long entry)voidtouch(K key)protected abstract VvalueAt(long entry)
-
-
-
Field Detail
-
log
protected static final org.slf4j.Logger log
-
unsafe
protected static final sun.misc.Unsafe unsafe
-
byteArrayOffset
protected static final long byteArrayOffset
-
MB
protected static final long MB
- See Also:
- Constant Field Values
-
CONCURRENCY_LEVEL
protected static final int CONCURRENCY_LEVEL
- See Also:
- Constant Field Values
-
HASH_OFFSET
protected static final int HASH_OFFSET
- See Also:
- Constant Field Values
-
NEXT_OFFSET
protected static final int NEXT_OFFSET
- See Also:
- Constant Field Values
-
TIME_OFFSET
protected static final int TIME_OFFSET
- See Also:
- Constant Field Values
-
HEADER_SIZE
protected static final int HEADER_SIZE
- See Also:
- Constant Field Values
-
capacity
protected final int capacity
-
count
protected final AtomicInteger count
-
expirations
protected final AtomicLong expirations
-
locks
protected final RWLock[] locks
-
mapBase
protected long mapBase
-
timeToLive
protected long timeToLive
-
minTimeToLive
protected long minTimeToLive
-
lockWaitTime
protected long lockWaitTime
-
cleanupInterval
protected long cleanupInterval
-
cleanupThreshold
protected double cleanupThreshold
-
maxSamples
protected int maxSamples
-
cleanupThread
protected OffheapMap.BasicCleanup cleanupThread
-
-
Method Detail
-
close
public final void close()
-
closeInternal
protected void closeInternal()
-
getTimeToLive
public long getTimeToLive()
- Specified by:
getTimeToLivein interfaceOffheapMapMXBean
-
setTimeToLive
public void setTimeToLive(long timeToLive)
- Specified by:
setTimeToLivein interfaceOffheapMapMXBean
-
getMinTimeToLive
public long getMinTimeToLive()
- Specified by:
getMinTimeToLivein interfaceOffheapMapMXBean
-
setMinTimeToLive
public void setMinTimeToLive(long minTimeToLive)
- Specified by:
setMinTimeToLivein interfaceOffheapMapMXBean
-
getLockWaitTime
public long getLockWaitTime()
- Specified by:
getLockWaitTimein interfaceOffheapMapMXBean
-
setLockWaitTime
public void setLockWaitTime(long lockWaitTime)
- Specified by:
setLockWaitTimein interfaceOffheapMapMXBean
-
getCleanupInterval
public long getCleanupInterval()
- Specified by:
getCleanupIntervalin interfaceOffheapMapMXBean
-
setCleanupInterval
public void setCleanupInterval(long cleanupInterval)
- Specified by:
setCleanupIntervalin interfaceOffheapMapMXBean
-
getCleanupThreshold
public double getCleanupThreshold()
- Specified by:
getCleanupThresholdin interfaceOffheapMapMXBean
-
setCleanupThreshold
public void setCleanupThreshold(double cleanupThreshold)
- Specified by:
setCleanupThresholdin interfaceOffheapMapMXBean
-
getMaxSamples
public int getMaxSamples()
- Specified by:
getMaxSamplesin interfaceOffheapMapMXBean
-
setMaxSamples
public void setMaxSamples(int maxSamples)
- Specified by:
setMaxSamplesin interfaceOffheapMapMXBean
-
getCapacity
public int getCapacity()
- Specified by:
getCapacityin interfaceOffheapMapMXBean
-
getCount
public int getCount()
- Specified by:
getCountin interfaceOffheapMapMXBean
-
getExpirations
public long getExpirations()
- Specified by:
getExpirationsin interfaceOffheapMapMXBean
-
put
public boolean put(K key, V value) throws OutOfMemoryException
- Throws:
OutOfMemoryException
-
putIfAbsent
public boolean putIfAbsent(K key, V value) throws OutOfMemoryException
- Throws:
OutOfMemoryException
-
remove
public boolean remove(K key)
-
touch
public void touch(K key)
-
lockRecordForRead
public OffheapMap.Record<K,V> lockRecordForRead(K key, long timeout) throws TimeoutException
- Throws:
TimeoutException
-
lockRecordForRead
public OffheapMap.Record<K,V> lockRecordForRead(K key)
-
lockRecordForWrite
public OffheapMap.WritableRecord<K,V> lockRecordForWrite(K key, long timeout, boolean create) throws TimeoutException
- Throws:
TimeoutException
-
lockRecordForWrite
public OffheapMap.WritableRecord<K,V> lockRecordForWrite(K key, boolean create)
-
entriesToClean
public int entriesToClean()
-
removeExpired
public int removeExpired(long expirationAge)
-
clear
public void clear()
-
iterate
public void iterate(OffheapMap.Visitor<K,V> visitor)
-
iterate
public void iterate(OffheapMap.Visitor<K,V> visitor, int workers)
-
iterate
public void iterate(OffheapMap.Visitor<K,V> visitor, int start, int end, int step)
-
iterate
public void iterate(OffheapMap.WritableVisitor<K,V> visitor)
-
iterate
public void iterate(OffheapMap.WritableVisitor<K,V> visitor, int workers)
-
iterate
public void iterate(OffheapMap.WritableVisitor<K,V> visitor, int start, int end, int step)
-
bucketFor
protected long bucketFor(long hashCode)
-
lockFor
protected RWLock lockFor(long hashCode)
-
timeAt
protected long timeAt(long entry)
-
setTimeAt
protected void setTimeAt(long entry)
-
setTimeAt
protected void setTimeAt(long entry, long time)
-
isExpired
protected boolean isExpired(long entry, boolean touch)
-
shouldCleanup
protected boolean shouldCleanup(long entry, long expirationTime)
-
keyAt
protected K keyAt(long entry)
-
reuseEntry
protected boolean reuseEntry(long entry, int newSize)
-
hashCode
protected abstract long hashCode(K key)
-
equalsAt
protected abstract boolean equalsAt(long entry, K key)
-
valueAt
protected abstract V valueAt(long entry)
-
setValueAt
protected abstract void setValueAt(long entry, V value)
-
allocateEntry
protected abstract long allocateEntry(K key, long hashCode, int size) throws OutOfMemoryException
- Throws:
OutOfMemoryException
-
destroyEntry
protected abstract void destroyEntry(long entry)
-
sizeOf
protected abstract int sizeOf(long entry)
-
sizeOf
protected abstract int sizeOf(V value)
-
-