Package org.apache.ignite.cache.eviction
Class AbstractEvictionPolicy<K,V>
- java.lang.Object
-
- org.apache.ignite.cache.eviction.AbstractEvictionPolicy<K,V>
-
- All Implemented Interfaces:
Externalizable,Serializable,EvictionPolicy<K,V>
- Direct Known Subclasses:
FifoEvictionPolicy,LruEvictionPolicy,SortedEvictionPolicy
public abstract class AbstractEvictionPolicy<K,V> extends Object implements EvictionPolicy<K,V>, Externalizable
Common functionality implementation for eviction policies with max size/max memory and batch eviction support.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractEvictionPolicy()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intgetBatchSize()Gets batch size.longgetCurrentMemorySize()Gets current queue size in bytes.protected abstract intgetCurrentSize()longgetMaxMemorySize()Gets maximum allowed cache size in bytes.intgetMaxSize()Gets maximum allowed size of cache before entry will start getting evicted.voidonEntryAccessed(boolean rmv, EvictableEntry<K,V> entry)Callback for whenever entry is accessed.voidreadExternal(ObjectInput in)protected abstract booleanremoveMeta(Object meta)AbstractEvictionPolicy<K,V>setBatchSize(int batchSize)Sets batch size.AbstractEvictionPolicy<K,V>setMaxMemorySize(long maxMemSize)Sets maximum allowed cache size in bytes.AbstractEvictionPolicy<K,V>setMaxSize(int max)Sets maximum allowed size of cache before entry will start getting evicted.protected voidshrink()Shrinks backed container to maximum allowed size.protected abstract intshrink0()protected abstract booleantouch(EvictableEntry<K,V> entry)voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
memSize
protected final LongAdder memSize
Memory size occupied by elements in container.
-
-
Method Detail
-
shrink
protected void shrink()
Shrinks backed container to maximum allowed size.
-
onEntryAccessed
public void onEntryAccessed(boolean rmv, EvictableEntry<K,V> entry)Callback for whenever entry is accessed.- Specified by:
onEntryAccessedin interfaceEvictionPolicy<K,V>- Parameters:
rmv-Trueif entry has been removed,falseotherwise.entry- Accessed entry.
-
getCurrentSize
protected abstract int getCurrentSize()
- Returns:
- Size of the container with trackable entries.
-
shrink0
protected abstract int shrink0()
- Returns:
- Size of the memory which was shrinked.
-
removeMeta
protected abstract boolean removeMeta(Object meta)
- Parameters:
meta- Meta-information shipped to an entry.- Returns:
Trueif meta was successfully removed from the container.
-
touch
protected abstract boolean touch(EvictableEntry<K,V> entry)
- Parameters:
entry- Entry to touch.- Returns:
Trueif container has been changed by this call.
-
setMaxMemorySize
public AbstractEvictionPolicy<K,V> setMaxMemorySize(long maxMemSize)
Sets maximum allowed cache size in bytes.- Parameters:
maxMemSize- Maximum allowed cache size in bytes.- Returns:
thisfor chaining.
-
getMaxMemorySize
public long getMaxMemorySize()
Gets maximum allowed cache size in bytes.- Returns:
- maximum allowed cache size in bytes.
-
getCurrentMemorySize
public long getCurrentMemorySize()
Gets current queue size in bytes.- Returns:
- current queue size in bytes.
-
setMaxSize
public AbstractEvictionPolicy<K,V> setMaxSize(int max)
Sets maximum allowed size of cache before entry will start getting evicted.- Parameters:
max- Maximum allowed size of cache before entry will start getting evicted.- Returns:
thisfor chaining.
-
getMaxSize
public int getMaxSize()
Gets maximum allowed size of cache before entry will start getting evicted.- Returns:
- Maximum allowed size of cache before entry will start getting evicted.
-
setBatchSize
public AbstractEvictionPolicy<K,V> setBatchSize(int batchSize)
Sets batch size.- Parameters:
batchSize- Batch size.- Returns:
thisfor chaining.
-
getBatchSize
public int getBatchSize()
Gets batch size.- Returns:
- batch size.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
-