org.objectweb.perseus.cache.lib

Class BasicCacheManager

Implemented Interfaces:
AttributeController, BindingController, CacheAttributeController, CacheManager, LifeCycleController, UnbindManager

public class BasicCacheManager
extends java.lang.Object
implements CacheManager, UnbindManager, BindingController, LifeCycleController, 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

static String
CACHE_CAPACTITY_LISTENER_BINDING
static String
CACHE_ENTRY_FACTORY_BINDING
static String
CACHE_LISTENER_BINDING
static String
DEFAULT_AUTO_CLEAN_SIZE
static String
REPLACEMENT_MANAGER_BINDING
protected Logger
bgclogger
protected Map
cache
This field is the cache.
protected int
cacheMaxSize
This field is the max size of the cache.
protected int
cacheThresHold
protected String
cacheThresHoldStr
protected HashMap
ccels
This field is the list of CacheEventListener registered.
protected CacheEntryFactory
cef
This field is the factory of CacheEntry instances.
protected HashMap
cels
This field is the list of CacheEventListener registered.
protected Logger
logger
protected ReferenceQueue
queue
Queue used to register the weak references stored in the cache.
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(Object id, Object object)
void
bindFc(String s, Object o)
void
fix(CacheEntry _ce)
String
getAutoCleanSize()
String
getAutoCleanThreshold()
BackgroundCleaner
getBgcleaner()
Collection
getCurrentEntryIdentifiers()
int
getCurrentMemorySize()
int
getCurrentSize()
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.
String[]
listFc()
CacheEntry
lookup(Object id)
Object
lookupFc(String s)
void
setAutoCleanSize(String size)
Assignes the number of element which can be removed when the cache is full.
void
setAutoCleanThreshold(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)
boolean
unbind(Object oid, boolean force)
Collection
unbindAll(Collection oids, boolean force)
void
unbindFc(String s)
Collection
unbindUnfixed(boolean force)
void
unfix(CacheEntry ce)

Field Details

CACHE_CAPACTITY_LISTENER_BINDING

public static final String CACHE_CAPACTITY_LISTENER_BINDING


CACHE_ENTRY_FACTORY_BINDING

public static final String CACHE_ENTRY_FACTORY_BINDING


CACHE_LISTENER_BINDING

public static final String CACHE_LISTENER_BINDING


DEFAULT_AUTO_CLEAN_SIZE

public static final String DEFAULT_AUTO_CLEAN_SIZE


REPLACEMENT_MANAGER_BINDING

public static final String REPLACEMENT_MANAGER_BINDING


bgclogger

protected Logger bgclogger


cache

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


cacheMaxSize

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


cacheThresHold

protected int cacheThresHold


cacheThresHoldStr

protected String cacheThresHoldStr


ccels

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


cef

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


cels

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


logger

protected Logger logger


queue

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


rm

protected ReplacementManager rm

Constructor Details

BasicCacheManager

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

Method Details

bind

public CacheEntry bind(Object id,
                       Object object)
            throws CacheException
Specified by:
bind in interface CacheManager


bindFc

public void bindFc(String s,
                   Object o)


fix

public void fix(CacheEntry _ce)
            throws CacheException
Specified by:
fix in interface CacheManager


getAutoCleanSize

public String getAutoCleanSize()
Specified by:
getAutoCleanSize in interface CacheAttributeController


getAutoCleanThreshold

public String getAutoCleanThreshold()
Specified by:
getAutoCleanThreshold in interface CacheAttributeController


getBgcleaner

public BackgroundCleaner getBgcleaner()


getCurrentEntryIdentifiers

public Collection getCurrentEntryIdentifiers()
Specified by:
getCurrentEntryIdentifiers in interface CacheAttributeController

Returns:
an unmodifiable collection containing the identifiers of current cache entries.


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.


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.


getFcState

public String getFcState()


getMaxObjects

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


getMemorySize

public int getMemorySize()
This method returns the maximum main-memory size allocated to the cache.
Specified by:
getMemorySize in interface CacheAttributeController


listFc

public String[] listFc()


lookup

public CacheEntry lookup(Object id)
Specified by:
lookup in interface CacheManager


lookupFc

public Object lookupFc(String s)


setAutoCleanSize

public void setAutoCleanSize(String size)
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


setAutoCleanThreshold

public void setAutoCleanThreshold(String size)
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


setMaxObjects

public void setMaxObjects(int size)
            throws IllegalArgumentException,
                   CacheException
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:
CacheException - if it is not possible to reduce the cache size because all entries are fixed.


setMemorySize

public void setMemorySize(int size)
            throws IllegalArgumentException
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).


startFc

public void startFc()


stopFc

public void stopFc()


touch

public void touch(CacheEntry ce)
            throws CacheException
Specified by:
touch in interface CacheManager


unbind

public boolean unbind(Object oid,
                      boolean force)
            throws CacheException
Specified by:
unbind in interface UnbindManager


unbindAll

public Collection unbindAll(Collection oids,
                            boolean force)
            throws CacheException
Specified by:
unbindAll in interface UnbindManager


unbindFc

public void unbindFc(String s)


unbindUnfixed

public Collection unbindUnfixed(boolean force)
            throws CacheException
Specified by:
unbindUnfixed in interface UnbindManager


unfix

public void unfix(CacheEntry ce)
            throws CacheException
Specified by:
unfix in interface CacheManager


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