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

Class JavaAgent.agent.MessageHandler

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

public class MessageHandler
extends Object
Object which handles all message transmissions for an Agent, maintains the link to the CommInterface. When the agent makes a call to sendMessage(), the message is put in the outgoing buffer. Similarly, when the CommInterface receives a message, it is put in the incoming buffer. Both the outgoing and incoming buffers are instances of MessageBuffer, which provides for synchronized access to the stored messages. Instances of TransmitterThread and ReceiverThread pull messages out of the buffers for either transmission by the CommInterface or processing.

Message transmission is normally serialized using the pending_transmission flag (i.e. receipt of transmission for each message is secured before the next message is sent). The releasePending() method can be called to allow for non-serialized message transmission, this done with address retrieval (the current message must release the pending flag so that the address retrieval message can actually be sent).

Message processing is not serialized: as each message is pulled off the buffer a separate thread is started to process the message. Serialized processing can be accomplished by rewriting the ReceiverThread class. When a message is finally sent it is put in a rotating transmitted messages buffer, the same is done for received messages.


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 comm
Mechanism through which messages are sent and received.
 o current_message
KQMLmessage which is currently being interpreted, or null if no message is being interpreted.
 o incoming
Buffer for received messages waiting to be processed.
 o last_message
Is this the last message which needs to be send before termination?
 o messages_in
Storage for received messages.
 o messages_out
Storage for transmitted messages.
 o outgoing
Buffer for messages waiting to be sent.
 o output_buffer
Buffer for messages waiting to be sent.
 o parent
Agent whose Resources are managed.
 o receiver
Thread which pulls messages from the incoming MessageBuffer and calls the specified Interpreter object for interpretation.
 o transmission_pending
Is there a message currently being sent?
 o transmitter
Thread which pulls messages from the outgoing MessageBuffer and calls the CommInterface for transmission.

Constructor Index

 o MessageHandler(Agent)
Creates a new MessageHandler.

Method Index

 o addSystemMessage(String)
Sends a system message to the agent.
 o addSystemMessage(String, Exception)
Sends a system message to the agent w/ exception.
 o currentMessage()
Returns the message currently being interpreted, returns null if no message is being interpreted.
 o getReceivedMessages()
Returns a Vector of received messages, if more than MESSAGE_STORAGE number have been received, only returns the most recent.
 o getSentMessages()
Returns a Vector of transmitted messages, if more than MESSAGE_STORAGE number have been sent, only returns the most recent.
 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 interpretMessage(KQMLmessage)
Called by the ReceiverThread to interpret a specific message.
 o invalidateAddress()
Called when the current address has been invalidated.
 o isPending()
This method will block until there is no longer a transmission pending.
 o receiveMessage(KQMLmessage)
Called by the associated CommInterface when a KQMLmessage is received.
 o releasePending()
Sets the transmission_pending flag to false.
 o resourceChanged(String)
Called when a non-Resource object has changed.
 o saveMessage(Vector, KQMLmessage)
Saves the message in the given storage.
 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 sendToComm(KQMLmessage)
Called by the TransmitterThread to send a message.
 o setComm(CommInterface)
Sets the CommInterface for the MessageHandler and creates and starts the TransmitterThread.
 o terminate()
Called when the last termination message has been sent.

Variables

 o parent
  protected Agent parent
Agent whose Resources are managed.
 o comm
  protected CommInterface comm
Mechanism through which messages are sent and received. The CommInterface must be intialized and assigned in the AgentContext which contains the Agent.
 o outgoing
  protected MessageBuffer outgoing
Buffer for messages waiting to be sent.
 o transmitter
  protected TransmitterThread transmitter
Thread which pulls messages from the outgoing MessageBuffer and calls the CommInterface for transmission.
 o incoming
  protected MessageBuffer incoming
Buffer for received messages waiting to be processed.
 o receiver
  protected ReceiverThread receiver
Thread which pulls messages from the incoming MessageBuffer and calls the specified Interpreter object for interpretation.
 o current_message
  protected KQMLmessage current_message
KQMLmessage which is currently being interpreted, or null if no message is being interpreted.
 o messages_in
  protected Vector messages_in
Storage for received messages. Rolling buffer of size defined by MESSAGE_STORAGE. Type KQMLmessage.
 o messages_out
  protected Vector messages_out
Storage for transmitted messages. Rolling buffer of size defined by MESSAGE_STORAGE. Type KQMLmessage.
 o output_buffer
  protected Vector output_buffer
Buffer for messages waiting to be sent.
 o last_message
  protected KQMLmessage last_message
Is this the last message which needs to be send before termination?
 o transmission_pending
  protected boolean transmission_pending
Is there a message currently being sent?

Constructors

 o MessageHandler
  public MessageHandler(Agent parent)
Creates a new MessageHandler. Creates and starts the ReceiverThread.
Parameters:
parent - Agent which this handler represents.

Methods

 o setComm
  public void setComm(CommInterface comm)
Sets the CommInterface for the MessageHandler and creates and starts the TransmitterThread.
Parameters:
comm - CommInterface which performs the low-level message transmission.
 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)
Sends a system message to the agent.
Parameters:
message - The system message to output.
 o addSystemMessage
  public void addSystemMessage(String message,
                               Exception e)
Sends a system message to the agent w/ exception.
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 sendMessage
  public void sendMessage(KQMLmessage message)
Called to send a given KQMLmessage. Inserts the message in the outgoing buffer.
Parameters:
message - The KQMLmessage to send.
 o sendToComm
  protected void sendToComm(KQMLmessage message)
Called by the TransmitterThread to send a message. Calls the sendMessage() method of the CommInterface.
Parameters:
message - KQMLmessage to send.
 o saveMessage
  protected void saveMessage(Vector storage,
                             KQMLmessage message)
Saves the message in the given storage. Only keep the most recent MESSAGE_STORAGE messages.
Parameters:
storage - The storage Vector.
message - Message to save.
 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 isPending
  public synchronized void isPending()
This method will block until there is no longer a transmission pending.
 o releasePending
  public synchronized void releasePending()
Sets the transmission_pending flag to false.
 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 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 interpretMessage
  protected void interpretMessage(KQMLmessage message)
Called by the ReceiverThread to interpret a specific message.
 o invalidateAddress
  public void invalidateAddress()
Called when the current address has been invalidated. Sends an invalidate address message to the ANS.
 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