stella.parameter
Class DeviceTrigger

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.parameter.AbstractParameter
                  extended by stella.parameter.AbstractTrigger
                      extended by stella.parameter.SimpleTrigger
                          extended by stella.parameter.DeviceTrigger
All Implemented Interfaces:
Cloneable, Caster, ErrorCaster, Parameter, Trigger, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, Reloadable, ResourceSupplying

public class DeviceTrigger
extends SimpleTrigger
implements ErrorCaster

Device trigger are used to mirror the status of an external command server. They are true if communication to the devices is possible. Device triggers are the only triggers that have a run method which periodically checks the connection. To allow starting of the trigger the command launcher must be registered to this trigger prior to launching the thread with registerCommandLaunching(stella.CommandLaunching).

Due to this special behaviour the construction of a device trigger with the AbstractParameter.createParameter(java.util.Map) method is not advised.


Nested Class Summary
private  class DeviceTrigger.PingTask
          The timer task that connects to the device.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static long DEFPING
          The default value of the is-alive intervall, in ms (10000).
private  CommandLaunching device
          The reference to the underlying command server.
private  List errlist
          The vector of error listeners.
static String KEY_PING
          The key linked to the is-alive intervall.
static String NAME_EXT
          The default extension to the trigger's server name.
private  TimerTask ping
          The timer task of the trigger that does the actual ping.
 
Fields inherited from class stella.parameter.SimpleTrigger
KEY_INITBOOLEAN
 
Fields inherited from class stella.parameter.AbstractParameter
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWN
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
DeviceTrigger(Map prop)
          Constructs a new sequence trigger with the given name and default value.
 
Method Summary
 void addErrorListener(ErrorListener ear)
          Registers an error event listener to this sequencer.
 void exit()
          Cancels the pinger task on exit.
 long getPingPeriod()
          Returns the onig period of this device trigger.
 TimerTask getTimerTask()
          Return the timer task associated with this device trigger.Note that starting the device trigger via an timer objects lies within the responsiblity of the calling object.
protected  void notifyErrorListener(ErrorEvent ee)
          Notifies all registered ErrorListeners.
 void registerCommandLaunching(CommandLaunching server)
          Registers a command launching instance to this device trigger.
 void removeErrorListener(ErrorListener ear)
          Deregisters an error event listener from this sequencer.
 Boolean setTrigger(Boolean val)
          Sets the value of this trigger.
 Boolean toggleTrigger()
          Toggling the trigger is not allowed, set is only through timer task.
 
Methods inherited from class stella.parameter.SimpleTrigger
getLastToggleTime, getTrigger, init, rescanned
 
Methods inherited from class stella.parameter.AbstractTrigger
get, getElapsedToggleTime, isTrue, set
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, register, setName, toString
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, 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.Reloadable
reload
 
Methods inherited from interface stella.Parameter
getFormatted, getName, getString
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

NAME_EXT

public static final String NAME_EXT
The default extension to the trigger's server name.

See Also:
Constant Field Values

KEY_PING

public static final String KEY_PING
The key linked to the is-alive intervall.

See Also:
Constant Field Values

DEFPING

private static final long DEFPING
The default value of the is-alive intervall, in ms (10000).

See Also:
Constant Field Values

device

private CommandLaunching device
The reference to the underlying command server.


errlist

private List errlist
The vector of error listeners.


ping

private TimerTask ping
The timer task of the trigger that does the actual ping.

Constructor Detail

DeviceTrigger

public DeviceTrigger(Map prop)
Constructs a new sequence trigger with the given name and default value. Use of this constructer guarantees that the KEY_PING points to a parsable long.

Method Detail

exit

public void exit()
Cancels the pinger task on exit.

Specified by:
exit in interface ExitCleaning
Overrides:
exit in class AbstractParameter

registerCommandLaunching

public void registerCommandLaunching(CommandLaunching server)
Registers a command launching instance to this device trigger. This method must always be called once prior to stating a thread from this trigger.

The default start value of the trigger is retrieved from the server. Note that this are special triggers that are always constructed in a trigger set, but should never be specialized in the trigger set trigger's list!


getPingPeriod

public long getPingPeriod()
Returns the onig period of this device trigger. This method should be used in conjuncture with the getTimerTask() method. Note that starting the device trigger via an timer objects lies within the responsiblity of the calling object.


getTimerTask

public TimerTask getTimerTask()
Return the timer task associated with this device trigger.Note that starting the device trigger via an timer objects lies within the responsiblity of the calling object.


setTrigger

public Boolean setTrigger(Boolean val)
Sets the value of this trigger.

Specified by:
setTrigger in interface Trigger
Overrides:
setTrigger in class SimpleTrigger
Returns:
The old value of the trigger.

toggleTrigger

public Boolean toggleTrigger()
Toggling the trigger is not allowed, set is only through timer task.

Specified by:
toggleTrigger in interface Trigger
Overrides:
toggleTrigger in class AbstractTrigger
Returns:
The old value of the trigger.

addErrorListener

public void addErrorListener(ErrorListener ear)
Registers an error event listener to this sequencer. Normally only a single error listener will register to a sequencer.
Only local error listeners are allowed.

Specified by:
addErrorListener in interface ErrorCaster

removeErrorListener

public void removeErrorListener(ErrorListener ear)
Deregisters an error event listener from this sequencer. Normally only a single error listener will be registered to this sequencer.
Only local error listeners are allowed.

Specified by:
removeErrorListener in interface ErrorCaster

notifyErrorListener

protected void notifyErrorListener(ErrorEvent ee)
Notifies all registered ErrorListeners. This method parses through the Vector of ErrorListeners and passes the argument to their errorOccured method. Registered listeners are local.

An error event signaling a lost connection is only generated if the connection state changes from connected to not connected, not if a server is simply not connected.

Parameters:
ee - The ErrorEvent to pass to the Listeners.