org.norther.tammi.core.cache
Class DefaultSharedCache

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.DefaultSharedCache
All Implemented Interfaces:
Serializable, ConcurrentMap, Map, NotificationBroadcaster, NotificationEmitter, CachedMap, Manageable, Cache, SharedCache

public class DefaultSharedCache
extends DefaultCache
implements SharedCache, NotificationEmitter

A default implementation of SharedCache.

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
static String SHARED_CACHE_NOTIF_DESCRIPTION
          The notification description.
static ModelMBeanNotificationInfo[] SHARED_CACHE_NOTIFICATIONS
          Shared cache notifications.
 
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
DefaultSharedCache()
          Constructs a new cache.
DefaultSharedCache(int max)
          Constructs a new cache with a max expiration time.
DefaultSharedCache(int max, int def)
          Constructs a new cache with max and default expiration times.
DefaultSharedCache(int max, int def, int sleep)
          Constructs a new cache with max and default expiration times and expiration sleep interval.
DefaultSharedCache(int max, int def, int sleep, int capacity)
          Constructs a new cache with max and default expiration times, an expiration sleep interval and initial capacity.
DefaultSharedCache(int max, int def, int sleep, int capacity, float loadFactor)
          Constructs a new cache with max and default expiration times, an expiration sleep interval, initial capacity and load factor.
 
Method Summary
 void clear(String domain)
          Clears the specified domain map.
 void clearDomains()
          Clears all domain caches.
 boolean containsDomain(String domain)
          Checks whether a domain has a cache.
 boolean containsKey(String domain, Object key)
          Checks a key from the specified domain map.
 boolean containsValue(String domain, Object obj)
          Checks a value from the specified domain map.
 Set domainSet()
          Returns a set of defined domains.
 Set entrySet(String domain)
          Gets an entry set from the specified domain map.
 Object expire(String domain, Object key)
          Expires and removes a value from the specified domain map.
 void expireAll(String domain)
          Expires all values from the specified domain map.
 void expireAllDomains()
          Expires all values from all domain caches.
 void expireFraction(String domain, float fraction)
          Expires a fraction of entries.
 Object get(String domain, Object key)
          Gets a value from the specified domain map.
 Object get(String domain, Object key, int freq)
          Gets a value from the the specified domain map and refreshes it with a specified expiration frequency.
 int getDefaultExpirationTime(String domain)
          Gets the default expiration time of the domain in seconds.
 CachedMap getDomainCache(String domain)
          Gets the cache of the specified domain.
 CachedMap getDomainCache(String domain, boolean create)
          Gets and optionally creates the cache of the specified domain.
 int getExpirationLimit(String domain)
          Gets the expiration limit in the domain.
 int getExpirationSleepInterval(String domain)
          Gets the expiration sleep interval of the domain in seconds.
 float getExpirationThreshold(String domain)
          Gets the expiration threshold in the domain.
 int getMaxExpirationTime(String domain)
          Gets the maximum expiration time of the domain in seconds.
 MBeanNotificationInfo[] getNotificationInfo()
           
 boolean isAllowExpired(String domain)
          Gets the allow expired option of the domain.
 boolean isDiscardOverloaded(String domain)
          Gets the discard overloaded option of the domain.
 boolean isEmpty(String domain)
          Checks if the specified domain map is empty.
 Set keySet(String domain)
          Gets a key set from the specified domain map.
 Object put(String domain, Object key, Object obj)
          Puts a value to the specified domain map.
 Object put(String domain, Object key, Object obj, int freq)
          Puts a value to the specified domain map with a value specific expiration frequency.
 void putAll(String domain, Map map)
          Puts a map to the specified domain map.
 boolean refresh(String domain, Object key)
          Refreshes a value in the specified domain map.
 boolean refresh(String domain, Object key, int freq)
          Refreshes a value in the specified domain map with a new frequency.
 Object remove(String domain, Object key)
          Removes a value from the specified domain map.
 void removeDomain(String domain)
          Removes the specified domain.
 void setAllowExpired(String domain, boolean flag)
          Sets the allow expired option of the domain allowing gets of entries already expired but not yet removed by the expiration handler.
 void setDefaultExpirationTime(String domain, int t)
          Sets the default expiration time of the domain in seconds.
 void setDiscardOverloaded(String domain, boolean flag)
          Sets the discard overloaded option of the domain.
 void setExpirationLimit(String domain, int c)
          Sets the expiration limit in the domain.
 void setExpirationSleepInterval(String domain, int t)
          Sets the expiration sleep interval of the domain in seconds.
 void setExpirationThreshold(String domain, float h)
          Gets the expiration threshold in the domain.
 void setMaxExpirationTime(String domain, int t)
          Sets the maximum expiration time of the domain in seconds.
 int size(String domain)
          Gets the size of the specified domain map.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 Collection values(String domain)
          Gets a collection of values from the specified domain map.
 
