stella.jview
Class DeviceSimulator

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.jview.DeviceSimulator
All Implemented Interfaces:
Cloneable, Remote, EventListener, Displayable, Caster, ErrorSending, ErrorCaster, RmiAcknowledgeCaster, RmiCommandListener, RmiDoneCaster, RmiErrorCaster, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiEventListener, RmiListener, RmiPropertyBearing, StepInitializable

public final class DeviceSimulator
extends ReceiverTorso
implements Displayable

The receiver end to a caster. This method is a generic device tester. It acts as a remote device. The user can choose between different acknoledge and done messages generated and sent back to the caster. Various error messages can be produced at any time.

A screenshot of an active device simulator looks like this:

DeviceSimulator

The receiver name links to the binding name of this receiver. If the receiver successfully bound its RmiAcknowledgeCaster, RmiDoneCaster, and RmiErrorCaster abilities to the registry, the appropriate bind fields get true. If the receiver is listening to a command caster the Command listening field gets true.
The number of acknowledge messages returned once the simulator receives a command can be alteres either using the JPlusMinusBox or by directly entering the acknowledge number in the appropriate field. Note that only the initial acknowledge message will be sent back automatically, after a delay time specified in the delay for 1st ack. field. The completion time this initial acknowledge message carries is specified in the next line. Any further acknowledge messages are only sent if the user presses the ACK button. It carries the completion time specified in the field right to the ACK button.
A done message is generated and sent back if the user hits the DONE button. The state of the successful flag of the done message can be specified.
To simulate errors occuring, the user can press the ERROR button at any time. The type of the error can be selected from the list to the right side of the button.
Any command message received shows up in the status field, to the right of the exit button, JExitButton. Commands are imprinted in brown while acknowledge messages show up in green, done messages are blue. Errors generated show up in red. Any other status information is printed in black.


Nested Class Summary
protected  class DeviceSimulator.SimulationHandler
          A thread that takes over the handling of the incomming command in the device simulator.
 
Nested classes/interfaces inherited from class stella.rmi.ReceiverTorso
ReceiverTorso.CommandHandler
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
static String[] ACCEPTS
          The keywords understood by the accept-key.
private  JTextField ackcomplete
          The completion time for the interactively sent acknowledge event.
private  JButton acknowledge
          Button for interactively sending back an acknowledge event.
private  JIncrementField acknr
          Input field for number of acknowledges.
private  JLabel bindack
          Boolean labels describing the status of device binding.
private  JLabel binddone
          Boolean labels describing the status of device binding.
private  JLabel binderror
          Boolean labels describing the status of device binding.
private  JTextField complete
          Input field for completion time of first acknowledge.
private static String DEFACCEPT
          The default accept key.
private static int DEFCOMPLETE
          The default completion time of the acknowledge event.
private static int DEFDELAY
          The default delay between command receipt and acknowledge.
private  JTextField delay
          Input field for delay between command and first acknowledge.
private  JButton done
          Button for interactive sending of done event.
private  JButton error
          Button to send back an error message.
private  JComboBox errorlist
          A list of instantiable error events.
static String KEY_ACCEPT
          The key to the commands accepted.
static String KEY_COMPLETE
          The key to the completion time of the first acknowledge event.
static String KEY_DELAY
          The key to the default delay between command receipt and acknowledge.
static String KEY_ERROR
          The key to the comma-separated list of instantiable errors.
static String KEY_NAME
          The key to the device name.
private  JLabel listen
          Boolean labels describing the status of device binding.
private  JRadioButton no
          The completion flag of the done event sent back.
private  DeviceSimulator.SimulationHandler receive
          The receiver thread.
private  JStatusExit status
          The status panel to display commands, erros, and replies.
private  JRadioButton yes
          The completion flag of the done event sent back.
 
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
DeviceSimulator(Map prop)
          Constructs a new test receiver.
 
Method Summary
 boolean accepts(CommandEvent ce)
          A device simulator can accept all types of commands.
protected  boolean deregisterAtCaster(RmiCaster caster, Class service)
          Links into the parent's ReceiverTorso.registerAtCaster(util.rmi.RmiCaster, java.lang.Class) method.
private  Component doLayout()
          Returns the panel after all components have been constructed.
 void exit()
          Does necessary clearing jobs.
protected  int getAcknowledgeNumber(CommandEvent cmd)
          Returns the type of the first acknowledge event.
protected  long getCompletionTime(CommandEvent ignore, int dummytype)
          Return the value of the completion-time text-field, multiplied with 1000.
 Icon getIcon()
          The default implementation returns null here.
protected  ErrorEvent getLastError()
          Retunrns null.
 Component getRepresentation()
          Creates all components of this device simulator, groups them into a panel which is then returned.
private  void init5()
          Manually initiates the rmi-caster and listener bindings.
 void initStep(int curstep)
          Manually initiates the rmi-caster and listener bindings.
static void main(String[] arg)
          For testing.
protected  boolean processCommand(CommandEvent ignore, int dummytype)
          Processes the given command.
protected  boolean registerAtCaster(RmiCaster caster, Class service)
          Links into the parent's ReceiverTorso.registerAtCaster(util.rmi.RmiCaster, java.lang.Class) method.
 void rmiCommand(CommandEvent cmd)
          The command receiving method.
 
Methods inherited from class stella.rmi.ReceiverTorso
addRmiAcknowledgeListener, addRmiDoneListener, bindDefault, containsRemoteProperty, equals, getRemoteProperties, getRemoteProperty, hashCode, notifyAcknowledgeListener, notifyDoneListener, removeRmiAcknowledgeListener, removeRmiDoneListener, rescanned, 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_DELAY

