Class JavaAgent.agent.Agent
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class JavaAgent.agent.Agent

java.lang.Object
   |
   +----JavaAgent.agent.Agent

public class Agent
extends Object
Class which represents a autonomous software agent whose capabilities are represented by a set of resource objects which include both data and Java class definitions. Agent's communicate with one another via KQML messages which are transmitted by a CommInterface object. Resource storage and management is handled by a ResourceManager object. Message transmission via the CommInterface is the responsibility of a MessageHandler object.

The Agent must be created, along with the CommInterface, in an external class which implements the ContextInterface interface. Upon creation the agent must be provided with:

Each Agent, when created, loads a set of initialization messages from an initialization file. One of these messages will provide the address of an Agent Name Server (ANS) to which the Agent must send its name and address. Each Agent automatically "knows" the "KQML" language (KQMLmessage class) and the "agent" Interpreter (AgentInterpreter class).

The internal knowledge of an Agent is contained in a set of Resource classes (managed by the ResourceManager). Access to the data within these classes is synchronized to prevent race conditions. A special subclass of Resource, RetrievalResource, provides the storage for addresses, languages, interpreters and remotely loaded classes. When an Agent attempts to access a non-existent element from a RetrievalResource instance, the access thread is blocked and a message is sent to obtain the desired object. When the object is received, the access thread is restarted. (See the RetrievalResource class for more information). This action is taken for unknown addresses, languages, interpreters, general classes and files. For the retrieval of remote code, a Hashtable of NetworkClassLoaders is maintained.

When a message is received by an Agent the following steps occur within the MessageHandler:

Agent communications regarding addressing, code retrieval and other organizational or architectural issues (not related to domain knowledge) are done using KQML for the message content syntax and the "agent" MessageHandler. (See class AgentHandler).


Copyright (c) 1995, H. Robert Frost, Stanford University. All rights reserved.

Copyright (c) 1996, H. Robert Frost, Enterprise Integration Technologies, Inc. All rights reserved.

