stella.rmi
Class GenericSimulator

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiListener
                      extended by stella.rmi.AbstractRmiCasterAndListener
                          extended by stella.rmi.ReceiverTorso
                              extended by stella.rmi.GenericSimulator
All Implemented Interfaces:
Cloneable, Remote, EventListener, Caster, ErrorSending, ErrorCaster, RmiAcknowledgeCaster, RmiCommandListener, RmiDoneCaster, RmiErrorCaster, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiEventListener, RmiListener, RmiPropertyBearing, StepInitializable
Direct Known Subclasses:
AdapterSimulator, AuxiliarySimulator, CalibrationSimulator, DomeSimulator, EnvironmentSimulator, SesSimulator, TelescopeSimulator, WifsipSimulator

public abstract class GenericSimulator
extends ReceiverTorso

A class used as a parental class for concrete device simulators. This class comprises only tasks that are common to all simulators, like a time accelaration. Details of the functionality provided:

Concrete simulators must deal with command processing. Therefore they need


Nested Class Summary
 
Nested classes/interfaces inherited from class stella.rmi.ReceiverTorso
ReceiverTorso.CommandHandler
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Map acknowledge
          A look-up table linking command types to acknowledge times.
static String ACKNOWLEDGEPREFIX
          The prefix for properties defining acknowledge times for commands.
private static double DEFACCELERATE
          The default time-acceleration factor.
private static long DEFERRORINTERVAL
          The default error-occurence intervall.
private static long DEFGENERICACKNOWLEDGE
          The default generic acknoledge time.
private static double DEFGENERICDEVIATE
          The default generic time deviation.
private static long DEFGENERICDONE
          The default generic done time.
private static long DEFSHUTDOWNDELAY
          The default shutdown delay time, 5 sec.
static String DEFUNIQUE
          The default name of the unique name identifier string.
private static String DEFURLRESOURCES
          For convenience, a default URL-resource.
private  Map deviate
          A look-up table linking command types to completion time deviations.
static String DEVIATEPREFIX
          The prefix for properties defining complete time deviations.
private  Map done
          A look-up table linking command types to 'real' completion times.
static String DONEPREFIX
          The prefix for properties defining complete times for commands.
private  List errors
          A list of Classes generated from KEY_ERRORCLASSES.
static String KEY_ACCELERATE
          The key to a time acceleration.
static String KEY_ERRORCLASSES
          A list of error-class names that may occur outside of a command cycle.
static String KEY_ERRORINTERVAL
          The generic error interval.
static String KEY_ERRORPROBABILITIES
          A list of probabilities for the errors in KEY_ERRORCLASSES.
static String KEY_GENERICACKNOWLEDGE
          The key to a default acknowledge time for unknown commands.
static String KEY_GENERICDEVIATE
          The key to a default completion time deviation.
static String KEY_GENERICDONE
          The key to a default completion time for unknown commands.
static String KEY_SET
          The key to the parameteres served by the simulator.
static String KEY_UNIQUE
          The unique name identifier string for acquire and guiding.
private  String lastdate
          For naming of acquire/guide frames.
private  Timer occur
          A timer scheduling out-of-command-cycle errors.
private  List probs
          A list of Doubles generated from KEY_ERRORPROBABILITIES.
protected static Random random
          A pseudo-random number generator.
private  ParameterClustering set
          Parameter cluster for all subclasses.
private static int SETPRIORITY
          The priority of the set exit.
private  int targetcount
          The target acquired at this date.
 
Fields inherited from class stella.rmi.ReceiverTorso
KEY_BIND, KEY_BINDNAME, KEY_COMMANDCASTER, KEY_ERRORCOOL
 
Fields inherited from class util.rmi.AbstractRmiListener
KEY_ALIVE, KEY_EXPORTPORT, KEY_INIT, KEY_LISTENERNAME, KEY_RETRY, KEY_RETRYSLEEP, KEY_SHUTDOWNDELAY
 
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 stella.rmi.RmiAcknowledgeCaster
NAMING_EXTENSION
 
Fields inherited from interface stella.rmi.RmiDoneCaster
NAMING_EXTENSION
 
Fields inherited from interface util.StepInitializable
KEY_INITDEPTH
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
protected GenericSimulator(Map prop)
          Constructs a new generic simulator.
 
Method Summary
protected static Map augmentProperties(Map target, String prefix, String[] keys, String[] values)
          Puts additional properties to the properties handed over.
 void exit()
          Exits the generic set.
