agentland.behavior
Class BehaviorAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
                          |
                          +--agentland.util.GoodAgent
                                |
                                +--agentland.resource.ManagedAgent
                                      |
                                      +--agentland.behavior.BehaviorAgent
All Implemented Interfaces:
Agent, Behavior, Good, Managed, MetagluePrimitives, Remote, Serializable, Spy
Direct Known Subclasses:
DefaultBehaviorAgent, DefaultTestingBehaviorAgent, MeetingBehaviorAgent, MovieBehaviorAgent, OccupiedBehaviorAgent, QuietBehaviorAgent

public class BehaviorAgent
extends ManagedAgent
implements Behavior

BehaviorAgent is the parent class for all Behaviors. Changes I will be making soon:
-> Use persistent maps and other forms of persistent storage
Ajay Kulkarni 7.25.2001

See Also:
ManagedAgent, Behavior, Serialized Form

Inner classes inherited from class metaglue.AgentAgent
AgentAgent.Attribute
 
Fields inherited from class agentland.resource.ManagedAgent
rm, society
 
Fields inherited from class agentland.util.GoodAgent
alert, notifier
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
BehaviorAgent()
          Creates a new BehaviorAgent instance.

Contains the code that stores all the Actions of a particular Behavior subclass.
 
Method Summary
 void activate(Secret secret)
          Each particular behavior -- i.e., a subclass of this class -- needs to implement this method.
 void activateAction(String actionName)
          The BehaviorAgent itself calls this method to restore an overriden action.
 void activateParent(BehaviorID bID)
          Adds a parent to its Active Parent collection
protected  void addAction(Method action)
          How a behavior adds its actions.
 void addActionDependency(BehaviorID parID, String thisAction, String parentAction)
          Adds an action dependency between an action in this behavior and an action in another behavior (parent).
 void addChild(BehaviorID bID)
          When this Behavior is no longer a Leaf Behavior, this method adds a connection the Bev(s) one level of hierarchy below this bev.
protected  void addEvent(String eventName, String actionName)
          How a behavior specifies what events (notifications) it wants to listen for, and what actions within the behavior listen for these events.
 void addParent(BehaviorID bID)
          Adds a child-parent relationship between this behavior (child) and another behavior with ID bID.
 void addPermanentAction(String actionName)
          Adds an action to the collection of Permanent Actions of this behavior.
 void deactivateParent(BehaviorID bID)
          Removes a parent from the Active Parent collection
 void deleteActionDependency(BehaviorID parID, String thisAction, String parentAction)
          Removes an action dependency between an action in this behavior and an action in another behavior (parent).
If the parent is not registered with this behavior, returns an error message.
 Vector getActivationEvents()
          Returns the events that ths behavior's activate method listens for...
 Vector getActiveParents()
          Returns all parents of this child that are in an active state.
 Vector getAllEvents()
          Returns all the events that this behavior listens for, i.e., the combination of getEvents() and getActivationEvents().
 Vector getChildren()
          Returns the behaviors that are at one level of hierarchy below this bev (in the active behavioral tree).
 String getDependencies()
          Returns the names of the actions in all its parents that this behavior overrides.
 String getDependencies(BehaviorID parID)
          Returns the names of the actions in parent with BehaviorID parID that this behavior overrides.
 Vector getDirectActiveParents()
          Returns the active parents that are at one level of hierarchy above this bev (in the active behavioral tree).
 Vector getEvents()
          Returns the events that this behavior's Actions listens for.
 BehaviorID getID()
          Returns the BehaviorID of this Behavior.
 String getName()
          Returns the name of this Behavior.
 Vector getOverridenActions()
          Returns the names of the actions of this Behavior that have been overriden.
 Vector getParents()
          Returns all parents of this child: i.e., all Behaviors such that a (child=>parent) relationship exists with this behavior (the child).
 Vector getPermanentActions()
          Returns the names of the actions of this Behavior that can not be overriden by any other behavior.
 boolean isActive()
          A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true of this Behavior is Active.
 boolean isInactive()
          A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is Inactive.
 boolean isLeaf()
          A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is a Leaf.
 boolean isListening()
          A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is Listening.
 boolean isOverriden()
          A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is Overriden.
protected  void makeActive()
          Changes the state of the Behavior to Leaf Active from a non-active state.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
This method also climbs up the active behavioral tree, identifying the direct parent(s) up this behavior.
protected  void makeDeActive()
          This method is called when a Behavior is transitioning from an Active state (leaf or overriden) to a Non-Active state (listening or inactive).
