org.norther.tammi.core.cache
Class DefaultResourceCache

java.lang.Object
  extended by org.norther.tammi.acorn.cache.CachedMapAdapter
      extended by org.norther.tammi.core.cache.DefaultCache
          extended by org.norther.tammi.core.cache.DefaultResourceCache
All Implemented Interfaces:
Serializable, ConcurrentMap, Map, NotificationBroadcaster, NotificationEmitter, CachedMap, Manageable, Cache, ResourceCache

public class DefaultResourceCache
extends DefaultCache
implements ResourceCache

A default implementation of ResourceCache.

Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.norther.tammi.core.cache.DefaultCache
DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR
 
Fields inherited from class org.norther.tammi.acorn.cache.CachedMapAdapter
DEFAULT_EXPIRATION_SLEEP_INTERVAL, DEFAULT_EXPIRATION_TIME
 
Constructor Summary
DefaultResourceCache()
          Constructs a new resource cache.
DefaultResourceCache(int max)
          Constructs a new resource cache with max expiration time.
DefaultResourceCache(int max, int def)
          Constructs a new resource cache with max and default expiration times.
DefaultResourceCache(int max, int def, int sleep)
          Constructs a new resource cache with max and default expiration times and expiration sleep interval.
DefaultResourceCache(int max, int def, int sleep, int capacity)
          Constructs a new resource cache with max and default expiration times, an expiration sleep interval and initial capacity.
DefaultResourceCache(int max, int def, int sleep, int capacity, float loadFactor)
          Constructs a new resource cache with max and default expiration times, an expiration sleep interval, initial capacity and load factor.
 
Method Summary
 long getCheckInterval()
          Gets the interval of checking validity of cached resources.
 Resource getResource(String key)
          Gets the cached resource.
 String getResourceClassName()
          Gets the name of the cached resource class to apply inside this cache.
 int getSizeLimit()
          Gets the size limit for resources to be kept in the cache.
 Resource putResource(String key, Object src)
          Puts the specified object as a resource into the cache.
 Resource putResource(String key, Object src, int freq)
          Puts the specified object with an expiration frequency as a resource into the cache.
 Resource removeResource(String key)
          Removes the cached resource.
 void setCheckInterval(long msecs)
          Gets the interval of checking validity of cached resources.
 void setResource(String key, Resource res)
          Sets the cached resource.
 void setResource(String key, Resource res, int freq)
          Sets the cached resource with an expiration frequency.
 void setResourceClassName(String className)
          Sets the name of the cached resource class to apply inside this cache.
 void setSizeLimit(int limit)
          Sets a size limit for resources to be kept in the cache.
 
Methods inherited from class org.norther.tammi.core.cache.DefaultCache
addNotificationListener, getMBeanDelegate, getNotificationInfo, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, setAllowExpired, setDefaultExpirationTime, setDiscardOverloaded, setExpirationLimit, setExpirationSleepInterval, setExpirationThreshold, setMaxExpirationTime, toString, unmanaged
 
Methods inherited from class org.norther.tammi.acorn.cache.CachedMapAdapter
add, add, clear, containsKey, containsValue, entrySet, equals, expire, expireAll, expireFraction, get, get, getDefaultExpirationTime, getExpirationLimit, getExpirationSleepInterval, getExpirationThreshold, getExpirationTimer, getMaxExpirationTime, getSwapOutHandler, hashCode, isAllowExpired, isAutoRefreshDeclined, isDiscardOverloaded, isEmpty, keySet, put, put, putAll, putIfAbsent, putIfAbsent, refresh, refresh, remove, remove, replace, replace, setAutoRefreshDeclined, setExpirationTimer, setSwapOutHandler, size, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.acorn.cache.CachedMap
add, add, expire, expireAll, expireFraction, get, getDefaultExpirationTime, getExpirationLimit, getExpirationSleepInterval, getExpirationThreshold, getMaxExpirationTime, isAllowExpired, isAutoRefreshDeclined, isDiscardOverloaded, put, putIfAbsent, refresh, refresh, setAllowExpired, setAutoRefreshDeclined, setDefaultExpirationTime, setDiscardOverloaded, setExpirationLimit, setExpirationSleepInterval, setExpirationThreshold, setMaxExpirationTime
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

DefaultResourceCache

public DefaultResourceCache()
Constructs a new resource cache.


DefaultResourceCache

public DefaultResourceCache(int max)
Constructs a new resource cache with max expiration time.

Parameters:
max - a max expiration time (0 = default, -1 = infinite).

DefaultResourceCache

public DefaultResourceCache(int max,
                            int def)
Constructs a new resource cache with max and default expiration times.

Parameters:
max - a max expiration time (0 = default, -1 = infinite).
def - a default expiration time (0 = default, -1 = infinite).

DefaultResourceCache

public DefaultResourceCache(int max,
                            int def,
                            int sleep)
Constructs a new resource cache with max and default expiration times and expiration sleep interval.