protected  String formatWithGlobals(String fill, Map<String,Object> extern)
          Formatting a fits file name from a place-holder supplied.
 int getAcknowledgeNumber(CommandEvent ce)
          Returns the expected acknowledge number.
protected  long getCompletionTime(CommandEvent cmd, int acknr)
          Returns the acknowledge time for the argumental command, with given acknowledge-cycle number.
protected  long getNoisyTime(long base, double divert)
          Calculates a simulated command execution time.
protected  Parameter getParameter(String name)
          Returns the paramter named as stated or null.
 Parameter getParameterByKey(String key)
          Access to a parameter from its property key.
 Parameter getParameterByName(String name)
          Access to a paramter by its name.
protected  ParameterClustering getParameterCluster()
          Returns the generic parameter cluster.
 Object getParameterValueByKey(String key)
          Access to a parameter value by the parameter key.
 Object getParameterValueByName(String name)
          Access to a parameter value by the parameter name.
protected  long getSimulationTime(CommandEvent cmd, int acknr)
          Returns the completion time actually used by the simulator, e.g.
protected  Boolean getTrigger(String name)
          Returns the trigger named as stated or null.
 String getUnique()
          Returns the value of the unique parameter, or, if this is not accessible a 'home-made' version of it.
protected  Number getValue(String name)
          Returns the value named as stated or null.
private  void init1()
          Initialization, second step.
private  void init4()
          Creates the error scheduler.
 void initStep(int curstep)
          Initializes the generic simulator.
protected abstract  boolean isAllowed(ErrorEvent ee)
          Checks if the current state of the system allows the generic error handed over to be cast to an error handler.
protected  boolean processCommand(CommandEvent cmd, int acknr)
          Processes the given command.
protected  Object setParameter(String name, Object value)
          Sets a parameter of the generic set to the given value.
 Object setParameterValueByKey(String key, Object newval)
          Set a parameter value with the parameter key.
 Object setParameterValueByName(String name, Object newval)
          Set a parameter value with the parameter name.
protected  Boolean setTrigger(String name, Boolean value)
          Sets a trigger of the generic set to the given value.
protected  Number setValue(String name, Number value)
          Sets a value of the generic set to the given value.
protected  void shutdown()
          Quits the currently running java VM with a System.exit call.
protected  void sleepFor(long ms)
          Sleeps for the specified amount of time.
 String statusSimulator()
          A default status implementation.
 
Methods inherited from class stella.rmi.ReceiverTorso
addRmiAcknowledgeListener, addRmiDoneListener, bindDefault, containsRemoteProperty, deregisterAtCaster, equals, getLastError, getRemoteProperties, getRemoteProperty, hashCode, notifyAcknowledgeListener, notifyDoneListener, registerAtCaster, removeRmiAcknowledgeListener, removeRmiDoneListener, rescanned, rmiCommand, sendAllPrematureDone, sendPrematureDone, setRemoteProperty, toString, unbindDefault
 
Methods inherited from class stella.rmi.AbstractRmiCasterAndListener
addErrorListener, addRmiErrorListener, bindToRegistry, getBindName, isValid, notifyErrorListener, removeErrorListener, removeRmiErrorListener, sendError, sendError, sendError, sendStatus, sendStatus, sendStatus, unbindFromRegistry
 
Methods inherited from class util.rmi.AbstractRmiListener
allBound, blockBinding, blockBinding, disconnect, getIP, getListenerName, isConnected, listenerName, releaseBinding, releaseBinding, startBinding, startBinding
 
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, init, 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
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 
Methods inherited from interface stella.ErrorCaster
addErrorListener, removeErrorListener
 
Methods inherited from interface stella.rmi.RmiCommandListener
accepts
 
Methods inherited from interface util.rmi.RmiEventListener
getListenerName
 
Methods inherited from interface util.rmi.RmiListener
disconnect, isConnected
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
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.Initializable
init
 

Field Detail

KEY_UNIQUE

public static final String KEY_UNIQUE
The unique name identifier string for acquire and guiding.

See Also:
Constant Field Values

KEY_SET

public static final String KEY_SET
The key to the parameteres served by the simulator.

See Also:
Constant Field Values

KEY_ACCELERATE

public static final String KEY_ACCELERATE
The key to a time acceleration.

See Also:
Constant Field Values

KEY_GENERICACKNOWLEDGE

public static final String KEY_GENERICACKNOWLEDGE
The key to a default acknowledge time for unknown commands.

See Also:
Constant Field Values

KEY_GENERICDONE

public static final String KEY_GENERICDONE
The key to a default completion time for unknown commands.

See Also:
Constant Field Values

