metaglue
Class AgentAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
Direct Known Subclasses:
AgentTesterAgent, AppGrammarAgent, AttributeManagerAgent, EmptyResourceManagerAgent, GoodAgent, GrammarCenterAgent, GroupAgent, HappyAgent, LogMonitorAgent, LoudMouthAgent, LoudMouthTestAgent, MetaglueAgent, MSWindowsDisplayAgent, NotifierAgent, RandomThoughtAgent, SerialAgent, SoundManagerAgent, SoundTestAgent, SpeechOutAgent, TestGrammarAgent, TypeWriterAgent, VerboseAgent, VoiceAgent

public class AgentAgent
extends UnicastRemoteObject
implements Agent, MetagluePrimitives

Superclass of all Metaglue agents. Provides the Metaglue primitives: reliesOn, tiedTo, as well as a host of other useful items.

See Also:
Serialized Form

Inner Class Summary
 class AgentAgent.Attribute
          Attribute class description
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
AgentAgent()
           
AgentAgent(AgentID agentID)
           
 
Method Summary
 void addMonitor(Spy monitor)
          Add a log monitor that gets all the screen output.
 boolean alive()
           
 Object defrost(String var)
          Defrosts an object to get its value from the icebox.
 Hashtable defrostAll()
          Gets the variables and values stored in the icebox.
 boolean defrostBoolean(String var)
          Defrosts a boolean value from the icebox.
 int defrostInt(String var)
          Defrosts a boolean value from the icebox.
 String defrostString(String var)
          Defrosts a string from the icebox.
protected  String fixAttribute(AgentID aid, String attributeName)
           
protected  String fixAttribute(AgentID aid, String attributeName, String specialMessage)
          Allows you to fix an existing attribute (useful if you try to cast attribute to something and it fails)
 void freeze(String var, boolean b)
          `Freeze' a boolean value into the icebox.
 void freeze(String var, int i)
          `Freeze' an integer value into the icebox.
 void freeze(String var, Serializable o)
          `Freeze' an object into the icebox.
 void freezeAll()
          A simple routine to freeze all the state of an object.
 void freezeVar(String var, Object obj)
          `Freeze' an object into the icebox.
 AgentID getAgentID()
           
 String getAttribute(String attributeName)
          Get attribute value for name.
 Catalog getCatalog()
           
 CatalogID getCatalogID()
           
 Object getDesignation()
           
 Set getFrozenVariables()
          Gets the set of variables stored in the icebox.
 int getLogLevel(int level)
           
 MetaglueAgent getMetaglueAgent()
          Gets the Metaglue Agent that loaded this agent
 AgentID getMetaglueAgentID()
          Gets the Metaglue Agent ID that loaded this agent
 String getOccupation()
           
 Properties getProperties()
           
 String getSociety()
           
 void log(int level, String info)
          Send a log message to the logging stream.
 void log(Object obj)
          Send a log message to the logging stream.
 void log(String level, String info)
          Send a log message to the logging stream.
 Metaglue obtainMetaglueAgent(AgentID mid)
           
 Metaglue obtainMetaglueAgent(InetAddress host)
           
 Metaglue obtainMetaglueAgentByName(String ma, boolean retry_if_fail)
           
 Agent reliesOn(AgentID agentID)
          Major reliesOn call.
 Agent reliesOn(String occupation)
          Ensures that the specified agent is running (starts if necessary).
 Agent reliesOn(String occupation, Object designation)
          Ensures that the specified agent is running (starts if necessary).
 Agent reliesOnSynch(AgentID agentID)
          Synchronously rely on agentID.
 boolean removeFrozen(String var)
          Remove a frozen object from the icebox.
 void replaceExceptionHandler(AgentExceptionHandler r)
          Stub routine for AEH exception handling.
