Class SortedEvictionPolicy<K,V>
- java.lang.Object
-
- org.apache.ignite.cache.eviction.AbstractEvictionPolicy<K,V>
-
- org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicy<K,V>
-
- All Implemented Interfaces:
Externalizable,Serializable,EvictionPolicy<K,V>,IgniteMBeanAware
public class SortedEvictionPolicy<K,V> extends AbstractEvictionPolicy<K,V> implements IgniteMBeanAware
Cache eviction policy which will select the minimum cache entry for eviction.The eviction starts in the following cases:
- The cache size becomes
batchSizeelements greater than the maximum size. - The size of cache entries in bytes becomes greater than the maximum memory size. The size of cache entry calculates as sum of key size and value size.
maxMemSize == 0).batchSizeelements will be evicted in this case. The defaultbatchSizevalue is1.Entries comparison based on
Comparatorinstance if provided. DefaultComparatorbehaviour is use cache entries keys for comparison that imposes a requirement for keys to implementComparableinterface.User defined comparator should implement
Serializableinterface.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.ignite.cache.eviction.AbstractEvictionPolicy
memSize
-
-
Constructor Summary
Constructors Constructor Description SortedEvictionPolicy()Constructs sorted eviction policy with all defaults.SortedEvictionPolicy(int max)Constructs sorted eviction policy with maximum size.SortedEvictionPolicy(int max, int batchSize, @Nullable Comparator<EvictableEntry<K,V>> comp)Constructs sorted eviction policy with given maximum size, eviction batch size and entries comparator.SortedEvictionPolicy(int max, @Nullable Comparator<EvictableEntry<K,V>> comp)Constructs sorted eviction policy with given maximum size and given entry comparator.SortedEvictionPolicy(@Nullable Comparator<EvictableEntry<K,V>> comp)Constructs sorted eviction policy with given maximum size and given entry comparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCurrentSize()ObjectgetMBean()Collection<EvictableEntry<K,V>>queue()Gets read-only view of backed queue in proper order.voidreadExternal(ObjectInput in)protected booleanremoveMeta(Object meta)Removes holder from backed queue and marks holder as removed.SortedEvictionPolicy<K,V>setBatchSize(int batchSize)Sets batch size.SortedEvictionPolicy<K,V>setMaxMemorySize(long maxMemSize)Sets maximum allowed cache size in bytes.SortedEvictionPolicy<K,V>setMaxSize(int max)Sets maximum allowed size of cache before entry will start getting evicted.protected intshrink0()Tries to remove one item from queue.protected booleantouch(EvictableEntry<K,V> entry)voidwriteExternal(ObjectOutput out)-
Methods inherited from class org.apache.ignite.cache.eviction.AbstractEvictionPolicy
getBatchSize, getCurrentMemorySize, getMaxMemorySize, getMaxSize, onEntryAccessed, shrink
-
-
-
-
Constructor Detail
-
SortedEvictionPolicy
public SortedEvictionPolicy()
Constructs sorted eviction policy with all defaults.
-
SortedEvictionPolicy
public SortedEvictionPolicy(int max)
Constructs sorted eviction policy with maximum size.- Parameters:
max- Maximum allowed size of cache before entry will start getting evicted.
-
SortedEvictionPolicy
public SortedEvictionPolicy(int max, @Nullable @Nullable Comparator<EvictableEntry<K,V>> comp)Constructs sorted eviction policy with given maximum size and given entry comparator.- Parameters:
max- Maximum allowed size of cache before entry will start getting evicted.comp- Entries comparator.
-
SortedEvictionPolicy
public SortedEvictionPolicy(int max, int batchSize, @Nullable @Nullable Comparator<EvictableEntry<K,V>> comp)Constructs sorted eviction policy with given maximum size, eviction batch size and entries comparator.- Parameters:
max- Maximum allowed size of cache before entry will start getting evicted.batchSize- Batch size.comp- Entries comparator.
-
SortedEvictionPolicy
public SortedEvictionPolicy(@Nullable @Nullable Comparator<EvictableEntry<K,V>> comp)Constructs sorted eviction policy with given maximum size and given entry comparator.- Parameters:
comp- Entries comparator.
-
-
Method Detail
-
setMaxMemorySize
public SortedEvictionPolicy<K,V> setMaxMemorySize(long maxMemSize)
Sets maximum allowed cache size in bytes.- Overrides:
setMaxMemorySizein classAbstractEvictionPolicy<K,V>- Parameters:
maxMemSize- Maximum allowed cache size in bytes.- Returns:
thisfor chaining.
-
setMaxSize
public SortedEvictionPolicy<K,V> setMaxSize(int max)
Sets maximum allowed size of cache before entry will start getting evicted.- Overrides:
setMaxSizein classAbstractEvictionPolicy<K,V>- Parameters:
max- Maximum allowed size of cache before entry will start getting evicted.- Returns:
thisfor chaining.
-
setBatchSize
public SortedEvictionPolicy<K,V> setBatchSize(int batchSize)
Sets batch size.- Overrides:
setBatchSizein classAbstractEvictionPolicy<K,V>- Parameters:
batchSize- Batch size.- Returns:
thisfor chaining.
-
queue
public Collection<EvictableEntry<K,V>> queue()
Gets read-only view of backed queue in proper order.- Returns:
- Read-only view of backed queue.
-
touch
protected boolean touch(EvictableEntry<K,V> entry)
- Specified by:
touchin classAbstractEvictionPolicy<K,V>- Parameters:
entry- Entry to touch.- Returns:
Trueif backed queue has been changed by this call.
-
getCurrentSize
public int getCurrentSize()
- Specified by:
getCurrentSizein classAbstractEvictionPolicy<K,V>- Returns:
- Size of the container with trackable entries.
-
shrink0
protected int shrink0()
Tries to remove one item from queue.- Specified by:
shrink0in classAbstractEvictionPolicy<K,V>- Returns:
- number of bytes that was free.
-1if queue is empty.
-
getMBean
public Object getMBean()
- Specified by:
getMBeanin interfaceIgniteMBeanAware- Returns:
- MBean for this object.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Overrides:
writeExternalin classAbstractEvictionPolicy<K,V>- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Overrides:
readExternalin classAbstractEvictionPolicy<K,V>- Throws:
IOExceptionClassNotFoundException
-
removeMeta
protected boolean removeMeta(Object meta)
Removes holder from backed queue and marks holder as removed.- Specified by:
removeMetain classAbstractEvictionPolicy<K,V>- Parameters:
meta- Holder.- Returns:
Trueif meta was successfully removed from the container.
-
-