IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

com.ibm.websphere.objectgrid.plugins.builtins
Class LRUEvictor

java.lang.Object
  extended by com.ibm.websphere.objectgrid.plugins.builtins.LRUEvictor
All Implemented Interfaces:
Evictor, RollbackEvictor, Runnable

public final class LRUEvictor
extends Object
implements Evictor, RollbackEvictor, Runnable

This evictor manages a BackingMap using a simple Least Recently Used (LRU) algorithm. It attempts to keep the BackingMap at less than a certain number of entries.

Since:
WAS XD 6.0, XC10
See Also:
Evictor

Field Summary
static int DEFAULT_NUMBER_OF_QUEUES
          Default number of LRU queues to create if the setNumberOfLRUQueues(int) method is not called.
static long DEFAULT_SLEEP_TIME
          Default sleep time for evictor thread if the setSleepTime(int) method is not called.
 
Constructor Summary
LRUEvictor()
          Creates a new LRUEvictor object with default values for the maximum size per LRU queue, the number of queues, and sleep time between sweeps by the evictor thread.
 
Method Summary
 void activate()
          This method is called to activate the Evictor.
 void apply(LogSequence sequence)
          Maintains a bi-directional queue ordered on last access.
 void deactivate()
          This method is called to deactivate the Evictor.
 void destroy()
          Called when the BackingMap associated with this evictor is destroyed.
 int getMaxSize()
          Gets the maximum size of each LRU queue.
 int getNumberOfLRUQueues()
          Gets number of LRU queues being used.
 int getSleepTime()
          Gets the sleep time being used in seconds.
 void initialize(BackingMap map, EvictionEventCallback callback)
          Called by a BackingMap instance during the evictor initialization time.
 void rollingBack(LogSequence sequence)
          Called after a transaction rollback to allow an evictor to track object usage in a backing map even when rollback occurs instead of commit.
 void run()
          Manages the map's size and sends eviction events to the Map.
 void setMaxSize(int maxSize)
          Sets the maximum size of each LRU queue.
 void setNumberOfLRUQueues(int numberOfQueues)
          Sets the number of LRU queues to use.
 void setSleepTime(int seconds)
          Sets the sleep time to use in seconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SLEEP_TIME

public static final long DEFAULT_SLEEP_TIME
Default sleep time for evictor thread if the setSleepTime(int) method is not called.

See Also:
setSleepTime(int), Constant Field Values

DEFAULT_NUMBER_OF_QUEUES

public static final int DEFAULT_NUMBER_OF_QUEUES
Default number of LRU queues to create if the setNumberOfLRUQueues(int) method is not called.

See Also:
setNumberOfLRUQueues(int), Constant Field Values
Constructor Detail

LRUEvictor

public LRUEvictor()
Creates a new LRUEvictor object with default values for the maximum size per LRU queue, the number of queues, and sleep time between sweeps by the evictor thread.

The default values can be overridden by use of the setMaxSize(int), setNumberOfLRUQueues(int), and setSleepTime(int) methods. If the setMaxSize method is never called, the size of BackingMap is unlimited and no LRU data is kept.

Method Detail

initialize

public void initialize(BackingMap map,
                       EvictionEventCallback callback)
Description copied from interface: Evictor

Called by a BackingMap instance during the evictor initialization time.

The BackingMap calls this method so the Evictor instance can have references to the BackingMap and EvictionEventCallback instances. The evictor can signal events to have specific entries evicted using the EvictionEventCallback.

Specified by:
initialize in interface Evictor
Parameters:
map - the BackingMap instance
callback - the EvictionEventCallback instance
See Also:
Evictor.initialize(BackingMap, EvictionEventCallback)

apply

public void apply(LogSequence sequence)
Maintains a bi-directional queue ordered on last access.

Specified by:
apply in interface Evictor
Parameters:
sequence - the LogSequence of changes committed to the map
See Also:
Evictor.apply(LogSequence)

rollingBack

public void rollingBack(LogSequence sequence)
Description copied from interface: RollbackEvictor
Called after a transaction rollback to allow an evictor to track object usage in a backing map even when rollback occurs instead of commit. Since the transaction is rolling back, the Evictor must be aware that it cannot depend on the LogElement type to infer the existence or non-existence of a map entry. See Evictor.apply(LogSequence) for other considerations when implementing this method. Many of the considerations with the Evictor.apply method also apply to this method.

