org.objectweb.perseus.cache.replacement.lib
Class AbstractReplacementManager

java.lang.Object
  extended byorg.objectweb.perseus.cache.replacement.lib.AbstractReplacementManager
All Implemented Interfaces:
CacheCapacityEventListener, ReplacementManager, UnbindManager
Direct Known Subclasses:
FIFOReplacementManager, LRUReplacementManager, MRUReplacementManager

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

This class is a common implementation of a ReplacementManager.

Author:
E.Bruneton
See Also:
FIFOReplacementManager, LRUReplacementManager, MRUReplacementManager

Field Summary
protected  java.util.SortedSet entries
          Sorted list of WeakReplaceableCacheEntry entries.
protected  Logger logger
           
protected  java.util.HashMap oid2wentry
           
protected  java.lang.ref.ReferenceQueue queue
          Queue used to register the weak references stored in the entries list.
protected  UnbindManager ub
           
static java.lang.String UNBIND_MANAGER_BINDING
           
 
Constructor Summary
AbstractReplacementManager()
           
 
Method Summary
protected abstract  void add(ReplaceableCacheEntry entry)
           
 void addForReplacement(FixableCacheEntry entry)
           
 void adjustForReplacement(FixableCacheEntry entry)
          Called whenever an object has been accessed.
 void bindFc(java.lang.String s, java.lang.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.
 java.lang.String[] listFc()
           
 java.lang.Object lookupFc(java.lang.String s)
           
 void removeForReplacement(java.lang.Object oid)
          This method is called by the CacheManager in order to signal that an entry has been really evicted.
protected abstract  void touch(ReplaceableCacheEntry entry)
           
 java.util.Collection unbind(CacheEntryFilter filter, boolean force)
          Evicts the entries which are accepted by the filter.
 boolean unbind(java.lang.Object oid, boolean force)
          It forces the replacement manager to unbind a CacheEntry instance from the cache.
 java.util.Collection unbindAll(java.util.Collection _oids, boolean force)
          Evicts instances from the cache.
 void unbindFc(java.lang.String s)
           
 java.util.Collection unbindUnfixed(boolean force)
          Try to evict unfixed instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNBIND_MANAGER_BINDING

public static final java.lang.String UNBIND_MANAGER_BINDING
See Also:
Constant Field Values

ub

protected UnbindManager ub

entries

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


oid2wentry

protected java.util.HashMap oid2wentry

queue

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


logger

protected Logger logger
Constructor Detail

AbstractReplacementManager

public AbstractReplacementManager()
Method Detail

listFc

public java.lang.String[] listFc()

lookupFc

public java.lang.Object lookupFc(java.lang.String s)

bindFc

public void bindFc(java.lang.String s,
                   java.lang.Object o)

unbindFc

public void unbindFc(java.lang.String s)

cacheResized

public void cacheResized(CacheCapacityEvent event)
Description copied from interface: CacheCapacityEventListener
The cache has been resized.

Specified by:
cacheResized in interface CacheCapacityEventListener
Parameters:
event - contains the old and the new cache size.

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
Description copied from interface: ReplacementManager
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.

forceFree

public int forceFree(int capacity)
              throws CacheException
Description copied from interface: ReplacementManager
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.
Throws:
CacheException

removeForReplacement

public void removeForReplacement(java.lang.Object oid)
Description copied from interface: ReplacementManager
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

unbind

public java.util.Collection unbind(CacheEntryFilter filter,
                                   boolean force)
                            throws CacheException
Description copied from interface: UnbindManager
Evicts the entries which are accepted by the filter.

Specified by:
unbind in interface UnbindManager
Parameters:
filter - is a cacheentry filter indicating wich entry has to be evicted
force - is a boolean value indicating if the cache must remove the entries or let the GC does its job.
Returns:
the collection of cache entry identifier really evicted.
Throws:
CacheException

unbindAll

public java.util.Collection unbindAll(java.util.Collection _oids,
                                      boolean force)
                               throws CacheException
Description copied from interface: UnbindManager
Evicts instances from the cache.

Specified by:
unbindAll in interface UnbindManager
Parameters:
_oids - is a collection of the identifier associated to cache entries to evict
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.

unbindUnfixed

public java.util.Collection unbindUnfixed(boolean force)
                                   throws CacheException
Description copied from interface: UnbindManager
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

unbind

public boolean unbind(java.lang.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
Parameters:
oid - is the identifier associated to the cache entry to evict
force - is a boolean value indicating if the cache must remove the entry or let the GC does its job.
Throws:
CacheException - is raised when the entry is already unbound from the cache.

add

protected abstract void add(ReplaceableCacheEntry entry)

touch

protected abstract void touch(ReplaceableCacheEntry entry)


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