Parameters:
max - a max expiration time (0 = default, -1 = infinite).
def - a default expiration time (0 = default, -1 = infinite).
sleep - an expiration sleep interval (0 = default, -1 = infinite).

DefaultResourceCache

public DefaultResourceCache(int max,
                            int def,
                            int sleep,
                            int capacity)
Constructs a new resource cache with max and default expiration times, an expiration sleep interval and initial capacity.

Parameters:
max - a max expiration time (0 = default, -1 = infinite).
def - a default expiration time (0 = default, -1 = infinite).
sleep - an expiration sleep interval (0 = default, -1 = infinite).
capacity - an initial capacity.

DefaultResourceCache

public DefaultResourceCache(int max,
                            int def,
                            int sleep,
                            int capacity,
                            float loadFactor)
Constructs a new resource cache with max and default expiration times, an expiration sleep interval, initial capacity and load factor.

Parameters:
max - a max expiration time (0 = default, -1 = infinite).
def - a default expiration time (0 = default, -1 = infinite).
sleep - an expiration sleep interval (0 = default, -1 = infinite).
capacity - an initial capacity.
loadFactor - a load factor.
Method Detail

getCheckInterval

public long getCheckInterval()
Description copied from interface: ResourceCache
Gets the interval of checking validity of cached resources.

Specified by:
getCheckInterval in interface ResourceCache
Returns:
the check interval in milliseconds.

setCheckInterval

public void setCheckInterval(long msecs)
Description copied from interface: ResourceCache
Gets the interval of checking validity of cached resources.

Specified by:
setCheckInterval in interface ResourceCache
Parameters:
msecs - the check interval in milliseconds (-1 = only once).

getSizeLimit

public int getSizeLimit()
Description copied from interface: ResourceCache
Gets the size limit for resources to be kept in the cache.

Specified by:
getSizeLimit in interface ResourceCache
Returns:
the limit for a resource size in bytes.

setSizeLimit

public void setSizeLimit(int limit)
Description copied from interface: ResourceCache
Sets a size limit for resources to be kept in the cache.

Specified by:
setSizeLimit in interface ResourceCache
Parameters:
limit - a limit for a resource size in bytes (-1 = unlimited).

getResourceClassName

public String getResourceClassName()
Description copied from interface: ResourceCache
Gets the name of the cached resource class to apply inside this cache. The class must implement the CachedResource interface and have a public constructor CachedResource((String) name, (Object) source).

Specified by:
getResourceClassName in interface ResourceCache
Returns:
the class name of the cached resource.

setResourceClassName

public void setResourceClassName(String className)
Description copied from interface: ResourceCache
Sets the name of the cached resource class to apply inside this cache. The class must implement the CachedResource interface and have a public constructor CachedResource((String) name, (Object) source).

Specified by:
setResourceClassName in interface ResourceCache
Parameters:
className - the class name of the cached resource.

getResource

public Resource getResource(String key)
Description copied from interface: ResourceCache
Gets the cached resource.

Specified by:
getResource in interface ResourceCache
Parameters:
key - the key of the cached resource.
Returns:
the cached resource, or null if not cached.

setResource

public void setResource(String key,
                        Resource res)
Description copied from interface: ResourceCache
Sets the cached resource.

Note that the size limit is not applied.

Specified by:
setResource in interface ResourceCache
Parameters:
key - the key of the cached resource.
res - the cached resource.

setResource

public void setResource(String key,
                        Resource res,
                        int freq)
Description copied from interface: ResourceCache
Sets the cached resource with an expiration frequency.

Note that the size limit is not applied.

Specified by:
setResource in interface ResourceCache
Parameters:
key - the key of the cached resource.
res - the cached resource.
freq - the expiration frequency.

putResource

public Resource putResource(String key,
                            Object src)
                     throws ConstructionException
Description copied from interface: ResourceCache
Puts the specified object as a resource into the cache. An existing resource mapped to the specified key is replaced with the given one if they are not equal.

Specified by:
putResource in interface ResourceCache
Parameters:
key - the key of the cached object.
src - the object to cache.
Returns:
the cached resource.
Throws:
ConstructionException - if construction fails.

putResource

public Resource putResource(String key,
                            Object src,
                            int freq)
                     throws ConstructionException
Description copied from interface: ResourceCache
Puts the specified object with an expiration frequency as a resource into the cache. An existing resource mapped to the specified key is replaced with the given one if they are not equal.

Specified by:
putResource in interface ResourceCache
Parameters:
key - the key of the cached object.
src - the object to cache.
freq - the expiration frequency.
Returns:
the cached resource.
Throws:
ConstructionException - if construction fails.

removeResource

public Resource removeResource(String key)
Description copied from interface: ResourceCache
Removes the cached resource.

Specified by:
removeResource in interface ResourceCache
Parameters:
key - the key of the cached resource.
Returns:
the removed resource.


Copyright © 2004 The Norther Organization. All rights reserved.