org.norther.tammi.core.cache
Class DefaultCache<K,V>

java.lang.Object
  extended by org.norther.tammi.acorn.cache.CachedMapAdapter<K,V>
      extended by org.norther.tammi.core.cache.DefaultCache<K,V>
Type Parameters:
K - the type of keys maintained by the cache.
V - the type of cached values.
All Implemented Interfaces:
Serializable, ConcurrentMap<K,V>, Map<K,V>, NotificationBroadcaster, NotificationEmitter, CachedMap<K,V>, Manageable, Cache<K,V>
Direct Known Subclasses:
DefaultSessionManager, DefaultSharedCache

public class DefaultCache<K,V>
extends CachedMapAdapter<K,V>
implements Cache<K,V>, Manageable, NotificationEmitter

A default implementation of Cache.

Version:
$Id: DefaultCache.java,v 1.11 2009/09/28 15:08:43 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.norther.tammi.acorn.cache.CachedMap
CachedMap.Value<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected static int DEFAULT_CAPACITY
          The default capacity.
protected static float DEFAULT_LOAD_FACTOR
          The default load factor.
 
Fields inherited from class org.norther.tammi.acorn.cache.CachedMapAdapter
DEFAULT_EXPIRATION_SLEEP_INTERVAL, DEFAULT_EXPIRATION_TIME
 
Constructor Summary
DefaultCache()
          Constructs a new cached map.
DefaultCache(int max)
          Constructs a new cache with max expiration time.
DefaultCache(int max, int def)
          Constructs a new cache with max and default expiration times.
DefaultCache(int max, int def, int sleep)
          Constructs a new cache with max and default expiration times and an expiration sleep interval.
