JBoss.org Community Documentation
In order to implement an eviction policy, the following interfaces must be implemented:
org.jboss.cache.eviction.EvictionPolicy
org.jboss.cache.eviction.EvictionAlgorithm
org.jboss.cache.eviction.EvictionQueue
org.jboss.cache.config.EvictionPolicyConfig
When compounded together, each of these interface implementations define all the underlying mechanics necessary for a complete eviction policy implementation.
Note that:
The
EvictionPolicyConfig
implementation
should maintain
getter and setter methods for whatever configuration properties
the policy supports (e.g. for
LRUConfiguration
among others there is a
int getMaxNodes()
and a
setMaxNodes(int)
). When the "EvictionConfig" section of an XML configuration
is parsed, these properties will be set by reflection.
Alternatively, the implementation of a new eviction policy
provider can be simplified by extending
BaseEvictionPolicy
and
BaseEvictionAlgorithm
. Or for properly sorted EvictionAlgorithms (sorted
in eviction order - see
LFUAlgorithm
) extending
BaseSortedEvictionAlgorithm
and implementing
SortedEvictionQueue
takes
care of most of the common functionality available in a set of eviction
policy provider classes
Note that:
The
BaseEvictionAlgorithm
class maintains a processing
structure. It will process the ADD, REMOVE, and VISIT events queued
by the region first. It also maintains an collection of
items that were not properly evicted during the last go around
because of held locks. That list is pruned. Finally, the
EvictionQueue itself is pruned for entries that should be evicted
based upon the configured eviction rules for the region.
The
BaseSortedEvictionAlgorithm
class will maintain a boolean
through the algorithm processing that will determine if any new
nodes were added or visited. This allows the Algorithm to determine
whether to resort the eviction queue items (in first to evict order)
or to skip the potentially expensive sorting if there have been no
changes to the cache in this region.
The
SortedEvictionQueue
interface defines the contract used by
the
BaseSortedEvictionAlgorithm
abstract class that is used to
resort the underlying queue. Again, the queue sorting should be
sorted in first to evict order. The first entry in the list should
evict before the last entry in the queue. The last entry in the
queue should be the last entry that will require eviction.