stella.parameter
Class AbstractStatusRequestor

java.lang.Object
  extended by util.PropertyContainer
      extended by stella.parameter.AbstractParameter
          extended by stella.parameter.AbstractCachedParameter
              extended by stella.parameter.AbstractStatusRequestor
All Implemented Interfaces:
Cloneable, ErrorDependingParameter, Parameter, StatusRequesting, ExitCleaning, Initializable, PropertyBearing
Direct Known Subclasses:
AltTelescope, AzTelescope, FocusPosition, MirrorTemperature, PowerTelescope, TelescopeError

public abstract class AbstractStatusRequestor
extends AbstractCachedParameter
implements StatusRequesting

An abstract base class providing the functionalibility of a StatusRequesting parameter. The KEY_COMMAND points to the class name of the command that is to be sent for an update of this parameter value. The AbstractCachedParameter.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 static boolean DEFDISABLE
          The default disable behaviour.
private static long DEFTIMEOUT
          The default status-request maximum time.
static String KEY_COMMAND
          The name of the command class to send for an update.
static String KEY_DISABLE
          The key pointing to true if command sending is disabled.
static String KEY_TIMEOUT
          The max.
private static Object lock
          A lock object to delay the AbstractCachedParameter.get() method until update occured.
private  CommandLaunching server
          The command launcher that takes the urge command.
private  CommandEvent urge
          The command to send that urges a status message sent back.
 
Fields inherited from class stella.parameter.AbstractCachedParameter
KEY_CACHE
 
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 stella.ErrorDependingParameter
NAMING_EXTENSION
 
Fields inherited from interface util.PropertyBearing
CONFIG, KEY_CLASS, KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected AbstractStatusRequestor(Map<String,String> prop)
          Constructs a new status requestor.
 
Method Summary
protected  Object getUncached()
          Gets this parameter value.
 void init()
          Inits the status requestor.
private  CommandEvent instantiateUrge(String comname)
          Tries to instantiate the command that should be sent to the command handling instance.
protected abstract  boolean isStatusRequested(ErrorEvent ee)
          Returns true, if the error event received is of the correct type for this parameter.
 void registerError(ErrorEvent ee)
          Test, if the error event received is the correct error event via a call to isStatusRequested(stella.ErrorEvent).
 boolean registerLauncher(CommandLaunching launch)
          Registers a command launcher.
protected  double rescanned(String key, String old, String newval)
          If the bind property changed, we deregister from our current binding and re-instantiate a new binding thread.
 
Methods inherited from class stella.parameter.AbstractCachedParameter
get, getCache, getCacheFormatted, set
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, exit, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, register, 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 stella.StatusRequesting
getCache, getCacheFormatted
 
Methods inherited from interface stella.ErrorDependingParameter
getForError
 
Methods inherited from interface stella.Parameter
get, getFormatted, getName, getString, set
 
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_COMMAND

public static final String KEY_COMMAND
The name of the command class to send for an update.

See Also:
Constant Field Values

KEY_DISABLE

public static final String KEY_DISABLE
The key pointing to true if command sending is disabled.

See Also:
Constant Field Values

KEY_TIMEOUT

public static final String KEY_TIMEOUT
The max. wait time for status receive.

See Also:
Constant Field Values

DEFDISABLE

private static final boolean DEFDISABLE
The default disable behaviour.

See Also:
Constant Field Values

DEFTIMEOUT

private static final long DEFTIMEOUT
The default status-request maximum time.

See Also:
Constant Field Values

urge

private CommandEvent urge
The command to send that urges a status message sent back.


server

private CommandLaunching server
The command launcher that takes the urge command.


lock

private static Object lock
A lock object to delay the AbstractCachedParameter.get() method until update occured.

Constructor Detail

AbstractStatusRequestor

protected AbstractStatusRequestor(Map<String,String> 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

init

public void init()
Inits the status requestor. This is delayed from construction because of possible default settings for KEY_COMMAND in daughter classes.

Specified by:
init in interface Initializable
Overrides:
init in class AbstractParameter

instantiateUrge

private CommandEvent instantiateUrge(String comname)
Tries to instantiate the command that should be sent to the command handling instance. Stores the command in urge as well as returning it.


rescanned

protected double rescanned(String key,
                           String old,
                           String newval)
If the bind property changed, we deregister from our current binding and re-instantiate a new binding thread.

Overrides:
rescanned in class AbstractParameter

registerLauncher

public boolean registerLauncher(CommandLaunching launch)
Registers a command launcher. If the launcher handles commands of the type of urge it is recognized as the correct launcher. Only then, true is returned.

Specified by:
registerLauncher in interface StatusRequesting
Returns:
True, if this is the coorect command launcher.

getUncached

protected Object getUncached()
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(stella.ErrorEvent) 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

Specified by:
getUncached in class AbstractCachedParameter

registerError

public void registerError(ErrorEvent ee)
Test, if the error event received is the correct error event via a call to isStatusRequested(stella.ErrorEvent). If so, the #getFor method is called and the cache is updated with the value returned.

Specified by:
registerError in interface ErrorDependingParameter

isStatusRequested

protected abstract boolean isStatusRequested(ErrorEvent ee)
Returns true, if the error event received is of the correct type for this parameter.