Class SmiTest

java.lang.Object
  |
  +--SmiTest
All Implemented Interfaces:
MobileObject, java.io.Serializable

public class SmiTest
extends java.lang.Object
implements MobileObject

MobiliTools $Name: $, $Id: SmiTest.java,v 1.1.1.1 2003/03/28 14:47:58 dillense Exp $

This example class shows MobileObject lifecycle through a console-based user interaction, as well as resource loading. The easiest way to use this example is to use GUI-enabled agencies.
Note that this agent has no autonomous activity.

See Also:
Serialized Form

Field Summary
(package private)  Agency my_agency
          reference to current host agency, set after each move - must be transient because non-serializable
(package private)  java.lang.String my_name
          display-friendly name, set once for all at creation
(package private)  boolean running
          true if the agent is currently active, false if it is suspended
 
Constructor Summary
SmiTest()
          Default constructor is invoked when no argument is provided for agent creation.
SmiTest(java.lang.Object arg)
          (Generic) Example of specific constructor.
 
Method Summary
 void afterBirth(AgentSystem agency, AgentInfo entry, java.lang.Object argument)
          Displays a message and plays a sound on agent creation.
 void afterMove(AgentSystem agency, Location location, java.lang.String place)
          Plays a sound and asks installation confirmation after deserialization in the target agency.
 void afterMoveFailed(Location location, java.lang.String place, int reason, java.lang.String message)
          Plays a sound and displays a message in the source agency after the agent has been serialized but its installation in the target agency has failed (probably rejected by the agent itself)
 void beforeDeath()
          Displays a message on termination
 void beforeMove(Location location, java.lang.String place)
          Asks confirmation before moving.
 void beforeResume()
          Displays an acknowledgement message on agent activity resumption if and only if it was suspended, otherwise the resume-caller gets an exception.
 void beforeShutdown()
          Displays a message on host agency shutdown
 void beforeSuspend()
          Displays an acknowledgement message on agent activity suspension if and only if it was active, otherwise the suspend-caller gets an exception.
(package private)  boolean confirm(java.lang.String message, boolean defaultYes)
          Displays a message and reads a confirmation ('y' or 'n' whatever upper or lower case) in the attached console/terminal
(package private)  void playSound(java.lang.String resourcename)
          Loads a sound designated by the provided resource name using the agent's class classloader and plays it.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

my_name

java.lang.String my_name
display-friendly name, set once for all at creation

running

boolean running
true if the agent is currently active, false if it is suspended

my_agency

transient Agency my_agency
reference to current host agency, set after each move - must be transient because non-serializable
Constructor Detail

SmiTest

public SmiTest()
Default constructor is invoked when no argument is provided for agent creation.

SmiTest

public SmiTest(java.lang.Object arg)
(Generic) Example of specific constructor. Displays the argument provided for agent creation.
Method Detail

afterBirth

public void afterBirth(AgentSystem agency,
                       AgentInfo entry,
                       java.lang.Object argument)
                throws BadOperation
Displays a message and plays a sound on agent creation. Aks confirmation of creation. Answer 'y' or 'n' to respectively accept or deny agent creation. If creation is denied, the creation-caller gets an exception.
Specified by:
afterBirth in interface MobileObject

beforeMove

public void beforeMove(Location location,
                       java.lang.String place)
                throws BadOperation
Asks confirmation before moving. Answer 'y' or 'n' in the console to respectively confirm or abort the move. In case you abort, an exception is raised, the agent is not serialized, and the move-caller gets an exception.
Specified by:
beforeMove in interface MobileObject

afterMove

public void afterMove(AgentSystem agency,
                      Location location,
                      java.lang.String place)
               throws BadOperation
Plays a sound and asks installation confirmation after deserialization in the target agency. Answer 'y' or 'n' to respectively accept or deny installation. Denying will drop the agent copy in the target agency and invoke afterMoveFailed() on the agent in source agency.
Specified by:
afterMove in interface MobileObject

afterMoveFailed

public void afterMoveFailed(Location location,
                            java.lang.String place,
                            int reason,
                            java.lang.String message)
Plays a sound and displays a message in the source agency after the agent has been serialized but its installation in the target agency has failed (probably rejected by the agent itself)
Specified by:
afterMoveFailed in interface MobileObject

beforeShutdown

public void beforeShutdown()
Displays a message on host agency shutdown
Specified by:
beforeShutdown in interface MobileObject

beforeDeath

public void beforeDeath()
Displays a message on termination
Specified by:
beforeDeath in interface MobileObject

beforeResume

public void beforeResume()
                  throws BadOperation
Displays an acknowledgement message on agent activity resumption if and only if it was suspended, otherwise the resume-caller gets an exception.
Specified by:
beforeResume in interface MobileObject

beforeSuspend

public void beforeSuspend()
                   throws BadOperation
Displays an acknowledgement message on agent activity suspension if and only if it was active, otherwise the suspend-caller gets an exception.
Specified by:
beforeSuspend in interface MobileObject

confirm

boolean confirm(java.lang.String message,
                boolean defaultYes)
Displays a message and reads a confirmation ('y' or 'n' whatever upper or lower case) in the attached console/terminal
Parameters:
message - confirmation question to be displayed
defaultYes - default answer (i.e. when neither 'y' nor 'n' is entered)
Returns:
true if the user answered 'y', false if the user answered 'n', defaultYes otherwise.

playSound

void playSound(java.lang.String resourcename)
Loads a sound designated by the provided resource name using the agent's class classloader and plays it.
Parameters:
resourcename - the name of the resource (should be an audio file)