org.sakaiproject.component.framework.memory
Class BasicMemoryService

java.lang.Object
  extended byorg.sakaiproject.component.framework.memory.BasicMemoryService
All Implemented Interfaces:
MemoryService, Observer

public class BasicMemoryService
extends Object
implements MemoryService, Observer

MemoryService is an implementation for the MemoryService which reports memory usage and runs a periodic garbage collection to keep memory available.

Version:
$Revision: 3596 $
Author:
University of Michigan, Sakai Software Development Team

Field Summary
protected static String EVENT_RESET
          Event for the memory reset.
protected  boolean m_cacheLogging
          If true, output verbose caching info.
protected  Set m_cachers
          Set of registered cachers.
protected  EventTrackingService m_eventTrackingService
          Dependency: EventTrackingService.
protected  Logger m_logger
          Dependency: logging service.
 
Constructor Summary
BasicMemoryService()
           
 
Method Summary
 void destroy()
          Returns to uninitialized state.
protected  void doReset()
          Do a reset of all cachers
 long getAvailableMemory()
          Return the amount of available memory.
 boolean getCacheLogging()
           
 String getStatus()
          Compute a status report on all memory users
 void init()
          Final initialization, once all dependencies are set.
 Cache newCache()
          Construct a Cache. No automatic refresh handling.
 Cache newCache(CacheRefresher refresher, long sleep)
          Construct a Cache. Automatic refresh handling if refresher is not null.
 Cache newCache(CacheRefresher refresher, String pattern)
          Construct a Cache. Attempts to keep complete on Event notification by calling the refresher.
 Cache newHardCache()
          Construct a Cache. No automatic refresh handling.
 Cache newHardCache(CacheRefresher refresher, long sleep)
          Construct a Cache. Automatic refresh handling if refresher is not null.
 Cache newHardCache(CacheRefresher refresher, String pattern)
          Construct a special Cache that uses hard references. Attempts to keep complete on Event notification by calling the refresher.
 Cache newHardCache(long sleep, String pattern)
          Construct a Cache. No automatic refresh: expire only, from time and events.
 MultiRefCache newMultiRefCache(long sleep)
          Construct a multi-ref Cache. No automatic refresh: expire only, from time and events.
 SiteCache newSiteCache(long sleep, String pattern)
          Construct a special Site Cache. No automatic refresh: expire only, from time and events.
 void registerCacher(Cacher cacher)
          Register as a cache user
 void resetCachers()
          Cause less memory to be used by clearing any optional caches.
 void setCacheLogging(boolean value)
          Configuration: cache verbose debug
 void setEventTrackingService(EventTrackingService service)
          Dependency: EventTrackingService.
 void setLogger(Logger service)
          Dependency: logging service
 void unregisterCacher(Cacher cacher)
          Unregister as a cache user
 void update(Observable o, Object arg)
          This method is called whenever the observed object is changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVENT_RESET

protected static final String EVENT_RESET
Event for the memory reset.

See Also:
Constant Field Values

m_cachers

protected Set m_cachers
Set of registered cachers.


m_cacheLogging

protected boolean m_cacheLogging
If true, output verbose caching info.


m_eventTrackingService

protected EventTrackingService m_eventTrackingService
Dependency: EventTrackingService.


m_logger

protected Logger m_logger
Dependency: logging service.

Constructor Detail

BasicMemoryService

public BasicMemoryService()
Method Detail

setEventTrackingService

public void setEventTrackingService(EventTrackingService service)
Dependency: EventTrackingService.


setLogger

public void setLogger(Logger service)
Dependency: logging service


setCacheLogging

public void setCacheLogging(boolean value)
Configuration: cache verbose debug


getCacheLogging

public boolean getCacheLogging()

init

public void init()
Final initialization, once all dependencies are set.


destroy

public void destroy()
Returns to uninitialized state.


getAvailableMemory

public long getAvailableMemory()
Return the amount of available memory.