public static final String KEY_DELAY
The key to the default delay between command receipt and acknowledge.

See Also:
Constant Field Values

KEY_COMPLETE

public static final String KEY_COMPLETE
The key to the completion time of the first acknowledge event.

See Also:
Constant Field Values

KEY_ERROR

public static final String KEY_ERROR
The key to the comma-separated list of instantiable errors.

See Also:
Constant Field Values

KEY_NAME

public static final String KEY_NAME
The key to the device name. Defaults to binding name

See Also:
Constant Field Values

KEY_ACCEPT

public static final String KEY_ACCEPT
The key to the commands accepted.

See Also:
Constant Field Values

ACCEPTS

public static final String[] ACCEPTS
The keywords understood by the accept-key.


DEFACCEPT

private static final String DEFACCEPT
The default accept key.

See Also:
Constant Field Values

DEFDELAY

private static final int DEFDELAY
The default delay between command receipt and acknowledge.

See Also:
Constant Field Values

DEFCOMPLETE

private static final int DEFCOMPLETE
The default completion time of the acknowledge event.

See Also:
Constant Field Values

acknr

private JIncrementField acknr
Input field for number of acknowledges.


delay

private JTextField delay
Input field for delay between command and first acknowledge.


complete

private JTextField complete
Input field for completion time of first acknowledge.


done

private JButton done
Button for interactive sending of done event.


yes

private JRadioButton yes
The completion flag of the done event sent back.


no

private JRadioButton no
The completion flag of the done event sent back.


acknowledge

private JButton acknowledge
Button for interactively sending back an acknowledge event.


ackcomplete

private JTextField ackcomplete
The completion time for the interactively sent acknowledge event.


error

private JButton error
Button to send back an error message.


errorlist

private JComboBox errorlist
A list of instantiable error events.


bindack

private JLabel bindack
Boolean labels describing the status of device binding.


binddone

private JLabel binddone
Boolean labels describing the status of device binding.


binderror

private JLabel binderror
Boolean labels describing the status of device binding.


listen

private JLabel listen
Boolean labels describing the status of device binding.


status

private JStatusExit status
The status panel to display commands, erros, and replies.


receive

private DeviceSimulator.SimulationHandler receive
The receiver thread.

Constructor Detail

DeviceSimulator

public DeviceSimulator(Map prop)
                throws RemoteException
Constructs a new test receiver. Registers System.err as an error listener. Exports itself in the unicast remote object server.

Throws:
RemoteException
Method Detail

initStep

public void initStep(int curstep)
Manually initiates the rmi-caster and listener bindings. This method can be called savely after the simulator's GUI is displayed.

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

init5

private void init5()
Manually initiates the rmi-caster and listener bindings. This method can be called savely after the simulator's GUI is displayed.


getIcon

public Icon getIcon()
The default implementation returns null here.

Specified by:
getIcon in interface Displayable

getRepresentation

public Component getRepresentation()
Creates all components of this device simulator, groups them into a panel which is then returned.

Specified by:
getRepresentation in interface Displayable

doLayout

private Component doLayout()
Returns the panel after all components have been constructed. Should increase readability of program.


exit

public void exit()
Does necessary clearing jobs.

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

rmiCommand

public void rmiCommand(CommandEvent cmd)
                throws RemoteException
The command receiving method. The command received is displayed at the status line and a new command simulator thread is started. The first acknowledge event is sent back immediately using the appropriate settings of the fields in the simulator's main panel. Any further acknowledge or done message is generated only when the appropriate button is pressed. The command simulator acts as an action event listener on the various buttons used to generate acknowledge, done, and error events.

Specified by:
rmiCommand in interface RmiCommandListener
Overrides:
rmiCommand in class ReceiverTorso
Parameters:
cmd - The command to process.
Throws:
RemoteException

accepts

public boolean accepts(CommandEvent ce)
                throws RemoteException
A device simulator can accept all types of commands. To narrow down the type of commands it should handle, you can use the KEY_ACCEPT key pointing to one of the ACCEPTS codes. Each of them has its obvious meaning.

Specified by:
accepts in interface RmiCommandListener
Throws:
RemoteException

registerAtCaster

protected boolean registerAtCaster(RmiCaster caster,
                                   Class service)
Links into the parent's ReceiverTorso.registerAtCaster(util.rmi.RmiCaster, java.lang.Class) method. If it returns true the listen label is set to true.

Overrides:
registerAtCaster in class ReceiverTorso
Returns:
True, if this listener can register at the specified caster

deregisterAtCaster

protected boolean deregisterAtCaster(RmiCaster caster,
                                     Class service)
Links into the parent's ReceiverTorso.registerAtCaster(util.rmi.RmiCaster, java.lang.Class) method. If it returns true the listen label is set to true.

Overrides:
deregisterAtCaster in class ReceiverTorso
Returns:
True, if this listener can deregister at the specified caster

getLastError

protected ErrorEvent getLastError()
Retunrns null.

Specified by:
getLastError in class ReceiverTorso

getAcknowledgeNumber

protected int getAcknowledgeNumber(CommandEvent cmd)
Returns the type of the first acknowledge event. Reads the field with the acknowledge number.

Specified by:
getAcknowledgeNumber in class ReceiverTorso

getCompletionTime

protected long getCompletionTime(CommandEvent ignore,
                                 int dummytype)
Return the value of the completion-time text-field, multiplied with 1000.

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

processCommand

protected boolean processCommand(CommandEvent ignore,
                                 int dummytype)
Processes the given command. Not needed in the simulator

Specified by:
processCommand in class ReceiverTorso

main

public static void main(String[] arg)
                 throws RemoteException
For testing. Registers to the command caster given in the first command line argument.

Throws:
RemoteException