stella.parameter
Class AbstractCachedParameter

java.lang.Object
  extended by util.PropertyContainer
      extended by stella.parameter.AbstractParameter
          extended by stella.parameter.AbstractCachedParameter
All Implemented Interfaces:
Cloneable, Parameter, ExitCleaning, Initializable, PropertyBearing
Direct Known Subclasses:
AbstractStatusRequestor, PilarParameter

public abstract class AbstractCachedParameter
extends AbstractParameter

An abstract base class providing the functionalibility of a parameter that can cache its value, if getting is too expensive to be commenced at any time. The KEY_CACHE points to the time (in ms) the cached value stays valid.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyContainer
PropertyContainer.URLResource
 
Field Summary
private  Object cache
          The cached value.
private static long DEFCACHE
          The default cache-valid time.
static String KEY_CACHE
          The cache-valid time.
private  long update
          The time of laast cache update.
 
Fields inherited from class stella.parameter.AbstractParameter
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWN
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR, KEY_NOINITONCREATE, KEY_RESOURCEBUNDLES
 
Fields inherited from interface util.PropertyBearing
CONFIG, KEY_CLASS, KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected AbstractCachedParameter(Map prop)
          Constructs a new status requestor.
 
Method Summary
 Object get()
          Gets this parameter value.
 Object getCache()
          Returns the cached value, regardless of validity.
 String getCacheFormatted()
          Returns the formatted cache entry.
protected abstract  Object getUncached()
          This method is called to deliver uncached values.
 Object set(Object newcache)
          Sets the cache value.
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, exit, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, init, register, rescanned, setName, toString
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, clone, createFrom, createFrom, createFrom, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getLocalClassLoader, getLocalized, getLocalized, getLocalizedString, getLocalizedString, getProperties, getPropertiesToKey, getPropertiesToKey, getProperty, getResource, getResourceAsStream, getResourceFromKey, getResources, has, isNew, keyCreate, keyCreate, parseObject, reload, reload, removeProperty, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.PropertyBearing
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getLocalized, getProperties, getProperty, getResource, getResourceAsStream, getResources, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_CACHE

public static final String KEY_CACHE
The cache-valid time.

See Also:
Constant Field Values

DEFCACHE

private static final long DEFCACHE
The default cache-valid time.

See Also:
Constant Field Values

cache

private Object cache
The cached value.


update

private long update
The time of laast cache update.

Constructor Detail

AbstractCachedParameter

protected AbstractCachedParameter(Map prop)
Constructs a new status requestor. Throws an IllegalArgumentException if the #KEY_COMMAND class is not found or cannot be used to instantiate a CommandEvent. The cache time and the disable flag are defaulted.

Method Detail

get

public Object get()
Gets this parameter value. If the cache is up-to-date, the cached value is returned. Otherwise, the #urge command is sent to the registered command launcher #server. The method now waits on the error event returned from the server. As soon as this error event is received in the #registerError method, the cache is updated and the value returned.
For parameters that link to the same command, the #KEY_DISABLE flag is introduced. If this is set to true, command sending is prevented, and the cache value is returned. This is only useful, if at least two parameters listen to the same status event. Then, only the parameter with the shortest cache time should carry a non-disabled flag. It is important to avoid dead-lock situations by using different cache times on these parameters. Keep in mind that all parameters will be updated at the highest frequency, regardless


getCache

public Object getCache()
Returns the cached value, regardless of validity.


getCacheFormatted

public String getCacheFormatted()
Returns the formatted cache entry.


set

public Object set(Object newcache)
Sets the cache value. Sets the cache-update time to the current time.

Returns:
The previous value of this parameter.

getUncached

protected abstract Object getUncached()
This method is called to deliver uncached values.