public class ExpirationAlgorithm extends BaseEvictionAlgorithm
System.currentTimeMillis()
).
This algorithm also obeys the configuration key EvictionAlgorithmConfigBase.getMaxNodes()
, and will evict the soonest to
expire entires first to reduce the region size. If there are not enough
nodes with expiration keys set, a warning is logged.
If a node in the eviction region does not have an expiration value, then
ExpirationAlgorithmConfig.getTimeToLive()
(if set) will be used.
The expiration is updated when a node is added or updated.
If there is no time-to-live set, and a node in the eviction region does not
have an expiration value, then that node will never be evicted. As
forgetting to indicate an expiration value is likely a mistake, a warning
message is logged by this class. This warning, however, can be disabled
through ExpirationAlgorithmConfig.setWarnNoExpirationKey(boolean)
.
A node's expiration time can be changed by setting a new value in the node.
Example usage:
Cache cache; Fqn fqn1 = Fqn.fromString("/node/1"); Long future = new Long(System.currentTimeMillis() + 2000); cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future); cache.put(fqn1, "foo"); assertTrue(cache.get(fqn1) != null); Thread.sleep(5000); // 5 seconds assertTrue(cache.get(fqn1) == null);
allowTombstones, cache, configuration, evictionActionPolicy, evictionAlgorithmConfig, evictionQueue, recycleQueue, regionFqn
Constructor and Description |
---|
ExpirationAlgorithm()
Constructs a new algorithm with a policy.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canIgnoreEvent(EvictionEvent.Type eventType)
Tests whether the algorithm would ignore certain event types on certain Fqns.
|
Class<? extends EvictionAlgorithmConfig> |
getConfigurationClass()
This is a helper so that the XML parser will be able to select and use the correct
EvictionAlgorithmConfig implementation
class corresponding to this EvictionAlgorithm. |
protected void |
processQueues(BlockingQueue<EvictionEvent> queue)
Event processing for Evict/Add/Visiting of nodes.
|
protected void |
prune() |
void |
resetEvictionQueue()
Reset the whole eviction queue.
|
protected EvictionQueue |
setupEvictionQueue()
This method will create an EvictionQueue implementation and prepare it for use.
|
protected boolean |
shouldEvictNode(NodeEntry ne)
This method will check whether the given node should be evicted or not.
|
assignToRegion, emptyRecycleQueue, evict, evictCacheNode, getEvictionActionPolicy, getEvictionAlgorithmConfig, getEvictionQueue, getNextInQueue, initialize, isNodeInUseAndNotTimedOut, isYoungerThanMinimumTimeToLive, process, processAddedElement, processAddedNodes, processAddedNodes, processMarkInUseNodes, processRemovedElement, processRemovedNodes, processUnmarkInUseNodes, processVisitedNodes, setEvictionActionPolicy, toString
public ExpirationAlgorithm()
protected void processQueues(BlockingQueue<EvictionEvent> queue) throws EvictionException
BaseEvictionAlgorithm
processQueues
in class BaseEvictionAlgorithm
queue
- queue to inspectEvictionException
- in the event of problemsprotected void prune() throws EvictionException
prune
in class BaseEvictionAlgorithm
EvictionException
public void resetEvictionQueue()
EvictionAlgorithm
resetEvictionQueue
in interface EvictionAlgorithm
resetEvictionQueue
in class BaseEvictionAlgorithm
protected EvictionQueue setupEvictionQueue() throws EvictionException
BaseEvictionAlgorithm
setupEvictionQueue
in class BaseEvictionAlgorithm
EvictionException
- if there are problemsEvictionQueue
protected boolean shouldEvictNode(NodeEntry ne)
BaseEvictionAlgorithm
shouldEvictNode
in class BaseEvictionAlgorithm
ne
- NodeEntry to test eviction for.public boolean canIgnoreEvent(EvictionEvent.Type eventType)
EvictionAlgorithm
canIgnoreEvent
in interface EvictionAlgorithm
canIgnoreEvent
in class BaseEvictionAlgorithm
eventType
- event type to test forpublic Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
EvictionAlgorithm
EvictionAlgorithmConfig
implementation
class corresponding to this EvictionAlgorithm. E.g., the FIFOAlgorithm
would return FIFOAlgorithmConfig
.class.Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.