KEY_GENERICDEVIATE

public static final String KEY_GENERICDEVIATE
The key to a default completion time deviation.

See Also:
Constant Field Values

KEY_ERRORCLASSES

public static final String KEY_ERRORCLASSES
A list of error-class names that may occur outside of a command cycle.

See Also:
Constant Field Values

KEY_ERRORPROBABILITIES

public static final String KEY_ERRORPROBABILITIES
A list of probabilities for the errors in KEY_ERRORCLASSES.

See Also:
Constant Field Values

KEY_ERRORINTERVAL

public static final String KEY_ERRORINTERVAL
The generic error interval.

See Also:
Constant Field Values

ACKNOWLEDGEPREFIX

public static final String ACKNOWLEDGEPREFIX
The prefix for properties defining acknowledge times for commands.

See Also:
Constant Field Values

DONEPREFIX

public static final String DONEPREFIX
The prefix for properties defining complete times for commands.

See Also:
Constant Field Values

DEVIATEPREFIX

public static final String DEVIATEPREFIX
The prefix for properties defining complete time deviations.

See Also:
Constant Field Values

DEFUNIQUE

public static final String DEFUNIQUE
The default name of the unique name identifier string.

See Also:
Constant Field Values

DEFURLRESOURCES

private static final String DEFURLRESOURCES
For convenience, a default URL-resource.

See Also:
Constant Field Values

DEFACCELERATE

private static final double DEFACCELERATE
The default time-acceleration factor.

See Also:
Constant Field Values

DEFGENERICACKNOWLEDGE

private static final long DEFGENERICACKNOWLEDGE
The default generic acknoledge time.

See Also:
Constant Field Values

DEFGENERICDONE

private static final long DEFGENERICDONE
The default generic done time.

See Also:
Constant Field Values

DEFGENERICDEVIATE

private static final double DEFGENERICDEVIATE
The default generic time deviation.

See Also:
Constant Field Values

DEFERRORINTERVAL

private static final long DEFERRORINTERVAL
The default error-occurence intervall.

See Also:
Constant Field Values

DEFSHUTDOWNDELAY

private static final long DEFSHUTDOWNDELAY
The default shutdown delay time, 5 sec.

See Also:
Constant Field Values

set

private ParameterClustering set
Parameter cluster for all subclasses.


acknowledge

private Map acknowledge
A look-up table linking command types to acknowledge times.


done

private Map done
A look-up table linking command types to 'real' completion times.


deviate

private Map deviate
A look-up table linking command types to completion time deviations.


errors

private List errors
A list of Classes generated from KEY_ERRORCLASSES.


probs

private List probs
A list of Doubles generated from KEY_ERRORPROBABILITIES.


occur

private Timer occur
A timer scheduling out-of-command-cycle errors.


SETPRIORITY

private static final int SETPRIORITY
The priority of the set exit.

See Also:
Constant Field Values

random

protected static Random random
A pseudo-random number generator. Use also directly from sub-classes.


lastdate

private String lastdate
For naming of acquire/guide frames.


targetcount

private int targetcount
The target acquired at this date.

Constructor Detail

GenericSimulator

protected GenericSimulator(Map prop)
Constructs a new generic simulator. Defaults KEY_ACCELERATE and KEY_ERRORINTERVAL.

Method Detail

initStep

public void initStep(int curstep)
Initializes the generic simulator. In this case, the list of possible errors and their probabilities along with the timer is generated.

Specified by:
initStep in interface StepInitializable
Overrides:
initStep in class ReceiverTorso
Parameters:
curstep - The current initialization depth.

exit

public void exit()
Exits the generic set. If we have a random-error time task, this is canceld.

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

init1

private void init1()
Initialization, second step.


init4

private void init4()
Creates the error scheduler. This is done just after registering.


getParameterCluster

protected ParameterClustering getParameterCluster()
Returns the generic parameter cluster.


getParameter

protected Parameter getParameter(String name)
Returns the paramter named as stated or null.


getValue

protected Number getValue(String name)
Returns the value named as stated or null.


getTrigger

protected Boolean getTrigger(String name)
Returns the trigger named as stated or null.


setParameter

protected Object setParameter(String name,
                              Object value)
Sets a parameter of the generic set to the given value.


setValue

protected Number setValue(String name,
                          Number value)
Sets a value of the generic set to the given value.


setTrigger

protected Boolean setTrigger(String name,
                             Boolean value)
Sets a trigger of the generic set to the given value.


getParameterByName

public Parameter getParameterByName(String name)
Access to a paramter by its name.