protected  void setFreezeName(String name)
           
 void setLogLevel(int level)
           
 void setLogName(String n)
          Sets a name for this agent that can be used while logging.
 void shutdown()
          Changes the agent so that it cannot be found through the catalog or accept RMI calls.
 void startAgent(AgentID agentID)
           
 void startAgentOn(AgentID theAgentID, Metaglue metaglue, boolean agent_previously_started, Object[] parameters)
          Start given agent on given metaglue agent.
 void startAgentOn(AgentID theAgentID, String host)
          Try to start agent on metaglue agent with given host for christian name, or, failing that, that host for a computer.
 void startup()
           
 int status(AgentID agentID)
          Determines the status of the described agent.
 void tiedTo(AgentID agentID)
          Ensures that agent is running on the same MVM as a given agent Must be asserted in agent contructor.
 void tiedTo(AgentID theAgentID, Object[] parameters)
          Ensures that agent is running on the same MVM as a given agent.
 void tiedTo(InetAddress host, Object[] parameters)
          Ensures that agent is running on host (moving it there if necessary with given parameters).
 void tiedTo(String host)
           
protected  String tieToDesignation()
          If the designation string is a name of a known host, this method will tie this agent to the host named in designation.
 InetAddress whereAreYou()
          Returns the InetAddress of the machine where the agent is running
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AgentAgent

public AgentAgent()
           throws RemoteException

AgentAgent

public AgentAgent(AgentID agentID)
           throws RemoteException
Method Detail

replaceExceptionHandler

public void replaceExceptionHandler(AgentExceptionHandler r)
Stub routine for AEH exception handling. This is a dummy routine, the wrapper will override this method and implement the correct behavior. DO NOT PUT CODE IN HERE. IT WILL NOT RUN
Specified by:
replaceExceptionHandler in interface MetagluePrimitives

getMetaglueAgent

public MetaglueAgent getMetaglueAgent()
Gets the Metaglue Agent that loaded this agent
Returns:
the Metaglue Agent that loaded this agent

getMetaglueAgentID

public AgentID getMetaglueAgentID()
                           throws RemoteException
Gets the Metaglue Agent ID that loaded this agent
Specified by:
getMetaglueAgentID in interface Agent
Returns:
the Metaglue AgentID that loaded this agent

reliesOnSynch

public Agent reliesOnSynch(AgentID agentID)
Synchronously rely on agentID. This is similar to reliesOn, but will not return an EHA placeholder for the agent.
Specified by:
reliesOnSynch in interface MetagluePrimitives
See Also:
reliesOn(String)

startAgent

public void startAgent(AgentID agentID)

status

public int status(AgentID agentID)
Determines the status of the described agent. This method does not cause the agent to be started if it's not running. Returns one of the following constants:
Parameters:
agentID - AgentID of the target agent.
Returns:
Integer describing whether agent is up.
See Also:
reliesOn(AgentID)

reliesOn

public Agent reliesOn(String occupation)
Ensures that the specified agent is running (starts if necessary).
Parameters:
agentID - agentID of agent to start
Returns:
stub to agent
Throws:
SpreadError - some reliance could not spread
AgentNotDefinedError - some part of the agent was not completely defined
NativityError - an error occurred during the construction of agent.
InvalidArgumentException - (runtime) agentID is null

reliesOn

public Agent reliesOn(String occupation,
                      Object designation)
Ensures that the specified agent is running (starts if necessary).
See Also:
reliesOn(String)

reliesOn

public Agent reliesOn(AgentID agentID)
Major reliesOn call. Ensures that the specified agent is running (starts if necessary).
See Also:
reliesOn(String)

tiedTo

public void tiedTo(AgentID agentID)
            throws RemoteException
Ensures that agent is running on the same MVM as a given agent Must be asserted in agent contructor. Any state the agent has established up to the tiedTo assertion is lost.
Parameters:
AgentID - agentID to tie agent to ("speech.AppGrammar");
Throws:
SpreadError - some reliance could not spread

tiedTo

public void tiedTo(AgentID theAgentID,
                   Object[] parameters)
            throws RemoteException
