org.apache.ignite.cache.eviction.sorted

## Class SortedEvictionPolicy<K,V>

- java.lang.Object
- - org.apache.ignite.cache.eviction.sorted.SortedEvictionPolicy<K,V>

All Implemented Interfaces:
  Externalizable, Serializable, EvictionPolicy<K,V>, SortedEvictionPolicyMBean

    public class SortedEvictionPolicy<K,V>
    extends Object
    implements EvictionPolicy<K,V>, SortedEvictionPolicyMBean, Externalizable

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.

Note:Batch eviction is enabled only if maximum memory limit isn't set (`maxMemSize == 0`). `batchSize` elements will be evicted in this case. The default `batchSize` value is `1`.

Entries comparison based on `Comparator` instance if provided. Default `Comparator` behaviour is use cache entries keys for comparison that imposes a requirement for keys to implement `Comparable` interface.

User defined comparator should implement `Serializable` interface.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`SortedEvictionPolicy()` Constructs sorted eviction policy with all defaults.
`SortedEvictionPolicy(Comparator<EvictableEntry<K,V>> comp)` Constructs sorted eviction policy with given maximum size and given entry comparator.
`SortedEvictionPolicy(int max)` Constructs sorted eviction policy with maximum size.
`SortedEvictionPolicy(int max, Comparator<EvictableEntry<K,V>> comp)` Constructs sorted eviction policy with given maximum size and given entry comparator.
`SortedEvictionPolicy(int max, int batchSize, Comparator<EvictableEntry<K,V>> comp)` Constructs sorted eviction policy with given maximum size, eviction batch size and entries comparator.

### Method Summary

Methods
`int` `getBatchSize()` Gets batch size.
`long` `getCurrentMemorySize()` Gets current sorted entries queue size in bytes.
`int` `getCurrentSize()` Gets current size.
`long` `getMaxMemorySize()` Gets maximum allowed cache size in bytes.
`int` `getMaxSize()` Gets maximum allowed size of cache before entry will start getting evicted.
`void` `onEntryAccessed(boolean rmv, EvictableEntry<K,V> entry)` Callback for whenever entry is accessed.
`Collection<EvictableEntry<K,V>>` `queue()` Gets read-only view of backed queue in proper order.
`void` `readExternal(ObjectInput in)`
`void` `setBatchSize(int batchSize)` Sets batch size.
`void` `setMaxMemorySize(long maxMemSize)` Sets maximum allowed cache size in bytes.
`void` `setMaxSize(int max)` Sets maximum allowed size of cache before entry will start getting evicted.
`void` `writeExternal(ObjectOutput out)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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
                        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
                        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
                        Comparator<EvictableEntry<K,V>> comp)

Constructs sorted eviction policy with given maximum size and given entry comparator.

Parameters:
  `comp` - Entries comparator.

### Method Detail

#### getMaxSize

    public int getMaxSize()

Gets maximum allowed size of cache before entry will start getting evicted.

Specified by:
  `getMaxSize` in interface `SortedEvictionPolicyMBean`
Returns:
  Maximum allowed size of cache before entry will start getting evicted.

#### setMaxSize

    public void setMaxSize(int max)

Sets maximum allowed size of cache before entry will start getting evicted.

Specified by:
  `setMaxSize` in interface `SortedEvictionPolicyMBean`
Parameters:
  `max` - Maximum allowed size of cache before entry will start getting evicted.

#### getBatchSize

    public int getBatchSize()

Gets batch size.

Specified by:
  `getBatchSize` in interface `SortedEvictionPolicyMBean`
Returns:
  batch size.

#### setBatchSize

    public void setBatchSize(int batchSize)

Sets batch size.

Specified by:
  `setBatchSize` in interface `SortedEvictionPolicyMBean`
Parameters:
  `batchSize` - Batch size.

#### getCurrentSize

    public int getCurrentSize()

Gets current size.

Specified by:
  `getCurrentSize` in interface `SortedEvictionPolicyMBean`
Returns:
  Current size.

#### getMaxMemorySize

    public long getMaxMemorySize()

Gets maximum allowed cache size in bytes.

Specified by:
  `getMaxMemorySize` in interface `SortedEvictionPolicyMBean`
Returns:
  maximum allowed cache size in bytes.

#### setMaxMemorySize

    public void setMaxMemorySize(long maxMemSize)

Sets maximum allowed cache size in bytes.

Specified by:
  `setMaxMemorySize` in interface `SortedEvictionPolicyMBean`

#### getCurrentMemorySize

    public long getCurrentMemorySize()

Gets current sorted entries queue size in bytes.

Specified by:
  `getCurrentMemorySize` in interface `SortedEvictionPolicyMBean`
Returns:
  current sorted entries queue size in bytes.

#### queue

    public Collection<EvictableEntry<K,V>> queue()

Gets read-only view of backed queue in proper order.

Returns:
  Read-only view of backed queue.

#### onEntryAccessed

    public void onEntryAccessed(boolean rmv,
                       EvictableEntry<K,V> entry)

Callback for whenever entry is accessed.

Specified by:
  `onEntryAccessed` in interface `EvictionPolicy<K,V>`
Parameters:
  `rmv` - `True` if entry has been removed, `false` otherwise.
  `entry` - Accessed entry.

#### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`
  `ClassNotFoundException`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.8.0
Release Date | : December 5 2016