getParameterByKey

public Parameter getParameterByKey(String key)
Access to a parameter from its property key.


getParameterValueByName

public Object getParameterValueByName(String name)
Access to a parameter value by the parameter name. Returns null if either the master has no set or the set does not know the parameter. Might still return null, if the queried value returns null.


getParameterValueByKey

public Object getParameterValueByKey(String key)
Access to a parameter value by the parameter key. Returns null if either the master has no set or the set does not know the parameter. Might still return null, if the queried value returns null.


setParameterValueByName

public Object setParameterValueByName(String name,
                                      Object newval)
Set a parameter value with the parameter name.


setParameterValueByKey

public Object setParameterValueByKey(String key,
                                     Object newval)
Set a parameter value with the parameter key.


augmentProperties

protected static Map augmentProperties(Map target,
                                       String prefix,
                                       String[] keys,
                                       String[] values)
Puts additional properties to the properties handed over. The first argument is a prefix that is prefixed to each key in the key list. The values are copied as-is. If a is already mapped in the properties it remains as-is. If the size of the keys and values does not match, no additional info is stored in the properties.

This method is used in conjuncture with construction of non-abstract daugther simulators.

Parameters:
target - The properties that need additional mappings.
prefix - A String to prefix before any key.
keys - The individual keys.
values - The mapping values to the keys
Returns:
A Map object that has additional properties.

processCommand

protected boolean processCommand(CommandEvent cmd,
                                 int acknr)
Processes the given command. If the command consists of multiple subtasks this method processes only the current subtask. The subtask can be derived from the acknowledge type handed over with the command. The type of the acknowledge is the type of the acknowledge that has been sent immediately before this method was called.

The method returns true if the (sub)task was executed without an error. If it returns false the appropriate error event must be ready for retrival using the ReceiverTorso.getLastError() method.

Specified by:
processCommand in class ReceiverTorso

shutdown

protected void shutdown()
Quits the currently running java VM with a System.exit call. Therefore, this method should only be invoked if no other master classes are executed in the same VM. It may nevertheless be called savely, if other classes execute on the same host (computer), but in different VMs.


statusSimulator

public String statusSimulator()
A default status implementation.


getAcknowledgeNumber

public int getAcknowledgeNumber(CommandEvent ce)
Returns the expected acknowledge number.

Specified by:
getAcknowledgeNumber in class ReceiverTorso

getCompletionTime

protected long getCompletionTime(CommandEvent cmd,
                                 int acknr)
Returns the acknowledge time for the argumental command, with given acknowledge-cycle number. Performs a lookup in the acknowledge map whether the command type can be found. If so, the matching list is queried for the cycle-number element, which is a Long carrying the required acknowledge time-out. If the command handed over is not found, a generic acknowledge time, KEY_GENERICACKNOWLEDGE is returned.

Specified by:
getCompletionTime in class ReceiverTorso
Parameters:
cmd - The command to process.
acknr - The number of the acknowledge that will be sent back.

getSimulationTime

protected long getSimulationTime(CommandEvent cmd,
                                 int acknr)
Returns the completion time actually used by the simulator, e.g. for delaying program execution. This method performs a look-up in the done time-table and distorts it with gaussian white noise, depending on the corresponding value found in the deviate look-up table.

This method does not delay program execution, daughter classes must call the sleepFor(long) method explicetly.


sleepFor

protected void sleepFor(long ms)
Sleeps for the specified amount of time. If an acceleration is given, the sleeping interval is shortened accordingly.

Parameters:
ms - The sleeping time in ms.

getNoisyTime

protected long getNoisyTime(long base,
                            double divert)
Calculates a simulated command execution time. Takes the basic sleep time and adds random (gaussian) noise to it, using the KEY_GENERICDEVIATE or the command-based DEVIATEPREFIX property.


formatWithGlobals

protected String formatWithGlobals(String fill,
                                   Map<String,Object> extern)
Formatting a fits file name from a place-holder supplied. The following rules apply: Example: science{Unique} returns the classic entry, as if no name would be given.

If unmatched parenthesis are encountered, the input string is returned.


getUnique

public String getUnique()
Returns the value of the unique parameter, or, if this is not accessible a 'home-made' version of it.


isAllowed

protected abstract boolean isAllowed(ErrorEvent ee)
Checks if the current state of the system allows the generic error handed over to be cast to an error handler. E.g. if you want to simulate weather changes, it is not useful to deploit two bad-weather event in a row.
Note that this check will affect the error-occurence probablity of a certain error if it does not allways return true.