Specified by:
rollingBack in interface RollbackEvictor
Parameters:
sequence - LogSequence of changes to the map
See Also:
RollbackEvictor.rollingBack(LogSequence)

getMaxSize

public int getMaxSize()
Gets the maximum size of each LRU queue.

Returns:
the same value that was passed to the setMaxSize(int) method or the default value of zero if the setMaxSize method is never called
See Also:
setMaxSize(int)

setMaxSize

public void setMaxSize(int maxSize)
Sets the maximum size of each LRU queue.

This method is used to override the default maximum size for each LRU queue used to keep LRU data. The evictor thread will attempt to keep each LRU queue to be no larger than the maximum size. This method must be called prior to the initialize method to avoid an IllegalStateException being thrown.

Parameters:
maxSize - is the maximum size per LRU queue. Any value <= 0 indicates to allow each queue to be of unlimited size. In which case, no LRU data is kept.
Throws:
IllegalStateException - if called after the initialize method.
See Also:
initialize(BackingMap, EvictionEventCallback)

getSleepTime

public int getSleepTime()
Gets the sleep time being used in seconds.

Returns:
the same value that was passed to the setSleepTime(int) method or the default value of DEFAULT_SLEEP_TIME if the setSleepTime method is never called
See Also:
setSleepTime(int)

setSleepTime

public void setSleepTime(int seconds)
Sets the sleep time to use in seconds.

This method is used to override the default sleep time of the evictor thread in seconds. This method must be called prior to the initialize method to avoid an IllegalStateException being thrown. If this method is not called, the DEFAULT_SLEEP_TIME constant is used as the sleep time.

Parameters:
seconds - is the number of seconds the evictor thread sleeps in between each sweep of the LRU queue data
Throws:
IllegalArgumentException - if seconds < 1
IllegalStateException - if called after the initialize method.
See Also:
DEFAULT_SLEEP_TIME, initialize(BackingMap, EvictionEventCallback)

getNumberOfLRUQueues

public int getNumberOfLRUQueues()
Gets number of LRU queues being used.

Returns:
the same value that was passed to the setNumberOfLRUQueues(int) method or the default value of DEFAULT_NUMBER_OF_QUEUES if the setNumberOfLRUQueues method is never called
See Also:
DEFAULT_NUMBER_OF_QUEUES, setNumberOfLRUQueues(int)

setNumberOfLRUQueues

public void setNumberOfLRUQueues(int numberOfQueues)
Sets the number of LRU queues to use.

This method is used to override the default number of LRU queues created by the initialize method for keeping the LRU data needed by the evictor thread. This method must be called prior to the initialize method to avoid an IllegalStateException being thrown. If this method is not called,the DEFAULT_NUMBER_OF_QUEUES constant is used as the number of heaps.

Parameters:
numberOfQueues - is the number of LRU queue instances used to hold LRU data. The value must be greater than or equal to 1 and a prime number is recommended for best performance.
Throws:
IllegalArgumentException - if numberOfQueuess < 1
IllegalStateException - if called after the initialize method.
See Also:
DEFAULT_NUMBER_OF_QUEUES, initialize(BackingMap, EvictionEventCallback)

run

public void run()
Manages the map's size and sends eviction events to the Map.

The thread is only spawned if the map size is limited rather than unlimited in size (e.g. maxSize > 0 ).

Specified by:
run in interface Runnable

destroy

public void destroy()
Description copied from interface: Evictor

Called when the BackingMap associated with this evictor is destroyed.

This method is the opposite of the initialize method. When it is called, the Evictor can free up any resources it uses.

Specified by:
destroy in interface Evictor
See Also:
Evictor.destroy()

activate

public void activate()
Description copied from interface: Evictor
This method is called to activate the Evictor. Until this method is called, the Evictor must not use the EvictionEventCallback interface to evict any map entries. If it does use the EvictionEventcallback interface to evict map entries prior to activate being called, an IllegalStateException is thrown.

Specified by:
activate in interface Evictor
See Also:
Evictor.activate()

deactivate

public void deactivate()
Description copied from interface: Evictor
This method is called to deactivate the Evictor. Once this method is called, the Evictor must quit using the EvictionEventCallback interface to evict any map entries. If it does use the EvictionEventcallback interface after this method is called, an IllegalStateException is thrown.

Specified by:
deactivate in interface Evictor
See Also:
Evictor.deactivate()

IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

© Copyright International Business Machines Corp 2005,2012. All rights reserved.