DefaultCache(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.
DefaultCache(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 addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
           
protected  MBeanDelegate getMBeanDelegate()
          Gets the delegate to provide access to its methods for subclasses.
 MBeanNotificationInfo[] getNotificationInfo()
           
 void postmanaged()
          This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.
 void premanaged(MBeanDelegate adapter)
          This method is called when the implementing adaptee is trying to be managed either during pre-registration of the corresponding adapter MBean or just before it is explicitly added to the adapter MBean during run-time.
 void removeNotificationListener(NotificationListener listener)
           
 void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
           
 void setAllowExpired(boolean flag)
          Sets the allow expired option allowing gets of entries already expired but not yet removed by the expiration handler.
 void setDefaultExpirationTime(int t)
          Sets the default expiration time in seconds.
 void setDiscardOverloaded(boolean flag)
          Sets the discard overloaded option.
 void setExpirationLimit(int c)
          Sets the expiration limit for the number of cached entries.
 void setExpirationSleepInterval(int t)
          Sets the expiration sleep interval in seconds.
 void setExpirationThreshold(float h)
          Sets the threshold relative to the entry limit before expiration of excessive entries starts.
 void setMaxExpirationTime(int t)
          Sets the maximum expiration time in seconds.
 String toString()
           
 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.
 
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, setAutoRefreshDeclined
 
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
 

Field Detail

DEFAULT_CAPACITY

protected static final int DEFAULT_CAPACITY
The default capacity.

See Also:
Constant Field Values

DEFAULT_LOAD_FACTOR

protected static final float DEFAULT_LOAD_FACTOR
The default load factor.

See Also:
Constant Field Values
Constructor Detail

DefaultCache

public DefaultCache()
Constructs a new cached map.


DefaultCache

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

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

DefaultCache

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

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

DefaultCache

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

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

DefaultCache

public DefaultCache(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 in secs (0 = default, -1 = infinite).
def - a default expiration time in secs (0 = default, -1 = infinite).
sleep - an expiration sleep interval in secs (0 = default, -1 = infinite).
capacity - an initial capacity.

DefaultCache

public DefaultCache(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 in secs (0 = default, -1 = infinite).
def - a default expiration time in secs (0 = default, -1 = infinite).
sleep - an expiration sleep interval in secs (0 = default, -1 = infinite).
capacity - an initial capacity.
loadFactor - a load factor.
Method Detail

toString

public String toString()
Overrides:
toString in class CachedMapAdapter<K,V>

premanaged

public void premanaged(MBeanDelegate adapter)
                throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is trying to be managed either during pre-registration of the corresponding adapter MBean or just before it is explicitly added to the adapter MBean during run-time.

Specified by:
premanaged in interface Manageable
Parameters:
adapter - the managing adapter.
Throws:
Exception - if the adaptee refused to be managed.

postmanaged

public void postmanaged()
Description copied from interface: Manageable
This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.

Specified by:
postmanaged in interface Manageable

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
Throws:
Exception - if the adaptee refused to be unmanaged.

setAllowExpired

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

Specified by:
setAllowExpired in interface CachedMap<K,V>
Overrides:
setAllowExpired in class CachedMapAdapter<K,V>
Parameters:
flag - the allow expired option.

setDiscardOverloaded

public void setDiscardOverloaded(boolean flag)
Description copied from interface: CachedMap
Sets the discard overloaded option. 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 CachedMap<K,V>
Overrides:
setDiscardOverloaded in class CachedMapAdapter<K,V>
Parameters:
flag - true if new puts are discarded if overloaded, false otherwise.

setMaxExpirationTime

public void setMaxExpirationTime(int t)
Description copied from interface: CachedMap
Sets the maximum expiration time in seconds.

Specified by:
setMaxExpirationTime in interface CachedMap<K,V>
Overrides:
setMaxExpirationTime in class CachedMapAdapter<K,V>
Parameters:
t - the secs.

setExpirationSleepInterval

public void setExpirationSleepInterval(int t)
Description copied from interface: CachedMap
Sets the expiration sleep interval in seconds.

Specified by:
setExpirationSleepInterval in interface CachedMap<K,V>
Overrides:
setExpirationSleepInterval in class CachedMapAdapter<K,V>
Parameters:
t - the secs

setDefaultExpirationTime

public void setDefaultExpirationTime(int t)
Description copied from interface: CachedMap
Sets the default expiration time in seconds.

Specified by:
setDefaultExpirationTime in interface CachedMap<K,V>
Overrides:
setDefaultExpirationTime in class CachedMapAdapter<K,V>
Parameters:
t - the secs.

setExpirationLimit

public void setExpirationLimit(int c)
Description copied from interface: CachedMap
Sets the expiration limit for the number of cached entries.

Specified by:
setExpirationLimit in interface CachedMap<K,V>
Overrides:
setExpirationLimit in class CachedMapAdapter<K,V>
Parameters:
c - the expiration limit.

setExpirationThreshold

public void setExpirationThreshold(float h)
Description copied from interface: CachedMap
Sets the threshold relative to the entry limit before expiration of excessive entries starts. Values below 1.0 define the filling rate right after expiration and values above 1.0 define the filling rate just before expiration. The exact value 1.0 is not recommended as it starts expiration after every addition of entries when the filling rate is at the limit.

Specified by:
setExpirationThreshold in interface CachedMap<K,V>
Overrides:
setExpirationThreshold in class CachedMapAdapter<K,V>
Parameters:
h - the threshold.

addNotificationListener

public void addNotificationListener(NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
Specified by:
addNotificationListener in interface NotificationBroadcaster

removeNotificationListener

public void removeNotificationListener(NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
                                throws ListenerNotFoundException
Specified by:
removeNotificationListener in interface NotificationEmitter
Throws:
ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
                                throws ListenerNotFoundException
Specified by:
removeNotificationListener in interface NotificationBroadcaster
Throws:
ListenerNotFoundException

getNotificationInfo

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

getMBeanDelegate

protected MBeanDelegate getMBeanDelegate()
Gets the delegate to provide access to its methods for subclasses.

Returns:
the delegate.


Copyright © 2004 The Norther Organization. All rights reserved.