protected  void makeInactive()
          Changes the state of the Behavior to Inactive.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
protected  void makeListening()
          Changes the state of the Behavior to Listening.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
protected  void makeOverriden()
          Changes the state of the Behavior to Overriden.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
protected  void makeUnOverriden()
          Changes the state of the Behavior to UnOverriden.(i.e., from Overriden Active to Leaf Active)
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
protected  Method nameToAction(String actionName)
          Given the name of an Action in this Behavior, returns the Method object of the Action.
 void override(Vector actionNames)
          What a child behavior would call to override specific actions of this behavior.
 void overrideAction(String actionName)
          The BehaviorAgent itself calls this method to mark an action as overriden.
 void pass(Secret secret)
          What the BehaviorCoordinator calls to pass an event (i.e., the Secret) to the Behavior.
 void registerBevCoord(AgentID aid)
          How the BehaviorCoordinator registers itself with this Behavior.
 void removeChild(BehaviorID bID)
          When a child behavior of this behavior becomes deactivated, it tells this bev, and this bev disconnects itself from the child.
 void removePermanentAction(String actionName)
          Removes an action from the collection of Permanent Actions of this behavior.
 void setIDNumeric(Integer num)
          How to set the numeric value of this Behavior's BehaviorID
 String showHashedAgentStubs()
          Returns a String representation of the agentID-->agentStub mapping.
 void temporarilyActivateAction(String actionName)
          For a given pass of a secret, a behavior can temporarily activate an action (that is overriden) in this action.
 void undoOverride(Vector actionNames)
          What a child behavior would call to un-override specific actions of this behavior.
protected  void unOver()
          Is called by actions to allow for the temporarily activation of all actions in all ancestor bevs that this action normally overrides.
 
Methods inherited from class agentland.resource.ManagedAgent
connect, getAlert, getNeed, isAvailable, isAvailable, reliesOn, reliesOn, replace, replace, request, request, request, requestAgent, requestAgent, resources, resourcesByAgentID, setNeed, tiedTo, yank, yank, yank
 
Methods inherited from class agentland.util.GoodAgent
addSpy, addSpy, alert, alertString, beep, error, getHistory, getHistoryElement, getPersistentMap, log, notify, removeSpy, removeSpy, resetHistory, safeRely, safeRely, safeRely, setNiceLogName, tell
 
Methods inherited from class metaglue.AgentAgent
addMonitor, alive, defrost, defrostAll, defrostBoolean, defrostInt, defrostString, fixAttribute, fixAttribute, freeze, freeze, freeze, freezeAll, freezeVar, getAgentID, getAttribute, getCatalog, getCatalogID, getDesignation, getFrozenVariables, getLogLevel, getMetaglueAgent, getMetaglueAgentID, getOccupation, getProperties, getSociety, log, log, lookupClass, obtainMetaglueAgent, obtainMetaglueAgent, obtainMetaglueAgentByName, reliesOn, reliesOnSynch, removeFrozen, replaceExceptionHandler, setFreezeName, setLogLevel, setLogName, shutdown, startAgent, startAgentOn, startAgentOn, startup, status, tiedTo, tiedTo, tiedTo, tiedTo, tieToDesignation, whereAreYou
 
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
 
Methods inherited from interface agentland.resource.Managed
getNeed, replace, replace, resources, yank, yank
 
Methods inherited from interface agentland.util.Good
getHistory, getHistoryElement, resetHistory
 
Methods inherited from interface metaglue.Agent
addMonitor, alive, getAgentID, getMetaglueAgentID, shutdown, startup, whereAreYou
 
Methods inherited from interface agentland.util.Spy
tell
 

Constructor Detail

BehaviorAgent

public BehaviorAgent()
              throws RemoteException
Creates a new BehaviorAgent instance.