Ensures that agent is running on the same MVM as a given agent. If it is not, i1t starts agent on desired machine, and then throws TiedToDeath exception, which will be swallowed silently. It does the following: find the named agent, find its MetaglueAgent, if that's my metaglue agent, done. otherwise, ask that metaglue agent to start me.
Parameters:
AgentID - agentID to tie agent to ("speech.AppGrammar");
parameters - list of paramaters given when starting up agent.
See Also:
tiedTo(AgentID)

tiedTo

public void tiedTo(String host)
            throws RemoteException

tiedTo

public void tiedTo(InetAddress host,
                   Object[] parameters)
            throws RemoteException
Ensures that agent is running on host (moving it there if necessary with given parameters). Must be asserted in agent contructor. Any state the agent has established up to the tiedTo assertion is lost.
Parameters:
host - host to tie agent to ("machine.ai.mit.edu", "128.128.128.128")
Throws:
SpreadError - some reliance could not spread
InvalidArgumentException - (runtime) host is unknown

tieToDesignation

protected String tieToDesignation()
                           throws RemoteException
If the designation string is a name of a known host, this method will tie this agent to the host named in designation. Otherwise, it will do nothing. If tying, the method returns the name of the host (i.e. the designation). If not tying, it returns null. THIS METHOD CAN ONLY BE CALLED FROM WITHIN AN AGENT CONSTRUCTOR!!!

obtainMetaglueAgent

public Metaglue obtainMetaglueAgent(AgentID mid)
                             throws MetaglueSystemError
Returns:
metaglue agent with given ID.

obtainMetaglueAgentByName

public Metaglue obtainMetaglueAgentByName(String ma,
                                          boolean retry_if_fail)
                                   throws MetaglueSystemError
Returns:
metaglue agent with given ID.

obtainMetaglueAgent

public Metaglue obtainMetaglueAgent(InetAddress host)
                             throws MetaglueSystemError
Returns:
metaglue agent on given host. Will start one if necessary.

startAgentOn

public void startAgentOn(AgentID theAgentID,
                         Metaglue metaglue,
                         boolean agent_previously_started,
                         Object[] parameters)
                  throws RemoteException
Start given agent on given metaglue agent.

startAgentOn

public void startAgentOn(AgentID theAgentID,
                         String host)
                  throws RemoteException
Try to start agent on metaglue agent with given host for christian name, or, failing that, that host for a computer. This allows you to start an agent on a remote machine, even if the agent is not internally tied to the machine.

getProperties

public Properties getProperties()

getAttribute

public String getAttribute(String attributeName)
Get attribute value for name.
Throws:
AttributeError - attribute database found corrupt

fixAttribute

protected String fixAttribute(AgentID aid,
                              String attributeName)

fixAttribute

protected String fixAttribute(AgentID aid,
                              String attributeName,
                              String specialMessage)
                       throws MissingAttributeError
Allows you to fix an existing attribute (useful if you try to cast attribute to something and it fails)

getSociety

public String getSociety()

getOccupation

public String getOccupation()

getDesignation

public Object getDesignation()

getAgentID

public AgentID getAgentID()
                   throws RemoteException
Specified by:
getAgentID in interface Agent

getCatalogID

public CatalogID getCatalogID()
                       throws RemoteException

getCatalog

public Catalog getCatalog()
                   throws RemoteException

alive

public boolean alive()
              throws RemoteException
Specified by:
alive in interface Agent

shutdown

public void shutdown()
              throws RemoteException
Changes the agent so that it cannot be found through the catalog or accept RMI calls. Subclasses should override this to kill any running threads, close any serial ports, and call the superclass shutdown() method as well.
Specified by:
shutdown in interface Agent
Throws:
RemoteException - if an error occurs

startup

public void startup()
             throws RemoteException
Specified by:
startup in interface Agent

freezeAll

public void freezeAll()
               throws RemoteException
A simple routine to freeze all the state of an object. Currently this is empty, and you should override this to make it do good things.

freezeVar

public void freezeVar(String var,
                      Object obj)
