org.objectweb.perseus.cache.lib
Class BasicCacheManager

java.lang.Object
  extended byorg.objectweb.perseus.cache.lib.BasicCacheManager
All Implemented Interfaces:
CacheAttributeController, CacheManager, UnbindManager

public class BasicCacheManager
extends java.lang.Object
implements CacheManager, UnbindManager, CacheAttributeController

This class is an implementation of a cache. The data structure is a Hahsed map between cache entry identifier and an entry instance. This class is a fractal component.

Author:
S.Chassande-Barrioz, E.Bruneton

Nested Class Summary
protected  class BasicCacheManager.CapacityEvent
          This class is a basic implementation of the CacheCapacityEvent interface.
protected  class BasicCacheManager.Event
          This class is a basic implementation of the CacheEvent interface.
 
Field Summary
protected  Logger bgclogger
           
protected  java.util.Map cache
          This field is the cache.
static java.lang.String CACHE_CAPACTITY_LISTENER_BINDING
           
static java.lang.String CACHE_ENTRY_FACTORY_BINDING
           
static java.lang.String CACHE_LISTENER_BINDING
           
protected  int cacheMaxSize
          This field is the max size of the cache.
protected  int cacheThresHold
           
protected  java.lang.String cacheThresHoldStr
           
protected  java.util.HashMap ccels
          This field is the list of CacheEventListener registered.
protected  CacheEntryFactory cef
          This field is the factory of CacheEntry instances.
protected  java.util.HashMap cels
          This field is the list of CacheEventListener registered.
static java.lang.String DEFAULT_AUTO_CLEAN_SIZE
           
protected  Logger logger
           
protected  java.lang.ref.ReferenceQueue queue
          Queue used to register the weak references stored in the cache.
static java.lang.String REPLACEMENT_MANAGER_BINDING
           
protected  ReplacementManager rm
           
 
Fields inherited from interface org.objectweb.perseus.cache.api.CacheAttributeController
NO_LIMIT
 
Constructor Summary
BasicCacheManager()
          It builds a BasicCacheManager with an empty CacheEventListener list, an empty cache and the default max size.
 
Method Summary
 CacheEntry bind(java.lang.Object id, java.lang.Object object)
          This method allows a in-memory object (incarnation) to be placed in the cache.
 void bindFc(java.lang.String s, java.lang.Object o)
           
 void fix(CacheEntry _ce)
          This method notifies the cache manager the intention to use the object identified by lid.
 void fix(CacheEntryFilter filter)
          This method notifies the cache manager the intention to use objects in the cache.
 java.lang.String getAutoCleanSize()
           
 java.lang.String getAutoCleanThreshold()
           
 BackgroundCleaner getBgcleaner()
           
 java.util.Collection getCurrentEntryIdentifiers()
           
 int getCurrentMemorySize()
           
 int getCurrentSize()
           
 java.lang.String getFcState()
           
 int getMaxObjects()
          This method retrieves the maximum number of objects to be held by the cache.
 int getMemorySize()
          This method returns the maximum main-memory size allocated to the cache.
 java.lang.String[] listFc()
           
 CacheEntry lookup(java.lang.Object id)
          This method searches the object, identified by lid, within the cache.
 java.lang.Object lookupFc(java.lang.String s)
           
 void setAutoCleanSize(java.lang.String size)
          Assignes the number of element which can be removed when the cache is full.
 void setAutoCleanThreshold(java.lang.String size)
          Assignes the cache size value since the cache try to decrease the number of entries.
 void setMaxObjects(int size)
          This method allows to set the maximum number of objects to be held by the cache manager.
 void setMemorySize(int size)
          This method allows to set the maximum main-memory size allocated to the cache.
 void startFc()
           
 void stopFc()
           
 void touch(CacheEntry ce)
          Called whenever an object has been accessed.
 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)
          Evicts an 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.
 void unfix(CacheEntry ce)
          This method is used to notify the cache manager that the object identified by lid is not longer to be used.
 void unfix(CacheEntryFilter filter)
          This method is used to notify the cache manager that objects are not longer to be used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_AUTO_CLEAN_SIZE

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

