stella.environment
Class EnvironmentSimulator

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
                                  extended by stella.environment.EnvironmentSimulator
All Implemented Interfaces:
Cloneable, Remote, EventListener, Caster, ErrorSending, ErrorCaster, RmiAcknowledgeCaster, RmiCommandListener, RmiDoneCaster, RmiErrorCaster, WeatherListener, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiEventListener, RmiListener, RmiPropertyBearing, StepInitializable

public class EnvironmentSimulator
extends GenericSimulator
implements WeatherListener

A class to simulate the environment. It extends a generic simulator and has the following properties:


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 static String[] ACKTIMES
          The acknowledge times for the known commands.
private static String[] COMMANDS
          The known command types, used for acknowledges.
private static double DEFCLOSEFAIL
          The default closinging failure probability .
private static String DEFERRORCLASSES
          The default error list.
private static String DEFERRORPROBABILITIES
          The default error probabilities.
private static String DEFFAKE
          The default properties of the fake weather station.
private static String DEFISOPEN
          The default name of the roof-is-open trigger.
private static double DEFOPENFAIL
          The default opening failure probability .
private static double DEFPOWERFAIL
          The default power-switching failure probability .
private static String DEFSET
          The default properties of the parameter set of the simulator.
private static String[] DIVERT
          The actual divert factors for the commands.
private static String[] DONETIMES
          The 'true' command execution times.
private  WeatherSurveying fake
          The weather station.
static String KEY_CLOSEFAIL
          The key to the sleep-time for an open-roof command.
static String KEY_FAKE
          The key to the properties of the fake weather station.
static String KEY_ISOPEN
          The key to the name of the is-open trigger.
static String KEY_OPENFAIL
          The key to the sleep-time for an open-roof command.
static String KEY_POWERFAIL
          The key to the probability of power-switch failure.
private  ErrorEvent lasterror
          The error event if command execution fails.
 
Fields inherited from class stella.rmi.GenericSimulator
ACKNOWLEDGEPREFIX, DEFUNIQUE, DEVIATEPREFIX, DONEPREFIX, KEY_ACCELERATE, KEY_ERRORCLASSES, KEY_ERRORINTERVAL, KEY_ERRORPROBABILITIES, KEY_GENERICACKNOWLEDGE, KEY_GENERICDEVIATE, KEY_GENERICDONE, KEY_SET, KEY_UNIQUE, random
 
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
EnvironmentSimulator(Map prop)
          Constructs a new environment simulator.
 
Method Summary
 boolean accepts(CommandEvent ce)
          Returns true if this receiver accepts commands of the type handed over as an argument.
protected  ErrorEvent getLastError()
          Returns the last error that occured during command processing.
 void init2()
          Initializes the weather station.
 void initStep(int curstep)
          Initializes the weather station.
protected  boolean isAllowed(ErrorEvent ee)
          Checks if the error handed over is currently allowed to be thrown.
static void main(String[] arg)
          Constructs a new environment simulator.
private static Map myAugment(Map def)
          Augments the properties three times, for acknowledge and done times and for divert factors.
protected  boolean processCommand(CommandEvent ce, int acknr)
          Simulated command processing.
 void weatherChanged(WeatherEvent we)
          The weather event receiving edge of the environment master.
 
Methods inherited from class stella.rmi.GenericSimulator
augmentProperties, exit, formatWithGlobals, getAcknowledgeNumber, getCompletionTime, getNoisyTime, getParameter, getParameterByKey, getParameterByName, getParameterCluster, getParameterValueByKey, getParameterValueByName, getSimulationTime, getTrigger, getUnique, getValue, setParameter, setParameterValueByKey, setParameterValueByName, setTrigger, setValue, shutdown, sleepFor, statusSimulator
 
Methods inherited from class stella.rmi.ReceiverTorso
addRmiAcknowledgeListener, addRmiDoneListener, bindDefault, containsRemoteProperty, deregisterAtCaster, equals, 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 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_OPENFAIL

public static final String KEY_OPENFAIL
The key to the sleep-time for an open-roof command.

See Also:
Constant Field Values