Methods inherited from class org.norther.tammi.core.cache.DefaultCache
addNotificationListener, getMBeanDelegate, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, setAllowExpired, setDefaultExpirationTime, setDiscardOverloaded, setExpirationLimit, setExpirationSleepInterval, setExpirationThreshold, setMaxExpirationTime, toString
 
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
 
Methods inherited from interface javax.management.NotificationEmitter
removeNotificationListener
 
Methods inherited from interface javax.management.NotificationBroadcaster
addNotificationListener, removeNotificationListener
 

Field Detail

SHARED_CACHE_NOTIF_DESCRIPTION

public static final String SHARED_CACHE_NOTIF_DESCRIPTION
The notification description.

See Also:
Constant Field Values

SHARED_CACHE_NOTIFICATIONS

public static final ModelMBeanNotificationInfo[] SHARED_CACHE_NOTIFICATIONS
Shared cache notifications.

Constructor Detail

DefaultSharedCache

public DefaultSharedCache()
Constructs a new cache.


DefaultSharedCache

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

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

DefaultSharedCache

public DefaultSharedCache(int max,
                          int def)
Constructs a new 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).

DefaultSharedCache

public DefaultSharedCache(int max,
                          int def,
                          int sleep)
Constructs a new 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).

DefaultSharedCache

public DefaultSharedCache(int max,
                          int def,
                          int sleep,
                          int capacity)
Constructs a new 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.

DefaultSharedCache

public DefaultSharedCache(int max,
                          int def,
                          int sleep,
                          int capacity,
                          float loadFactor)
Constructs a new 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

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class DefaultCache
Throws:
Exception - if the adaptee refused to be unmanaged.

isAllowExpired

public boolean isAllowExpired(String domain)
Description copied from interface: SharedCache
Gets the allow expired option of the domain.

Specified by:
isAllowExpired in interface SharedCache
Parameters:
domain - the domain.
Returns:
the allow expired option.

setAllowExpired

public void setAllowExpired(String domain,
                            boolean flag)
Description copied from interface: SharedCache
Sets the allow expired option of the domain allowing gets of entries already expired but not yet removed by the expiration handler.

Specified by:
setAllowExpired in interface SharedCache
Parameters:
domain - the domain.
flag - the allow expired option.

isDiscardOverloaded

public boolean isDiscardOverloaded(String domain)
Description copied from interface: SharedCache
Gets the discard overloaded option of the domain.

Specified by:
isDiscardOverloaded in interface SharedCache
Parameters:
domain - the domain.
Returns:
true if new puts are discarded if overloaded, false otherwise.

setDiscardOverloaded

public void setDiscardOverloaded(String domain,
                                 boolean flag)
Description copied from interface: SharedCache
Sets the discard overloaded option of the domain. If set to true, new entries are discarded and an exception thrown when the capacity of the cache is exceeded. The default policy is to expire old entries until enough capacity is available.

Specified by:
setDiscardOverloaded in interface SharedCache
Parameters:
domain - the domain.
flag - true if new puts are discarded if overloaded, false otherwise.

getMaxExpirationTime

public int getMaxExpirationTime(String domain)
Description copied from interface: SharedCache
Gets the maximum expiration time of the domain in seconds.

Specified by:
getMaxExpirationTime in interface SharedCache
Parameters:
domain - the domain.
Returns:
the secs.

setMaxExpirationTime

public void setMaxExpirationTime(String domain,
                                 int t)
Description copied from interface: SharedCache
Sets the maximum expiration time of the domain in seconds.

Specified by:
setMaxExpirationTime in interface SharedCache
Parameters:
domain - the domain.
t - the secs.

getDefaultExpirationTime

public int getDefaultExpirationTime(String domain)
Description copied from interface: SharedCache
Gets the default expiration time of the domain in seconds.

