org.objectweb.perseus.cache.replacement.lib

Class AbstractReplacementManager

Implemented Interfaces:
BindingController, CacheCapacityEventListener, ReplacementManager, UnbindManager
Known Direct Subclasses:
FIFOReplacementManager, LRUReplacementManager, MRUReplacementManager

public abstract class AbstractReplacementManager
extends java.lang.Object
implements ReplacementManager, BindingController, CacheCapacityEventListener

This class is a common implementation of a ReplacementManager.

Author:
E.Bruneton

See Also:
LRUReplacementManager, MRUReplacementManager

Field Summary

static String
UNBIND_MANAGER_BINDING
protected SortedSet
entries
Sorted list of WeakReplaceableCacheEntry entries.
protected Logger
logger
protected HashMap
oid2wentry
protected ReferenceQueue
queue
Queue used to register the weak references stored in the entries list.
protected UnbindManager
ub

Constructor Summary

AbstractReplacementManager()

Method Summary

protected void
add(ReplaceableCacheEntry entry)
void
addForReplacement(FixableCacheEntry entry)
void
adjustForReplacement(FixableCacheEntry entry)
Called whenever an object has been accessed.
void
bindFc(String s, Object o)
void
cacheResized(CacheCapacityEvent event)
The cache has been resized.
int
forceFree(int capacity)
It forces the replacement manager to free CacheEntry instances from the cahce.
String[]
listFc()
Object
lookupFc(String s)
void
removeForReplacement(Object oid)
This method is called by the CacheManager in order to signal that an entry has been really evicted.
protected void
touch(ReplaceableCacheEntry entry)
boolean
unbind(Object oid, boolean force)
It forces the replacement manager to unbind a CacheEntry instance from the cache.
Collection
unbindAll(Collection _oids, boolean force)
Evicts instances from the cache.
void
unbindFc(String s)
Collection
unbindUnfixed(boolean force)
Try to evict unfixed instances.

Field Details

UNBIND_MANAGER_BINDING

public static final String UNBIND_MANAGER_BINDING


entries

protected SortedSet entries
Sorted list of WeakReplaceableCacheEntry entries. Each entry must have a unique age, so that this sorted set behaves as a sorted list.


logger

protected Logger logger


oid2wentry

protected HashMap oid2wentry


queue

protected ReferenceQueue queue
Queue used to register the weak references stored in the entries list.


ub

protected UnbindManager ub

Constructor Details

AbstractReplacementManager

public AbstractReplacementManager()

Method Details

add

protected void add(ReplaceableCacheEntry entry)


addForReplacement

public void addForReplacement(FixableCacheEntry entry)
            throws CacheException
Specified by:
addForReplacement in interface ReplacementManager

Parameters:
entry - The cache entry that has been accessed.

Throws:
CacheException - Whenever an internal error occurs.


adjustForReplacement

public void adjustForReplacement(FixableCacheEntry entry)
            throws CacheException
Called whenever an object has been accessed. Thus, this method, gives hints about recency/frequency of use. This hints are used within the replacement algorithm.
Specified by:
adjustForReplacement in interface ReplacementManager

Parameters:
entry - The cache entry that has been accessed.

Throws:
CacheException - Whenever an internal error occurs.


bindFc

public void bindFc(String s,
                   Object o)


cacheResized

public void cacheResized(CacheCapacityEvent event)
The cache has been resized.
Specified by:
cacheResized in interface CacheCapacityEventListener

Parameters:
event - contains the old and the new cache size.


forceFree

public int forceFree(int capacity)
            throws CacheException
It forces the replacement manager to free CacheEntry instances from the cahce.
Specified by:
forceFree in interface ReplacementManager

Parameters:
capacity - is the quantity of space required by the cache.


listFc

public String[] listFc()


lookupFc

public Object lookupFc(String s)


removeForReplacement

public void removeForReplacement(Object oid)
This method is called by the CacheManager in order to signal that an entry has been really evicted. In fact the eviction has been previously requested by the ReplacementManager, and now the GC garbaged an entry.
Specified by:
removeForReplacement in interface ReplacementManager

Parameters:
oid - is the evicted cache entry


touch

protected void touch(ReplaceableCacheEntry entry)


unbind

public boolean unbind(Object oid,
                      boolean force)
            throws CacheException
It forces the replacement manager to unbind a CacheEntry instance from the cache.
Specified by:
unbind in interface UnbindManager


unbindAll

public Collection unbindAll(Collection _oids,
                            boolean force)
            throws CacheException
Evicts instances from the cache.
Specified by:
unbindAll in interface UnbindManager

Parameters:
force - is a boolean value indicating if the cache must remove the entries or let the GC does its job.

Returns:
the oid of the really evicted entries

Throws:
CacheException - is raised when entries are already unbound from the cache.


unbindFc

public void unbindFc(String s)


unbindUnfixed

public Collection unbindUnfixed(boolean force)
            throws CacheException
Try to evict unfixed instances.
Specified by:
unbindUnfixed in interface UnbindManager

Parameters:
force - is a boolean value indicating if the cache must remove the entries or let the GC does its job.

Returns:
the number of entry really evicted

Throws:
CacheException -


Copyright © 2000-2002 France Telecom S.A., INRIA, IMAG-LSR All Rights Reserved.