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
batchSize
elements 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
).batchSize
elements will be evicted in this case. The defaultbatchSize
value is1
.Entries comparison based on
Comparator
instance if provided. DefaultComparator
behaviour is use cache entries keys for comparison that imposes a requirement for keys to implementComparable
interface.User defined comparator should implement
Serializable
interface.- 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 int
getCurrentSize()
Object
getMBean()
Collection<EvictableEntry<K,V>>
queue()
Gets read-only view of backed queue in proper order.void
readExternal(ObjectInput in)
protected boolean
removeMeta(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 int
shrink0()
Tries to remove one item from queue.protected boolean
touch(EvictableEntry<K,V> entry)
void
writeExternal(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:
setMaxMemorySize
in classAbstractEvictionPolicy<K,V>
- Parameters:
maxMemSize
- Maximum allowed cache size in bytes.- Returns:
this
for chaining.
-
setMaxSize
public SortedEvictionPolicy<K,V> setMaxSize(int max)
Sets maximum allowed size of cache before entry will start getting evicted.- Overrides:
setMaxSize
in classAbstractEvictionPolicy<K,V>
- Parameters:
max
- Maximum allowed size of cache before entry will start getting evicted.- Returns:
this
for chaining.
-
setBatchSize
public SortedEvictionPolicy<K,V> setBatchSize(int batchSize)
Sets batch size.- Overrides:
setBatchSize
in classAbstractEvictionPolicy<K,V>
- Parameters:
batchSize
- Batch size.- Returns:
this
for 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:
touch
in classAbstractEvictionPolicy<K,V>
- Parameters:
entry
- Entry to touch.- Returns:
True
if backed queue has been changed by this call.
-
getCurrentSize
public int getCurrentSize()
- Specified by:
getCurrentSize
in classAbstractEvictionPolicy<K,V>
- Returns:
- Size of the container with trackable entries.
-
shrink0
protected int shrink0()
Tries to remove one item from queue.- Specified by:
shrink0
in classAbstractEvictionPolicy<K,V>
- Returns:
- number of bytes that was free.
-1
if queue is empty.
-
getMBean
public Object getMBean()
- Specified by:
getMBean
in interfaceIgniteMBeanAware
- Returns:
- MBean for this object.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Overrides:
writeExternal
in classAbstractEvictionPolicy<K,V>
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Overrides:
readExternal
in classAbstractEvictionPolicy<K,V>
- Throws:
IOException
ClassNotFoundException
-
removeMeta
protected boolean removeMeta(Object meta)
Removes holder from backed queue and marks holder as removed.- Specified by:
removeMeta
in classAbstractEvictionPolicy<K,V>
- Parameters:
meta
- Holder.- Returns:
True
if meta was successfully removed from the container.
-
-