Specified by:
getDefaultExpirationTime in interface SharedCache
Parameters:
domain - the domain.
Returns:
the secs.

setDefaultExpirationTime

public void setDefaultExpirationTime(String domain,
                                     int t)
Description copied from interface: SharedCache
Sets the default expiration time of the domain in seconds.

Specified by:
setDefaultExpirationTime in interface SharedCache
Parameters:
domain - the domain.
t - the secs.

getExpirationSleepInterval

public int getExpirationSleepInterval(String domain)
Description copied from interface: SharedCache
Gets the expiration sleep interval of the domain in seconds.

Specified by:
getExpirationSleepInterval in interface SharedCache
Parameters:
domain - the domain.
Returns:
the secs.

setExpirationSleepInterval

public void setExpirationSleepInterval(String domain,
                                       int t)
Description copied from interface: SharedCache
Sets the expiration sleep interval of the domain in seconds.

Specified by:
setExpirationSleepInterval in interface SharedCache
Parameters:
domain - the domain.
t - the secs

getExpirationLimit

public int getExpirationLimit(String domain)
Description copied from interface: SharedCache
Gets the expiration limit in the domain.

Specified by:
getExpirationLimit in interface SharedCache
Parameters:
domain - the domain.
Returns:
the limit.

setExpirationLimit

public void setExpirationLimit(String domain,
                               int c)
Description copied from interface: SharedCache
Sets the expiration limit in the domain.

Specified by:
setExpirationLimit in interface SharedCache
Parameters:
domain - the domain.
c - the limit.

getExpirationThreshold

public float getExpirationThreshold(String domain)
Description copied from interface: SharedCache
Gets the expiration threshold in the domain.

Specified by:
getExpirationThreshold in interface SharedCache
Parameters:
domain - the domain.
Returns:
the threshold.

setExpirationThreshold

public void setExpirationThreshold(String domain,
                                   float h)
Description copied from interface: SharedCache
Gets the expiration threshold in the domain.

Specified by:
setExpirationThreshold in interface SharedCache
Parameters:
domain - the domain.
h - the threshold.

clear

public void clear(String domain)
Description copied from interface: SharedCache
Clears the specified domain map.

Specified by:
clear in interface SharedCache
Parameters:
domain - the domain.

containsKey

public boolean containsKey(String domain,
                           Object key)
Description copied from interface: SharedCache
Checks a key from the specified domain map.

Specified by:
containsKey in interface SharedCache
Parameters:
domain - the domain.
key - the key to check.
Returns:
true if the key was found.

containsValue

public boolean containsValue(String domain,
                             Object obj)
Description copied from interface: SharedCache
Checks a value from the specified domain map.

Specified by:
containsValue in interface SharedCache
Parameters:
domain - the domain.
obj - the value to check.
Returns:
true if the value was found.

entrySet

public Set entrySet(String domain)
Description copied from interface: SharedCache
Gets an entry set from the specified domain map.

Specified by:
entrySet in interface SharedCache
Parameters:
domain - the domain.
Returns:
an entry set.

keySet

public Set keySet(String domain)
Description copied from interface: SharedCache
Gets a key set from the specified domain map.

Specified by:
keySet in interface SharedCache
Parameters:
domain - the domain.
Returns:
a key set.

values

public Collection values(String domain)
Description copied from interface: SharedCache
Gets a collection of values from the specified domain map.

Specified by:
values in interface SharedCache
Parameters:
domain - the domain.
Returns:
a collection.

get

public Object get(String domain,
                  Object key)
Description copied from interface: SharedCache
Gets a value from the specified domain map.

Specified by:
get in interface SharedCache
Parameters:
domain - the domain.
key - the key.
Returns:
the value or null.

put

public Object put(String domain,
                  Object key,
                  Object obj)
Description copied from interface: SharedCache
Puts a value to the specified domain map.

Specified by:
put in interface SharedCache
Parameters:
domain - the domain.
key - the key.
obj - the value.
Returns:
the previous value or null.

putAll

public void putAll(String domain,
                   Map map)
Description copied from interface: SharedCache
Puts a map to the specified domain map.

Specified by:
putAll in interface SharedCache
Parameters:
domain - the domain.
map - the map.

remove

public Object remove(String domain,
                     Object key)
Description copied from interface: SharedCache
Removes a value from the specified domain map.