CACHE_ENTRY_FACTORY_BINDING

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

REPLACEMENT_MANAGER_BINDING

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

CACHE_LISTENER_BINDING

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

CACHE_CAPACTITY_LISTENER_BINDING

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

cef

protected CacheEntryFactory cef
This field is the factory of CacheEntry instances.


rm

protected ReplacementManager rm

cache

protected java.util.Map cache
This field is the cache. This is a Map which the key are object identifiers and the values are FixableCacheEntry instances.


queue

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


cacheMaxSize

protected int cacheMaxSize
This field is the max size of the cache.


cacheThresHold

protected int cacheThresHold

cacheThresHoldStr

protected java.lang.String cacheThresHoldStr

logger

protected Logger logger

bgclogger

protected Logger bgclogger

cels

protected java.util.HashMap cels
This field is the list of CacheEventListener registered.


ccels

protected java.util.HashMap ccels
This field is the list of CacheEventListener registered.

Constructor Detail

BasicCacheManager

public BasicCacheManager()
It builds a BasicCacheManager with an empty CacheEventListener list, an empty cache and the default max size.

Method Detail

getBgcleaner

public BackgroundCleaner getBgcleaner()

getFcState

public java.lang.String getFcState()

startFc

public void startFc()

stopFc

public void stopFc()

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)

setMaxObjects

public void setMaxObjects(int size)
                   throws java.lang.IllegalArgumentException,
                          CacheException
Description copied from interface: CacheAttributeController
This method allows to set the maximum number of objects to be held by the cache manager. However, the actual capacity of the cache depends on the Java Virtual Machine memory limits (and eventually by the amount of disk allocated). That is, if the application allocates a lot of large objects, and the memory limit is reached, the cache would not be able to hold more objects. The cache replacement task is launched when the maximum number of objects limit is nearly to be reached.

Specified by:
setMaxObjects in interface CacheAttributeController
Parameters:
size - The maximum number of objects to be held in cache. (It must be a positive number).
Throws:
java.lang.IllegalArgumentException - if the size is invalid (e.g. negative).
CacheException - if it is not possible to reduce the cache size because all entries are fixed.

getMaxObjects

public int getMaxObjects()
Description copied from interface: CacheAttributeController
This method retrieves the maximum number of objects to be held by the cache.

Specified by:
getMaxObjects in interface CacheAttributeController

getCurrentSize

public int getCurrentSize()
Specified by:
getCurrentSize in interface CacheAttributeController
Returns:
an positive integer value. It is the current size of the cache in term of object number currently managed by the cache.

getCurrentEntryIdentifiers

public java.util.Collection getCurrentEntryIdentifiers()
Specified by:
getCurrentEntryIdentifiers in interface CacheAttributeController
Returns:
an unmodifiable collection containing the identifiers of current cache entries.

setMemorySize

public void setMemorySize(int size)
                   throws java.lang.IllegalArgumentException
Description copied from interface: CacheAttributeController
This method allows to set the maximum main-memory size allocated to the cache. The size is limited by the actual amount of memory allocated to the Java Virtual Machine.

Specified by:
setMemorySize in interface CacheAttributeController
Parameters:
size - The maximum memory size. (It must be a positive number).
Throws:
java.lang.IllegalArgumentException - if the size is invalid (e.g. negative).

getMemorySize

public int getMemorySize()
Description copied from interface: CacheAttributeController
This method returns the maximum main-memory size allocated to the cache.

Specified by:
getMemorySize in interface CacheAttributeController

getCurrentMemorySize

public int getCurrentMemorySize()
Specified by:
getCurrentMemorySize in interface CacheAttributeController
Returns:
an positive integer value. It is the current size of the cache in octets. This size matches to the memory foot print of the entries set managed by the cache.

setAutoCleanSize

public void setAutoCleanSize(java.lang.String size)
Description copied from interface: CacheAttributeController
Assignes the number of element which can be removed when the cache is full. This value can be an absolute value( ex: "124") or a percent of the maximal cache size ("8%").