Specified by:
getAvailableMemory in interface MemoryService
Returns:
the amount of available memory.

resetCachers

public void resetCachers()
                  throws PermissionException
Cause less memory to be used by clearing any optional caches.

Specified by:
resetCachers in interface MemoryService
Throws:
PermissionException - if the current user does not have permission to do this.

getStatus

public String getStatus()
Compute a status report on all memory users

Specified by:
getStatus in interface MemoryService
Returns:
A status report of memory users.

doReset

protected void doReset()
Do a reset of all cachers


registerCacher

public void registerCacher(Cacher cacher)
Register as a cache user

Specified by:
registerCacher in interface MemoryService

unregisterCacher

public void unregisterCacher(Cacher cacher)
Unregister as a cache user

Specified by:
unregisterCacher in interface MemoryService

newCache

public Cache newCache(CacheRefresher refresher,
                      String pattern)
Construct a Cache. Attempts to keep complete on Event notification by calling the refresher.

Specified by:
newCache in interface MemoryService
Parameters:
refresher - The object that will handle refreshing of event notified modified or added entries.
pattern - The "startsWith()" string for all resources that may be in this cache - if null, don't watch events for updates.

newHardCache

public Cache newHardCache(CacheRefresher refresher,
                          String pattern)
Construct a special Cache that uses hard references. Attempts to keep complete on Event notification by calling the refresher.

Specified by:
newHardCache in interface MemoryService
Parameters:
refresher - The object that will handle refreshing of event notified modified or added entries.
pattern - The "startsWith()" string for all resources that may be in this cache - if null, don't watch events for updates.

newHardCache

public Cache newHardCache(long sleep,
                          String pattern)
Construct a Cache. No automatic refresh: expire only, from time and events.

Specified by:
newHardCache in interface MemoryService
Parameters:
sleep - The number of seconds to sleep between expiration checks.
pattern - The "startsWith()" string for all resources that may be in this cache - if null, don't watch events for expiration.

newCache

public Cache newCache(CacheRefresher refresher,
                      long sleep)
Construct a Cache. Automatic refresh handling if refresher is not null.

Specified by:
newCache in interface MemoryService
Parameters:
refresher - The object that will handle refreshing of expired entries.
sleep - The number of seconds to sleep between expiration checks.

newHardCache

public Cache newHardCache(CacheRefresher refresher,
                          long sleep)
Construct a Cache. Automatic refresh handling if refresher is not null.

Specified by:
newHardCache in interface MemoryService
Parameters:
refresher - The object that will handle refreshing of expired entries.
sleep - The number of seconds to sleep between expiration checks.

newCache

public Cache newCache()
Construct a Cache. No automatic refresh handling.

Specified by:
newCache in interface MemoryService

newHardCache

public Cache newHardCache()
Construct a Cache. No automatic refresh handling.

Specified by:
newHardCache in interface MemoryService

newSiteCache

public SiteCache newSiteCache(long sleep,
                              String pattern)
Construct a special Site Cache. No automatic refresh: expire only, from time and events.

Specified by:
newSiteCache in interface MemoryService
Parameters:
sleep - The number of seconds to sleep between expiration checks.
pattern - The "startsWith()" string for all resources that may be in this cache - if null, don't watch events for updates.

newMultiRefCache

public MultiRefCache newMultiRefCache(long sleep)
Construct a multi-ref Cache. No automatic refresh: expire only, from time and events.

Specified by:
newMultiRefCache in interface MemoryService
Parameters:
sleep - The number of seconds to sleep between expiration checks.

update

public void update(Observable o,
                   Object arg)
This method is called whenever the observed object is changed. An application calls an Observable object's notifyObservers method to have all the object's observers notified of the change. default implementation is to cause the courier service to deliver to the interface controlled by my controller. Extensions can override.

Specified by:
update in interface Observer
Parameters:
o - the observable object.
arg - an argument passed to the notifyObservers method.