Contains the code that stores all the Actions of a particular Behavior subclass. Must be called in each Behavior subclass. (i.e., by calling super(); in the subclass constructor.
Throws:
RemoteException - if an error occurs
Method Detail

getID

public BehaviorID getID()
Returns the BehaviorID of this Behavior.
Specified by:
getID in interface Behavior
Returns:
a BehaviorID value

setIDNumeric

public void setIDNumeric(Integer num)
                  throws RemoteException
How to set the numeric value of this Behavior's BehaviorID
Specified by:
setIDNumeric in interface Behavior
Parameters:
num - an Integer value
Throws:
RemoteException - if an error occurs
See Also:
BehaviorID

isOverriden

public boolean isOverriden()
A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is Overriden.
Specified by:
isOverriden in interface Behavior
Returns:
a boolean value

isLeaf

public boolean isLeaf()
A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is a Leaf.
Specified by:
isLeaf in interface Behavior
Returns:
a boolean value

isActive

public boolean isActive()
A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true of this Behavior is Active.
Specified by:
isActive in interface Behavior
Returns:
a boolean value

isListening

public boolean isListening()
A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is Listening.
Specified by:
isListening in interface Behavior
Returns:
a boolean value

isInactive

public boolean isInactive()
A Behavior can be in one of four states:
0: Inactive
1: Listening
2: Leaf Active
3: Overriden Active
Returns true if this Behavior is Inactive.
Specified by:
isInactive in interface Behavior
Returns:
a boolean value

makeOverriden

protected void makeOverriden()
Changes the state of the Behavior to Overriden.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
See Also:
BehaviorCoordinator

makeUnOverriden

protected void makeUnOverriden()
Changes the state of the Behavior to UnOverriden.(i.e., from Overriden Active to Leaf Active)
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
See Also:
BehaviorCoordinator

makeActive

protected void makeActive()
Changes the state of the Behavior to Leaf Active from a non-active state.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
This method also climbs up the active behavioral tree, identifying the direct parent(s) up this behavior. As the Behavior is transitioning from a non-active state to leaf active, this method overrides the appropriate actions of its active ancestors.
See Also:
BehaviorCoordinator

makeListening

protected void makeListening()
Changes the state of the Behavior to Listening.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
See Also:
BehaviorCoordinator

makeInactive

protected void makeInactive()
Changes the state of the Behavior to Inactive.
If this bev is registered with a Behavior Coordinator (as it should be), it updates its state with the Coordinator.
See Also:
BehaviorCoordinator

makeDeActive

protected void makeDeActive()
This method is called when a Behavior is transitioning from an Active state (leaf or overriden) to a Non-Active state (listening or inactive). It contains tasks common for when a Behavior is deactivated: e.g., undo the overriding of ancestorial behaviors.
Note that while a Behavior used to have to explicitly call this method, now, this method is called automatically by the pass() method if the behavior becomes deactivated from its actionDeactive method (i.e., its deactive action).
See Also:
pass(Secret secret)

addParent

public void addParent(BehaviorID bID)
               throws RemoteException
Adds a child-parent relationship between this behavior (child) and another behavior with ID bID.
Specified by:
addParent in interface Behavior
Parameters:
bID - The BehaviorID of the parent
Throws:
RemoteException - if an error occurs

addChild

public void addChild(BehaviorID bID)
              throws RemoteException
When this Behavior is no longer a Leaf Behavior, this method adds a connection the Bev(s) one level of hierarchy below this bev. This method is called by the child behavior -- this behavior has no knowledge of the child behavior until the child tells it.
Specified by:
addChild in interface Behavior
Parameters:
bID - the BehaviorID of the child behavior
Throws:
RemoteException - if an error occurs

removeChild

public void removeChild(BehaviorID bID)
                 throws RemoteException
When a child behavior of this behavior becomes deactivated, it tells this bev, and this bev disconnects itself from the child. (This method is called by the child behavior.)
Specified by:
removeChild in interface Behavior
Parameters:
bID - a BehaviorID value
Throws:
RemoteException - if an error occurs

getParents

public Vector getParents()
                  throws RemoteException
Returns all parents of this child: i.e., all Behaviors such that a (child=>parent) relationship exists with this behavior (the child).
Specified by:
getParents in interface Behavior
Returns:
a Vector containing the BehaviorIDs of the parents
Throws:
RemoteException - if an error occurs

getActiveParents

public Vector getActiveParents()
Returns all parents of this child that are in an active state. Note that if this behavior is active, this method will only return the parents that are in an active state that is hierarchically higher than this behavior.
This method is different than getDirectActiveParents(), which returns the parents that are at one level of hierarchy above this bev (in the active behavioral tree).
Specified by:
getActiveParents in interface Behavior
Returns:
a Vector containing the BehaviorIDs of the parents
Throws:
RemoteException - if an error occurs
See Also:
getDirectActiveParents()

getDirectActiveParents

public Vector getDirectActiveParents()
Returns the active parents that are at one level of hierarchy above this bev (in the active behavioral tree). Related to getChildren().
Specified by:
getDirectActiveParents in interface Behavior
Returns:
a Vector containing the BehaviorIDs of the parents
See Also:
getChildren()

getChildren

public Vector getChildren()
Returns the behaviors that are at one level of hierarchy below this bev (in the active behavioral tree). Related to getDirectActiveParents().
Specified by:
getChildren in interface Behavior
Returns:
a Vector containing the BehaviorIDs of the children
See Also:
getDirectActiveParents()

activateParent

public void activateParent(BehaviorID bID)
Adds a parent to its Active Parent collection
Specified by:
activateParent in interface Behavior
Parameters:
bID - the BehaviorID of the parent to be activated

deactivateParent

public void deactivateParent(BehaviorID bID)
Removes a parent from the Active Parent collection
Specified by:
deactivateParent in interface Behavior
Parameters:
bID - the BehaviorID of the parent to be deactivated

addActionDependency

public void addActionDependency(BehaviorID parID,
                                String thisAction,
                                String parentAction)
                         throws RemoteException
Adds an action dependency between an action in this behavior and an action in another behavior (parent).
Specified by:
addActionDependency in interface Behavior
Parameters:
parID - the BehaviorID of the parent behavior
thisAction - the String name of the action in this behavior that is overriding
parentAction - the String name of the action in the parent behavior that is being overriden
Throws:
RemoteException - if an error occurs

deleteActionDependency

public void deleteActionDependency(BehaviorID parID,
                                   String thisAction,
                                   String parentAction)
                            throws RemoteException
Removes an action dependency between an action in this behavior and an action in another behavior (parent).
If the parent is not registered with this behavior, returns an error message.
Specified by:
deleteActionDependency in interface Behavior
Parameters:
parID - the BehaviorID of the parent behavior
thisAction - the String name of the action in this behavior that is overriding
parentAction - the String name of this action in the parent behavior that is being overriden
Throws:
RemoteException - if an error occurs

getOverridenActions

public Vector getOverridenActions()
Returns the names of the actions of this Behavior that have been overriden. (Note that the behavior must be in the overriden state for it to have any overriden actions.
Specified by:
getOverridenActions in interface Behavior
Returns:
a Vector of the names of the overriden actions (as String objects)
Throws:
RemoteException - if an error occurs

getPermanentActions

public Vector getPermanentActions()
Returns the names of the actions of this Behavior that can not be overriden by any other behavior.
Specified by:
getPermanentActions in interface Behavior
Returns:
a Vector of the String names of the actions
See Also:
addPermanentAction(String actionName), removePermanentAction(String actionName)

getEvents

public Vector getEvents()
                 throws RemoteException
Returns the events that this behavior's Actions listens for.
Specified by:
getEvents in interface Behavior
Returns:
a Vector of events (notifications) as String
Throws:
RemoteException - if an error occurs

getActivationEvents

public Vector getActivationEvents()
                           throws RemoteException
Returns the events that ths behavior's activate method listens for... i.e., the events that will activate this action.
Specified by:
getActivationEvents in interface Behavior
Returns:
a Vector of events (notifications) as String
Throws:
RemoteException - if an error occurs

getAllEvents

public Vector getAllEvents()
                    throws RemoteException
Returns all the events that this behavior listens for, i.e., the combination of getEvents() and getActivationEvents().
Specified by:
getAllEvents in interface Behavior
Returns:
a Vector of events (notifications) as String
Throws:
RemoteException - if an error occurs

addAction

protected void addAction(Method action)
How a behavior adds its actions.
Parameters:
action - the method to be called (i.e., the action) as a Method object

addPermanentAction

public void addPermanentAction(String actionName)
Adds an action to the collection of Permanent Actions of this behavior. (A Permanent Action is an action that can not be overriden by any other behavior.)
Specified by:
addPermanentAction in interface Behavior
Parameters:
actionName - a String value

removePermanentAction

public void removePermanentAction(String actionName)
Removes an action from the collection of Permanent Actions of this behavior. (A Permanent Action is an action that can not be overriden by any other behavior.)
Specified by:
removePermanentAction in interface Behavior
Parameters:
actionName - a String value

addEvent

protected void addEvent(String eventName,
                        String actionName)
How a behavior specifies what events (notifications) it wants to listen for, and what actions within the behavior listen for these events.
Parameters:
eventName - the name of the notification as a String
actionName - the name of an action that listens for this notification, as a String

nameToAction

protected Method nameToAction(String actionName)
Given the name of an Action in this Behavior, returns the Method object of the Action.
Parameters:
actionName - the name of the Action, as a String object
Returns:
the Action, as a Method object

overrideAction

public void overrideAction(String actionName)
                    throws RemoteException
The BehaviorAgent itself calls this method to mark an action as overriden. I should probably make this a private / protected method.
Note that if the action is permanent, i.e., it can't be overriden, this method logs an error message.
Specified by:
overrideAction in interface Behavior
Parameters:
actionName - the name of the action to be overriden
Throws:
RemoteException - if an error occurs

activateAction

public void activateAction(String actionName)
                    throws RemoteException
The BehaviorAgent itself calls this method to restore an overriden action. I should probably make this a private / protected method.
Specified by:
activateAction in interface Behavior
Parameters:
actionName - a String value
Throws:
RemoteException - if an error occurs

temporarilyActivateAction

public void temporarilyActivateAction(String actionName)
For a given pass of a secret, a behavior can temporarily activate an action (that is overriden) in this action. Note that the bev temporarily activating should be the same bev that overrode the action in the first place.
Specified by:
temporarilyActivateAction in interface Behavior
Parameters:
actionName - the name of the action to temporarily activate, as a String
See Also:
getTemporarilyActiveActions()

override

public void override(Vector actionNames)
              throws RemoteException
What a child behavior would call to override specific actions of this behavior. The child behavior passes a collection of the names of the actions that it wants to override.
Specified by:
override in interface Behavior
Parameters:
actionNames - a Vector containing the names of the actions that the child behavior wants to override. Each name is a String object.
Throws:
RemoteException - if an error occurs

undoOverride

public void undoOverride(Vector actionNames)
                  throws RemoteException
What a child behavior would call to un-override specific actions of this behavior. The child behavior passes a collection of the names of the actions that it wants to restore.
Specified by:
undoOverride in interface Behavior
Parameters:
actionNames - a Vector containing the names of the actions that the child behavior wants to restore. Each name is a String object.
Throws:
RemoteException - if an error occurs

activate

public void activate(Secret secret)
Each particular behavior -- i.e., a subclass of this class -- needs to implement this method. This method is the Action that is called when the Behavior is Listening; it specifies how the behavior is activated (i.e., what notification(s) activate(s) the behavior).
In this class -- BehaviorAgent -- this method only logs an error message.
Parameters:
secret - the Secret that gets passed to the Behavior.

pass

public void pass(Secret secret)
          throws RemoteException
What the BehaviorCoordinator calls to pass an event (i.e., the Secret) to the Behavior. This method in turn calls all the actions of this Behavior.
Specified by:
pass in interface Behavior
Parameters:
secret - the Secret that gets passed
Throws:
RemoteException - if an error occurs
See Also:
BehaviorCoordinator

getName

public String getName()
               throws RemoteException
Returns the name of this Behavior. I'll probably get rid of this method soon, as you can do the same thing through the BehaviorID.
Specified by:
getName in interface Behavior
Returns:
the name
Throws:
RemoteException - if an error occurs

getDependencies

public String getDependencies(BehaviorID parID)
                       throws RemoteException
Returns the names of the actions in parent with BehaviorID parID that this behavior overrides.
Specified by:
getDependencies in interface Behavior
Parameters:
parID - the BehaviorID of the parent
Returns:
the names of all the actions that it overrides (in this parent), as a big String
Throws:
RemoteException - if an error occurs

getDependencies

public String getDependencies()
                       throws RemoteException
Returns the names of the actions in all its parents that this behavior overrides.
Specified by:
getDependencies in interface Behavior
Returns:
the names of all the actions that it overrides, as a big String
Throws:
RemoteException - if an error occurs

registerBevCoord

public void registerBevCoord(AgentID aid)
                      throws RemoteException
How the BehaviorCoordinator registers itself with this Behavior. Is called in the BehaviorCoordinator, after an external Agent has registered this Behavior with the Coordinator.
Specified by:
registerBevCoord in interface Behavior
Parameters:
aid - the AgentID of the BehaviorCoordinator
Throws:
RemoteException - if an error occurs

unOver

protected void unOver()
Is called by actions to allow for the temporarily activation of all actions in all ancestor bevs that this action normally overrides. Can be seen as analogous to the super() call in Java, but this analogy doesn't go very far. unOver() doesn't immediately call the action in the ancestor; the temporarily activated action is called when that behavior has the secret. So you can't embed the unOver() call as you would a super() call. Also, unOver() temporarily activates ALL actions (in ALL bevs) that the current action overrides. (But note that even if this action temporarily activates another action, if other actions still override the actions, it still won't be fired.)

showHashedAgentStubs

public String showHashedAgentStubs()
Returns a String representation of the agentID-->agentStub mapping.
Specified by:
showHashedAgentStubs in interface Behavior
Returns:
the String representation