org.castor.cache.hashbelt

Class AbstractHashbelt

Implemented Interfaces:
Cache, Map
Known Direct Subclasses:
FIFOHashbelt, LRUHashbelt

public abstract class AbstractHashbelt
extends AbstractBaseCache

An abstract, core implementation of the hashbelt functionality; individual implementations will differ on the underlying behavior.

A hashbelt has six important values which get set at initialization:


org.castor.cache.hashbelt.container.Container



org.castor.cache.hashbelt.reaper.NullReaperorg.castor.cahe.hashbelt.reaper.Reaper



Version:
$Revision: 6320 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
Authors:
Gregory Block
Ralf Joachim
Since:
1.0

Field Summary

static int
DEFAULT_CAPACITY
Default capacity of cache.
static int
DEFAULT_CONTAINERS
Default number of containers for cache.
static Class
DEFAULT_CONTAINER_CLASS
Default container class.
static int
DEFAULT_MONITOR
Default monitor interval of cache in minutes.
static Class
DEFAULT_REAPER_CLASS
Default reaper class.
static int
DEFAULT_TTL
Default ttl of cache in seconds.
static String
PARAM_CAPACITY
Mapped initialization parameter: capacity
static String
PARAM_CONTAINERS
Mapped initialization parameter: containers
static String
PARAM_CONTAINER_CLASS
Mapped initialization parameter: container-class
static String
PARAM_MONITOR
Mapped initialization parameter: monitor
static String
PARAM_REAPER_CLASS
Mapped initialization parameter: reaper-class
static String
PARAM_TTL
Mapped initialization parameter: ttl

Fields inherited from interface org.castor.cache.Cache

DEFAULT_DEBUG, DEFAULT_NAME, DEFAULT_TYPE, PARAM_DEBUG, PARAM_NAME, PARAM_TYPE

Method Summary

void
clear()
void
close()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set
entrySet()
int
getCapacity()
Get real capacity of this cache.
protected Object
getObjectFromCache(Object key)
Get object currently associated with given key from cache.
int
getTTL()
Get real ttl of this cache.
void
initialize(Properties params)
boolean
isEmpty()
Set
keySet()
protected ReadWriteLock
lock()
Get reference to the ReadWriteLock of this cache instance.
protected Object
putObjectIntoCache(Object key, Object value)
Put given value with given key in cache.
protected Object
removeObjectFromCache(Object key)
Remove any available association for given key.
int
size()
Collection
values()

Methods inherited from class org.castor.cache.AbstractBaseCache

close, expire, expireAll, getName, initialize, invokeMethod, invokeStaticMethod

Field Details

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
Default capacity of cache.
Field Value:
0

DEFAULT_CONTAINERS

public static final int DEFAULT_CONTAINERS
Default number of containers for cache.
Field Value:
10

DEFAULT_CONTAINER_CLASS

public static final Class DEFAULT_CONTAINER_CLASS
Default container class.

DEFAULT_MONITOR

public static final int DEFAULT_MONITOR
Default monitor interval of cache in minutes.
Field Value:
0

DEFAULT_REAPER_CLASS

public static final Class DEFAULT_REAPER_CLASS
Default reaper class.

DEFAULT_TTL

public static final int DEFAULT_TTL
Default ttl of cache in seconds.
Field Value:
60

PARAM_CAPACITY

public static final String PARAM_CAPACITY
Mapped initialization parameter: capacity

PARAM_CONTAINERS

public static final String PARAM_CONTAINERS
Mapped initialization parameter: containers

PARAM_CONTAINER_CLASS

public static final String PARAM_CONTAINER_CLASS
Mapped initialization parameter: container-class

PARAM_MONITOR

public static final String PARAM_MONITOR
Mapped initialization parameter: monitor

PARAM_REAPER_CLASS

public static final String PARAM_REAPER_CLASS
Mapped initialization parameter: reaper-class

PARAM_TTL

public static final String PARAM_TTL
Mapped initialization parameter: ttl

Method Details

clear

public final void clear()
See Also:
java.util.Map.clear()

close

public final void close()
Specified by:
close in interface Cache
Overrides:
close in interface AbstractBaseCache
See Also:
Cache.close()

containsKey

public final boolean containsKey(Object key)
See Also:
java.util.Map.containsKey(java.lang.Object)

containsValue

public final boolean containsValue(Object value)
See Also:
java.util.Map.containsValue(java.lang.Object)

entrySet

public final Set entrySet()
See Also:
java.util.Map.entrySet()

getCapacity

public final int getCapacity()
Get real capacity of this cache.
Returns:
Real capacity of this cache.

getObjectFromCache

protected final Object getObjectFromCache(Object key)
Get object currently associated with given key from cache. Take care to acquire a read or write lock before calling this method and release the lock thereafter.
Parameters:
key - The key to return the associated object for.
Returns:
The object associated with given key.

getTTL

public final int getTTL()
Get real ttl of this cache.
Returns:
Real ttl of this cache.

initialize

public final void initialize(Properties params)
            throws CacheAcquireException
Specified by:
initialize in interface Cache
Overrides:
initialize in interface AbstractBaseCache
See Also:
org.castor.cache.Cache.initialize(java.util.Properties)

isEmpty

public final boolean isEmpty()
See Also:
java.util.Map.isEmpty()

keySet

public final Set keySet()
See Also:
java.util.Map.keySet()

lock

protected final ReadWriteLock lock()
Get reference to the ReadWriteLock of this cache instance.
Returns:
ReadWriteLock to synchronize access to cache.

putObjectIntoCache

protected final Object putObjectIntoCache(Object key,
                                          Object value)
Put given value with given key in cache. Return the object previously associated with key. Take care to acquire a write lock before calling this method and release the lock thereafter.
Parameters:
key - The key to associate the given value with.
value - The value to associate with given key.
Returns:
The object previously associated with given key. null will be returned if no value has been associated with key.

removeObjectFromCache

protected final Object removeObjectFromCache(Object key)
Remove any available association for given key. Take care to acquire a write lock before calling this method and release the lock thereafter.
Parameters:
key - The key to remove any previously associate value for.
Returns:
The object previously associated with given key. null will be returned if no value has been associated with key.

size

public final int size()
See Also:
java.util.Map.size()

values

public final Collection values()
See Also:
java.util.Map.values()

Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com