org.norther.tammi.core.monitor
Class DefaultCacheMonitor

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.thread.DefaultExecutable
          extended by org.norther.tammi.core.monitor.DefaultCacheMonitor
All Implemented Interfaces:
Serializable, Runnable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, Refreshable, Startable, CacheClient, CacheMonitor, Executable

public class DefaultCacheMonitor
extends DefaultExecutable
implements CacheMonitor

The default implementation of CacheMonitor. The cache controlling methods do not affect the CacheMonitor itself.

Author:
Marketta Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultCacheMonitor()
           
 
Method Summary
 void clearCached()
          Clears cached entries in all registered CacheClientMBeans without notifying.
 void expireCached(long timestamp)
          Expires cached entries in all registered CacheClients notifying them about expiration.
 void expireFraction(long timestamp, float frac)
          Expires a fraction of cached entries in all registered CacheClients notifying them about expiration.
 void gc()
          Runs the garbage collector.
 ConcurrentMap getCache(boolean create)
          Gets the client cache which is always null for CacheMonitor.
 float getExpirationFraction()
          Gets the fraction of cached entries to expire when running low in memory.
 long getExpirationThreshold()
          Gets the threshold of available memory below which caches are expired.
 long getFreeMemory()
          Gets the amount of free memory in bytes.
 long getMaxMemory()
          Gets max amount of memory in bytes.
 long getRefreshed()
          Gets the last refresh timestamp.
 long getTotalMemory()
          Gets total amount of memory in bytes.
 boolean isCachingDisabled()
          Checks whether any registered CacheClientMBean has caching disabled.
 String logMemoryStatus()
          Logs memory status using the info logger.
 void refresh()
          Refreshes the MBean.
 void removeCache()
          Removes the cache which is always null for CacheMonitor.
 void run()
          A thread polling freed references (no need for internal synchronizations as Executable takes care of running this method only in one thread at a time).
 void setCachingDisabled(boolean flag)
          Sets the caching disabled flag for all registered CacheClientMBeans.
 void setExpirationFraction(float frac)
          Sets the fraction of cached entries to expire when running low in memory.
 void setExpirationThreshold(long thresh)
          Sets the threshold of available memory below which caches are expired.
 
Methods inherited from class org.norther.tammi.core.thread.DefaultExecutable
getExecutor, getExecutorName, isStarted, postmanaged, setExecutorName, start, stop, unmanaged
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.thread.Executable
getExecutorName, setExecutorName
 
Methods inherited from interface org.norther.tammi.core.base.Startable
isStarted, start, stop
 

Constructor Detail

DefaultCacheMonitor

public DefaultCacheMonitor()
Method Detail

isCachingDisabled

public boolean isCachingDisabled()
Checks whether any registered CacheClientMBean has caching disabled.

Specified by:
isCachingDisabled in interface CacheClient
Returns:
true if caching is disabled in any clients, otherwise false.

setCachingDisabled

public void setCachingDisabled(boolean flag)
Sets the caching disabled flag for all registered CacheClientMBeans.

Specified by:
setCachingDisabled in interface CacheClient
Parameters:
flag - the caching disabled flag.

expireCached

public void expireCached(long timestamp)
Expires cached entries in all registered CacheClients notifying them about expiration.

Specified by:
expireCached in interface CacheClient
Parameters:
timestamp - the timestamp of the expiration.

expireFraction

public void expireFraction(long timestamp,
                           float frac)
Expires a fraction of cached entries in all registered CacheClients notifying them about expiration.

Specified by:
expireFraction in interface CacheClient
Parameters:
timestamp - the timestamp of the expiration.
frac - the fraction of entries to expire.

clearCached

public void clearCached()
Clears cached entries in all registered CacheClientMBeans without notifying.

Specified by:
clearCached in interface CacheClient

getCache

public ConcurrentMap getCache(boolean create)
Gets the client cache which is always null for CacheMonitor.

Specified by:
getCache in interface CacheClient
Parameters:
create - ignored.
Returns:
always null.

removeCache

public void removeCache()
Removes the cache which is always null for CacheMonitor.

Specified by:
removeCache in interface CacheClient

refresh

public void refresh()
Description copied from interface: Refreshable
Refreshes the MBean.

Specified by:
refresh in interface Refreshable

getRefreshed

public long getRefreshed()
Description copied from interface: Refreshable
Gets the last refresh timestamp.

Specified by:
getRefreshed in interface Refreshable
Returns:
the timestamp of the last refresh.

getMaxMemory

public long getMaxMemory()
Description copied from interface: CacheMonitor
Gets max amount of memory in bytes.

Specified by:
getMaxMemory in interface CacheMonitor
Returns:
the max amount of memory in bytes.

getTotalMemory

public long getTotalMemory()
Description copied from interface: CacheMonitor
Gets total amount of memory in bytes.

Specified by:
getTotalMemory in interface CacheMonitor
Returns:
the total amount of memory in bytes.

getFreeMemory

public long getFreeMemory()
Description copied from interface: CacheMonitor
Gets the amount of free memory in bytes.

Specified by:
getFreeMemory in interface CacheMonitor
Returns:
the amount of free memory in bytes.

getExpirationThreshold

public long getExpirationThreshold()
Description copied from interface: CacheMonitor
Gets the threshold of available memory below which caches are expired.

Specified by:
getExpirationThreshold in interface CacheMonitor
Returns:
the cache expiration threshold in bytes.

setExpirationThreshold

public void setExpirationThreshold(long thresh)
Description copied from interface: CacheMonitor
Sets the threshold of available memory below which caches are expired.

Specified by:
setExpirationThreshold in interface CacheMonitor
Parameters:
thresh - the cache expiration threshold in bytes.

getExpirationFraction

public float getExpirationFraction()
Description copied from interface: CacheMonitor
Gets the fraction of cached entries to expire when running low in memory.

Specified by:
getExpirationFraction in interface CacheMonitor
Returns:
the cache expiration fraction (0.0..1.0).

setExpirationFraction

public void setExpirationFraction(float frac)
Description copied from interface: CacheMonitor
Sets the fraction of cached entries to expire when running low in memory.

Specified by:
setExpirationFraction in interface CacheMonitor
Parameters:
frac - the cache expiration fraction (0.0..1.0).

logMemoryStatus

public String logMemoryStatus()
Description copied from interface: CacheMonitor
Logs memory status using the info logger.

Specified by:
logMemoryStatus in interface CacheMonitor
Returns:
the memory status.

gc

public void gc()
Description copied from interface: CacheMonitor
Runs the garbage collector.

Specified by:
gc in interface CacheMonitor

run

public void run()
A thread polling freed references (no need for internal synchronizations as Executable takes care of running this method only in one thread at a time).

A freed soft reference indicates that memory is running out and therefore caches are expired in this case.

Specified by:
run in interface Runnable
Overrides:
run in class DefaultExecutable


Copyright © 2004 The Norther Organization. All rights reserved.