KEY_CLOSEFAIL

public static final String KEY_CLOSEFAIL
The key to the sleep-time for an open-roof command.

See Also:
Constant Field Values

KEY_POWERFAIL

public static final String KEY_POWERFAIL
The key to the probability of power-switch failure.

See Also:
Constant Field Values

KEY_FAKE

public static final String KEY_FAKE
The key to the properties of the fake weather station.

See Also:
Constant Field Values

KEY_ISOPEN

public static final String KEY_ISOPEN
The key to the name of the is-open trigger.

See Also:
Constant Field Values

DEFOPENFAIL

private static final double DEFOPENFAIL
The default opening failure probability .

See Also:
Constant Field Values

DEFCLOSEFAIL

private static final double DEFCLOSEFAIL
The default closinging failure probability .

See Also:
Constant Field Values

DEFPOWERFAIL

private static final double DEFPOWERFAIL
The default power-switching failure probability .

See Also:
Constant Field Values

DEFFAKE

private static final String DEFFAKE
The default properties of the fake weather station.

See Also:
Constant Field Values

DEFSET

private static final String DEFSET
The default properties of the parameter set of the simulator.

See Also:
Constant Field Values

DEFISOPEN

private static final String DEFISOPEN
The default name of the roof-is-open trigger.

See Also:
Constant Field Values

DEFERRORCLASSES

private static final String DEFERRORCLASSES
The default error list.

See Also:
Constant Field Values

DEFERRORPROBABILITIES

private static final String DEFERRORPROBABILITIES
The default error probabilities.

See Also:
Constant Field Values

COMMANDS

private static final String[] COMMANDS
The known command types, used for acknowledges.


ACKTIMES

private static final String[] ACKTIMES
The acknowledge times for the known commands.


DONETIMES

private static final String[] DONETIMES
The 'true' command execution times.


DIVERT

private static final String[] DIVERT
The actual divert factors for the commands.


fake

private WeatherSurveying fake
The weather station. Use fake data.


lasterror

private ErrorEvent lasterror
The error event if command execution fails.

Constructor Detail

EnvironmentSimulator

public EnvironmentSimulator(Map prop)
                     throws RemoteException
Constructs a new environment simulator.

Throws:
RemoteException
Method Detail

myAugment

private static Map myAugment(Map def)
Augments the properties three times, for acknowledge and done times and for divert factors. Uses an own method to increase readability.


initStep

public void initStep(int curstep)
Initializes the weather station. The weather station should use pre-recorded data and should consist of FakeSensor sensors only.

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

init2

public void init2()
Initializes the weather station. The weather station should use pre-recorded data and should consist of FakeSensor sensors only.


accepts

public boolean accepts(CommandEvent ce)
                throws RemoteException
Returns true if this receiver accepts commands of the type handed over as an argument. An environment master accepts all sort of EnvironmentCommands.

Specified by:
accepts in interface RmiCommandListener
Throws:
RemoteException

isAllowed

protected boolean isAllowed(ErrorEvent ee)
Checks if the error handed over is currently allowed to be thrown. A NoRoof error is always allowed.

Specified by:
isAllowed in class GenericSimulator

getLastError

protected ErrorEvent getLastError()
Returns the last error that occured during command processing.

Specified by:
getLastError in class ReceiverTorso

weatherChanged

public void weatherChanged(WeatherEvent we)
The weather event receiving edge of the environment master. This method is only reached when direct roof control is enabled with a call to the #direct method. Here, the weather event is checked for bad weather. If so, the roof operator gets directly a signal to close the roof without waiting for a close-roof from the default command caster. Note that closing of the roof is only allowed in robotic mode.
Implementation note: If the roof is closed, a new thread for this task is generated to allow fast-return of the listener method.

Specified by:
weatherChanged in interface WeatherListener

processCommand

protected boolean processCommand(CommandEvent ce,
                                 int acknr)
Simulated command processing. This does the following:

Overrides:
processCommand in class GenericSimulator

main

public static void main(String[] arg)
                 throws RemoteException
Constructs a new environment simulator. The single argument supplied are the simulator properties.

Throws:
RemoteException