RESTRICTED RIGHTS LEGEND: Use, duplication or disclosure by the Government is subject to restrictions as set forth in subparagraph(c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 and in similar clauses in the FAR and NASA FAR supplement.

This software is bound by the terms and conditions listed in the attached LICENSE file.



Variable Index

 o context
Interface to the context in which the Agent was created.
 o handler
Object which handles all message transmission and maintains a history of both sent and received messages.
 o init_url
URL for initialization file.
 o io_enabled
Can the Agent perform local file io?
 o name
A unique String identifier for the Agent.
 o resources
Object which contains and manages all of the Agent's resources.
 o shared_classes
URL for the classes directory containing classes which will be shared with other agents.
 o shared_dir
Directory for local access to the shared classes URL.
 o working_dir
Working directory for saving files on the local disk, null if the Agent cannot write to the local file system.

Constructor Index

 o Agent(ContextInterface, String, URL, URL, File, File)
Contructs an Agent with a name, init file, shared classes URL and working directory.

Method Index

 o addPanel(Panel)
If the context supports a GUI, then add the instantiated and intialized panel to a new top-level window.
 o addSystemMessage(String)
Pipes a system message to the Agent's context.
 o addSystemMessage(String, Exception)
Pipes a system message to the Agent's context.
 o currentMessage()
Returns the message currently being interpreted, returns null if no message is being interpreted.
 o getName()
Gets name of Agent.
 o getReceivedMessages()
Returns a Vector of received messages, if more than MESSAGE_STORAGE number have been received, only returns the most recent.
 o getResource(String)
Get the resource object for the specified type.
 o getSentMessages()
Returns a Vector of transmitted messages, if more than MESSAGE_STORAGE number have been sent, only returns the most recent.
 o getSharedClassesURL()
Retrieves the URL for shared classes and files, returns null if there are no files to share.
 o getSharedDir()
Retrieves the directory for local access to the shared classe dir.
 o getWorkingDir()
Retrieves the directory for local file storage, might be null.
 o hasGUI()
Returns true if the AgentContext supports a GUI.
 o init()
Creates the ResourceManager, MessageHandler and reads in the init_file.
 o initiateTermination()
Called when the executable class which contains the Agent terminates.
 o interpretingMessage()
Returns true if the Agent is currently interpreting a message.
 o loadClass(URL, String)
Called to load a remote class into the current runtime environment.
 o loadInitFile(URL)
Loads a set of KQMLmessages from a file at the specified URL.
 o loadResource(String, String, String, String)
Loads a given resource.
 o localIO()
 o receiveMessage(KQMLmessage)
Called by the associated CommInterface when a KQMLmessage is received.
 o releasePending()
Releases the transmission block.
 o resourceChanged(Resource)
Called by a Resource object when the number of elements has changed.
 o resourceChanged(String)
Called when a non-Resource object has changed.
 o sendInitMessages()
Group of messages which are automatically sent out at startup.
 o sendMessage(KQMLmessage)
Called to send a given KQMLmessage.
 o sendResult(KQMLmessage, boolean, String)
Called by the associated CommInterface to report the success of a sendMessage call.
 o setComm(CommInterface)
Sets the value of the CommInterface.
 o setName(String)
Sets the name of the Agent.
 o terminate()
Called when the last termination message has been sent.

Variables

 o context
  protected ContextInterface context
Interface to the context in which the Agent was created.
 o resources
  protected ResourceManager resources
Object which contains and manages all of the Agent's resources.
 o handler
  protected MessageHandler handler
Object which handles all message transmission and maintains a history of both sent and received messages.
 o name
  protected String name
A unique String identifier for the Agent. When an Agent is started the user is requested to either provide a name or let the name default to one generated from the Agent's address (will be unique).
 o working_dir
  protected File working_dir
Working directory for saving files on the local disk, null if the Agent cannot write to the local file system.
 o shared_classes
  protected URL shared_classes
URL for the classes directory containing classes which will be shared with other agents.
 o shared_dir
  protected File shared_dir
Directory for local access to the shared classes URL.
 o init_url
  protected URL init_url
URL for initialization file.
 o io_enabled
  protected boolean io_enabled
Can the Agent perform local file io?

Constructors

 o Agent
  public Agent(ContextInterface context,
               String n,
               URL init_url,
               URL shared,
               File shared_dir,
               File working_dir)
Contructs an Agent with a name, init file, shared classes URL and working directory.
Parameters:
n - String identifier for the Agent.
init_url - URL for the initialization file.
shared - URL for shared classes.
shared_dir - Directory for local access to shared classes.
working_dir - Directory for local files, will be null if the Agent is unable to write to the local file system.

Methods

 o init
  public void init()
Creates the ResourceManager, MessageHandler and reads in the init_file.
 o setComm
  public void setComm(CommInterface c)
Sets the value of the CommInterface.
Parameters:
c - CommInterface for this Agent.
 o sendInitMessages
  public void sendInitMessages()
Group of messages which are automatically sent out at startup. If the name submitted by the agent is non-unique, these message will be resent with the unique name.
 o localIO
  public boolean localIO()
Returns:
True if the Agent can perform local file IO.
 o getSharedClassesURL
  public URL getSharedClassesURL()
Retrieves the URL for shared classes and files, returns null if there are no files to share.
Returns:
URL for directory containing both the classes directory and the directory for files.
 o getWorkingDir
  public File getWorkingDir()
Retrieves the directory for local file storage, might be null.
Returns:
Directory for local files.
 o getSharedDir
  public File getSharedDir()
Retrieves the directory for local access to the shared classe dir.
Returns:
Directory for shared classes
 o loadInitFile
  public void loadInitFile(URL file_url)
Loads a set of KQMLmessages from a file at the specified URL. This file must be a text file containing one KQMLmessage per line. The language and Interpreter fields for the messages are limited to "KQML" and "agent", respectively. At a minimum this file must contain a KQMLmessage informing the Agent of the address of the ANS, this message will have the following structure: "(evaluate :sender file :receiver: agent :language KQML :ontology agent :content (tell-address :name <name> :host <host> :port <port>))".
Parameters:
file_url - The URL for the init file.
 o loadResource
  public void loadResource(String type,
                           String name,
                           String object_name,
                           String url)
Loads a given resource. If the resource currently exists does not overwrite.
Parameters:
type - Type of resource, either language, Interpreter or class
name - The identifier for the resource.
object_name - The class or file name.
url - The code base for the class.
 o getResource
  public Resource getResource(String type)
Get the resource object for the specified type.
Parameters:
type - Resource type to get, one of: "address", "language", "interpreter" or "class".
Returns:
Resource object or null if type does not exist.
 o resourceChanged
  public void resourceChanged(Resource r)
Called by a Resource object when the number of elements has changed.
Parameters:
type - Type of the Resource.
 o resourceChanged
  public void resourceChanged(String resource)
Called when a non-Resource object has changed.
Parameters:
type - Type of resource.
 o addSystemMessage
  public void addSystemMessage(String message)
Pipes a system message to the Agent's context.
Parameters:
message - The system message to output.
 o addSystemMessage
  public void addSystemMessage(String message,
                               Exception e)
Pipes a system message to the Agent's context.
Parameters:
message - The system message to output.
e - Exception which generated the message, may be null.
 o interpretingMessage
  public boolean interpretingMessage()
Returns true if the Agent is currently interpreting a message.
Returns:
true if a message is being interpreted.
 o currentMessage
  public KQMLmessage currentMessage()
Returns the message currently being interpreted, returns null if no message is being interpreted.
 o getName
  public String getName()
Gets name of Agent.
Returns:
Agent name.
 o setName
  public void setName(String name)
Sets the name of the Agent.
Parameters:
name - Agent name.
 o hasGUI
  public boolean hasGUI()
Returns true if the AgentContext supports a GUI.
Returns:
True if the context has a GUI, false otherwise.
 o addPanel
  public void addPanel(Panel p)
If the context supports a GUI, then add the instantiated and intialized panel to a new top-level window.
Parameters:
p - Panel to add.
 o sendMessage
  public void sendMessage(KQMLmessage message)
Called to send a given KQMLmessage. Calls the sendMessage method of the associated MessageHandler which will pass the message to the CommInterface for transmission.

Parameters:
message - The KQMLmessage to send, null if the buffer is being flushed.
 o releasePending
  public void releasePending()
Releases the transmission block.
 o sendResult
  public void sendResult(KQMLmessage message,
                         boolean status,
                         String reason)
Called by the associated CommInterface to report the success of a sendMessage call.
Parameters:
message - The KQMLmessage which the CommInterface was asked to send.
status - True if the message transmission was successful, false if otherwise.
reason - String with detailed reason.
 o getSentMessages
  public Vector getSentMessages()
Returns a Vector of transmitted messages, if more than MESSAGE_STORAGE number have been sent, only returns the most recent.
Returns:
Vector of KQMLmessages.
 o getReceivedMessages
  public Vector getReceivedMessages()
Returns a Vector of received messages, if more than MESSAGE_STORAGE number have been received, only returns the most recent.
Returns:
Vector of KQMLmessages.
 o receiveMessage
  public void receiveMessage(KQMLmessage message)
Called by the associated CommInterface when a KQMLmessage is received. The message is handled based on the Interpreter for the message content. Content language is considered within the Interpreter handler.
Parameters:
message - The KQMLmessage which was received.
 o loadClass
  public Class loadClass(URL code_url,
                         String name)
Called to load a remote class into the current runtime environment. First check to see if a loader for the URL already exists, only create a new loader if one doesn't currently exist. Returns null if no code is found.
Parameters:
code_url - code base URL
name - Class name.
Returns:
The loaded Class.
 o terminate
  public void terminate()
Called when the last termination message has been sent.
 o initiateTermination
  public void initiateTermination()
Called when the executable class which contains the Agent terminates. The agent sends a remove-address message to the ANS.

All Packages  Class Hierarchy  This Package  Previous  Next  Index