Save This Page
Home » JBoss-5.1.0 » org » jboss » util » [javadoc | source]
org.jboss.util
public class: TimedCachePolicy [javadoc | source]
java.lang.Object
   java.util.TimerTask
      org.jboss.util.TimedCachePolicy

All Implemented Interfaces:
    CachePolicy, Runnable

An implementation of a timed cache. This is a cache whose entries have a limited lifetime with the ability to refresh their lifetime. The entries managed by the cache implement the TimedCachePolicy.TimedEntry interface. If an object inserted into the cache does not implement this interface, it will be wrapped in a DefaultTimedEntry and will expire without the possibility of refresh after getDefaultLifetime() seconds. This is a lazy cache policy in that objects are not checked for expiration until they are accessed.
Nested Class Summary:
public static interface  TimedCachePolicy.TimedEntry  The interface that cache entries support. 
static class  TimedCachePolicy.DefaultTimedEntry  The default implementation of TimedEntry used to wrap non-TimedEntry objects inserted into the cache. 
Field Summary
public static final  String TIMER_CLASSLOADER_PROPERTY    Name of system property that this class consults to determine what classloader to assign to its static Timer 's thread. 
public static final  String TIMER_CLASSLOADER_SYSTEM    Value for #TIMER_CLASSLOADER_PROPERTY indicating the system classloader should be used. This is the default value if the system property is not set. 
public static final  String TIMER_CLASSLOADER_CURRENT    Value for #TIMER_CLASSLOADER_PROPERTY indicating the classloader that loaded this class should be used. 
public static final  String TIMER_CLASSLOADER_CONTEXT    Value for #TIMER_CLASSLOADER_PROPERTY indicating the thread context classloader in effect when this class is loaded should be used. 
protected static  Timer resolutionTimer     
protected  Map entryMap    The map of cached TimedEntry objects. 
protected  int defaultLifetime    The lifetime in seconds to use for objects inserted that do not implement the TimedEntry interface. 
protected  boolean threadSafe    A flag indicating if entryMap should be synchronized 
protected  long now    The caches notion of the current time 
protected  int resolution    The resolution in seconds of the cach current time 
protected  ResolutionTimer theTimer     
Fields inherited from java.util.TimerTask:
lock,  state,  VIRGIN,  SCHEDULED,  EXECUTED,  CANCELLED,  nextExecutionTime,  period
Constructor:
 public TimedCachePolicy() 
 public TimedCachePolicy(int defaultLifetime) 
 public TimedCachePolicy(int defaultLifetime,
    boolean threadSafe,
    int resolution) 
Method from org.jboss.util.TimedCachePolicy Summary:
create,   currentTimeMillis,   destroy,   flush,   get,   getDefaultLifetime,   getResolution,   getValidKeys,   insert,   peek,   peekEntry,   remove,   run,   setDefaultLifetime,   setResolution,   size,   start,   stop
Methods from java.util.TimerTask:
cancel,   run,   scheduledExecutionTime
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.jboss.util.TimedCachePolicy Detail:
 public  void create() 
    Initializes the cache for use. Prior to this the cache has no store.
 public long currentTimeMillis() 
    Get the cache time.
 public  void destroy() 
    Clears the cache of all entries.
 public  void flush() 
    Remove all entries from the cache.
 public Object get(Object key) 
    Get the cache value for key if it has not expired. If the TimedEntry is expired its destroy method is called and then removed from the cache.
 public int getDefaultLifetime() 
    Get the default lifetime of cache entries.
 public int getResolution() 
    Get the frequency of the current time snapshot.
 public List getValidKeys() 
    Get the list of keys for entries that are not expired.
 public  void insert(Object key,
    Object value) 
    Insert a value into the cache. In order to have the cache entry reshresh itself value would have to implement TimedEntry and implement the required refresh() method logic.
 public Object peek(Object key) 
    Get the cache value for key. This method does not check to see if the entry has expired.
 public TimedEntry peekEntry(Object key) 
    Get the raw TimedEntry for key without performing any expiration check.
 public  void remove(Object key) 
    Remove the entry associated with key and call destroy on the entry if found.
 public  void run() 
    The TimerTask run method. It updates the cache time to the current system time.
 public synchronized  void setDefaultLifetime(int defaultLifetime) 
    Set the default lifetime of cache entries for new values added to the cache.
 public synchronized  void setResolution(int resolution) 
    Set the cache timer resolution
 public int size() 
 public  void start() 
    Schedules this with the class resolutionTimer Timer object for execution every resolution seconds.
 public  void stop() 
    Stop cancels the resolution timer and flush()es the cache.