Specified by:
remove in interface SharedCache
Parameters:
domain - the domain.
key - the key.
Returns:
the removed value or null.

size

public int size(String domain)
Description copied from interface: SharedCache
Gets the size of the specified domain map.

Specified by:
size in interface SharedCache
Parameters:
domain - the domain.
Returns:
the size.

isEmpty

public boolean isEmpty(String domain)
Description copied from interface: SharedCache
Checks if the specified domain map is empty.

Specified by:
isEmpty in interface SharedCache
Parameters:
domain - the domain.
Returns:
true if the map is empty.

get

public Object get(String domain,
                  Object key,
                  int freq)
Description copied from interface: SharedCache
Gets a value from the the specified domain map and refreshes it with a specified expiration frequency.

Specified by:
get in interface SharedCache
Parameters:
domain - the domain.
key - the key.
freq - the expiration frequency.
Returns:
the value or null.

put

public Object put(String domain,
                  Object key,
                  Object obj,
                  int freq)
Description copied from interface: SharedCache
Puts a value to the specified domain map with a value specific expiration frequency.

Specified by:
put in interface SharedCache
Parameters:
domain - the domain.
key - the key.
obj - the value.
freq - the expiration frequency.
Returns:
the previous value or null.

refresh

public boolean refresh(String domain,
                       Object key)
Description copied from interface: SharedCache
Refreshes a value in the specified domain map.

Specified by:
refresh in interface SharedCache
Parameters:
domain - the domain.
key - the key.
Returns:
true if refreshed, false otherwise.

refresh

public boolean refresh(String domain,
                       Object key,
                       int freq)
Description copied from interface: SharedCache
Refreshes a value in the specified domain map with a new frequency.

Specified by:
refresh in interface SharedCache
Parameters:
domain - the domain.
key - the key.
freq - the expiration frequency.
Returns:
true if refreshed, false otherwise.

expire

public Object expire(String domain,
                     Object key)
Description copied from interface: SharedCache
Expires and removes a value from the specified domain map.

Specified by:
expire in interface SharedCache
Parameters:
domain - the domain.
key - the key.
Returns:
the expired value or null.

expireAll

public void expireAll(String domain)
Description copied from interface: SharedCache
Expires all values from the specified domain map.

Specified by:
expireAll in interface SharedCache
Parameters:
domain - the domain.

expireFraction

public void expireFraction(String domain,
                           float fraction)
Description copied from interface: SharedCache
Expires a fraction of entries.

Specified by:
expireFraction in interface SharedCache
Parameters:
domain - the domain.
fraction - the fraction to expire (0.0..1.0).

getDomainCache

public CachedMap getDomainCache(String domain)
Description copied from interface: SharedCache
Gets the cache of the specified domain.

Specified by:
getDomainCache in interface SharedCache
Parameters:
domain - the domain.
Returns:
the domain cache or null.

getDomainCache

public CachedMap getDomainCache(String domain,
                                boolean create)
Description copied from interface: SharedCache
Gets and optionally creates the cache of the specified domain.

Specified by:
getDomainCache in interface SharedCache
Parameters:
domain - the domain.
create - true to create a missing cache.
Returns:
the domain cache.

containsDomain

public boolean containsDomain(String domain)
Description copied from interface: SharedCache
Checks whether a domain has a cache.

Specified by:
containsDomain in interface SharedCache
Parameters:
domain - the domain.
Returns:
true if the domain was found.

removeDomain

public void removeDomain(String domain)
Description copied from interface: SharedCache
Removes the specified domain.

Specified by:
removeDomain in interface SharedCache
Parameters:
domain - the domain.

domainSet

public Set domainSet()
Description copied from interface: SharedCache
Returns a set of defined domains.

Specified by:
domainSet in interface SharedCache
Returns:
a read-only set of domains.

clearDomains

public void clearDomains()
Description copied from interface: SharedCache
Clears all domain caches.

Specified by:
clearDomains in interface SharedCache

expireAllDomains

public void expireAllDomains()
Description copied from interface: SharedCache
Expires all values from all domain caches.

Specified by:
expireAllDomains in interface SharedCache

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()
Specified by:
getNotificationInfo in interface NotificationBroadcaster
Overrides:
getNotificationInfo in class DefaultCache


Copyright © 2004 The Norther Organization. All rights reserved.