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

### Field Summary

Fields
`protected LongAdder8` `memSize` Memory size occupied by elements in container.

### Constructor Summary

Constructors
Constructor and Description
`AbstractEvictionPolicy()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`int` `getBatchSize()` Gets batch size.
`long` `getCurrentMemorySize()` Gets current queue size in bytes.
`protected abstract int` `getCurrentSize()`
`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.
`void` `readExternal(ObjectInput in)`
`protected abstract boolean` `removeMeta(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 void` `shrink()` Shrinks backed container to maximum allowed size.
`protected abstract int` `shrink0()`
`protected abstract boolean` `touch(EvictableEntry<K,V> entry)`
`void` `writeExternal(ObjectOutput out)`

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

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

### Field Detail

#### memSize

    protected final LongAdder8 memSize

Memory size occupied by elements in container.

### Constructor Detail

#### AbstractEvictionPolicy

    public AbstractEvictionPolicy()

### 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:
  `onEntryAccessed` in interface `EvictionPolicy<K,V>`
Parameters:
  `rmv` - `True` if entry has been removed, `false` otherwise.
  `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:
  `True` if meta was successfully removed from the container.

#### touch

    protected abstract boolean touch(EvictableEntry<K,V> entry)

Parameters:
  `entry` - Entry to touch.
Returns:
  `True` if container has been changed by this call.

#### setMaxMemorySize

    public AbstractEvictionPolicy<K,V> setMaxMemorySize(long maxMemSize)

Sets maximum allowed cache size in bytes.

Returns:
  `this` for 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:
  `this` for 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:
  `this` for chaining.

#### getBatchSize

    public int getBatchSize()

Gets batch size.

Returns:
  batch size.

#### 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`

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.4.0
Release Date | : March 5 2018