`Freeze' an object into the icebox. This will store the given object under the given name in some location, where it can later be `defrosted'. Anything serializable can be frozen--it will dump the serializable form of the object out using an ObjectOutputStream. The format for frozen objects is as defined in CrystalOutputStream.
Parameters:
var - The variable name to save under.
obj - The object being saved. This must satisfy Serializable.
See Also:
defrost(String), CrystalOutputStream

removeFrozen

public boolean removeFrozen(String var)
Remove a frozen object from the icebox.
Parameters:
var - The variable name to remove.
See Also:
defrost(String), freezeVar(String, Object)

freeze

public void freeze(String var,
                   Serializable o)
`Freeze' an object into the icebox.
Parameters:
var - The variable name to save under.
obj - The object being saved.
See Also:
defrost(String), CrystalOutputStream

freeze

public void freeze(String var,
                   int i)
`Freeze' an integer value into the icebox.
Parameters:
var - The variable name to save under.
i - The object being saved.
See Also:
freeze(String, Serializable), defrost(String), CrystalOutputStream

freeze

public void freeze(String var,
                   boolean b)
`Freeze' a boolean value into the icebox.
Parameters:
var - The variable name to save under.
b - The object being saved.
See Also:
freeze(String, Serializable), defrost(String), CrystalOutputStream

setFreezeName

protected void setFreezeName(String name)

defrost

public Object defrost(String var)
Defrosts an object to get its value from the icebox. Returns null if the object is not found.
Parameters:
var - The variable name to defrost.
Returns:
The object stored under the name.
See Also:
freezeVar(String, Object)

defrostBoolean

public boolean defrostBoolean(String var)
Defrosts a boolean value from the icebox.
Parameters:
var - The variable name to defrost.
Returns:
return var as boolean. If error or undefined, return false.
See Also:
defrost(String)

defrostInt

public int defrostInt(String var)
Defrosts a boolean value from the icebox.
Parameters:
var - The variable name to defrost.
Returns:
return var as int. If error or undefined, return 0.
See Also:
defrost(String)

defrostString

public String defrostString(String var)
Defrosts a string from the icebox.
Parameters:
var - The variable name to defrost.
Returns:
return string. If error or undefined, returns null.
See Also:
defrost(String)

getFrozenVariables

public Set getFrozenVariables()
                       throws RemoteException
Gets the set of variables stored in the icebox.
Returns:
A set of variable names.
See Also:
freezeVar(String, Object), defrost(String)

defrostAll

public Hashtable defrostAll()
                     throws RemoteException
Gets the variables and values stored in the icebox.
Returns:
A hashtable mapping variable names to values.
See Also:
freezeVar(String, Object), defrost(String)

whereAreYou

public InetAddress whereAreYou()
                        throws RemoteException
Returns the InetAddress of the machine where the agent is running
Specified by:
whereAreYou in interface Agent

setLogName

public void setLogName(String n)
Sets a name for this agent that can be used while logging. Usually this is used to give the agent a shorter name that doesn't clutter up the logs.
Parameters:
n - A string with the new log name in it.

log

public void log(Object obj)
Send a log message to the logging stream. The log level will be INFO, and the object will be converted to a String automatically.
Parameters:
obj - The object to log.
See Also:
log(int, String)

log

public void log(int level,
                String info)
Send a log message to the logging stream. The log level will be one of the level constants listed in LogStream.
Parameters:
level - The log level.
info - The string to send to the log.
See Also:
LogStream

log

public void log(String level,
                String info)
Send a log message to the logging stream. The log level string is converted to an integer.
Parameters:
level - The log level, usually one of "INFO", "DEBUG", "WARNING", "ERROR", or "CRITICAL". If it's unrecognized, the log level will be "INFO".
info - The string to send to the log.
See Also:
log(int, String)

setLogLevel

public void setLogLevel(int level)

getLogLevel

public int getLogLevel(int level)

addMonitor

public void addMonitor(Spy monitor)
                throws RemoteException
Description copied from interface: Agent
Add a log monitor that gets all the screen output.
Specified by:
addMonitor in interface Agent