Specified by:
setAutoCleanSize in interface CacheAttributeController

getAutoCleanSize

public java.lang.String getAutoCleanSize()
Specified by:
getAutoCleanSize in interface CacheAttributeController

setAutoCleanThreshold

public void setAutoCleanThreshold(java.lang.String size)
Description copied from interface: CacheAttributeController
Assignes the cache size value since the cache try to decrease the number of entries. This value can be an absolute value( ex: "124") or a percent of the maximal cache size ("8%").

Specified by:
setAutoCleanThreshold in interface CacheAttributeController

getAutoCleanThreshold

public java.lang.String getAutoCleanThreshold()
Specified by:
getAutoCleanThreshold in interface CacheAttributeController

bind

public CacheEntry bind(java.lang.Object id,
                       java.lang.Object object)
                throws CacheException
Description copied from interface: CacheManager
This method allows a in-memory object (incarnation) to be placed in the cache. Such object is identified by the provided lid. If there is currently an object associated with lid, an Exception is thrown.

Specified by:
bind in interface CacheManager
Parameters:
id - The corresponding object identifier. (It must be generated elsewhere, e.g. by a naming service).
object - The object to be cached.
Returns:
the new CacheEntry add in the cache
Throws:
CacheException - If object/lid are already registered or either object or lid are null.

lookup

public CacheEntry lookup(java.lang.Object id)
Description copied from interface: CacheManager
This method searches the object, identified by lid, within the cache. If such an object has been previously added to the cache the corresponding reference to it will be returned as a result. NULL is returned otherwise. Note that objects must be added to the cache to make it available through it, and that objects could be evicted by the internal replacement algorithm.

Specified by:
lookup in interface CacheManager
Parameters:
id - The corresponding object identifier.
Returns:
The reference to the CacheEntry associated to the id. NULL otherwise.

fix

public void fix(CacheEntry _ce)
         throws CacheException
Description copied from interface: CacheManager
This method notifies the cache manager the intention to use the object identified by lid. The cache manager will mark internally this object, so that this object would not be evicted from the cache.

Specified by:
fix in interface CacheManager
Parameters:
_ce -
Throws:
CacheException - If the object is not in the cache.

fix

public void fix(CacheEntryFilter filter)
         throws CacheException
Description copied from interface: CacheManager
This method notifies the cache manager the intention to use objects in the cache. The cache manager will mark internally this object, so that this object would not be evicted from the cache. The CacheEntryFilter is used to says which entry has to be fix or not.

Specified by:
fix in interface CacheManager
Parameters:
filter -
Throws:
CacheException - If the object is not in the cache.

unfix

public void unfix(CacheEntry ce)
           throws CacheException
Description copied from interface: CacheManager
This method is used to notify the cache manager that the object identified by lid is not longer to be used. After executing this operation, the corresponding object is candidate for eviction, according to the replacement algorithm. That means, that the object will remain in the cache, but it may be evicted.

Specified by:
unfix in interface CacheManager
Parameters:
ce -
Throws:
CacheException - If the object has not been previously fixed.

unfix

public void unfix(CacheEntryFilter filter)
           throws CacheException
Description copied from interface: CacheManager
This method is used to notify the cache manager that objects are not longer to be used. After executing this operation, the corresponding object is candidate for eviction, according to the replacement algorithm. That means, that the object will remain in the cache, but it may be evicted.

Specified by:
unfix in interface CacheManager
Parameters:
filter - indicates which instances have to be unfixed among entries in the cache.
Throws:
CacheException - If the object has not been previously fixed.

touch

public void touch(CacheEntry ce)
           throws CacheException
Description copied from interface: CacheManager
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:
touch in interface CacheManager
Parameters:
ce - The cache entry that has been accessed.
Throws:
CacheException - Whenever an internal error occurs.

unbind

public boolean unbind(java.lang.Object oid,
                      boolean force)
               throws CacheException
Description copied from interface: UnbindManager
Evicts an 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.

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


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