com.agentfactory.cldc.mts
Class MessageTransportService

java.lang.Object
  extended by com.agentfactory.cldc.Service
      extended by com.agentfactory.cldc.mts.MessageTransportService
All Implemented Interfaces:
java.lang.Runnable

public class MessageTransportService
extends Service
implements java.lang.Runnable

The message transport service facilitates communication between agents in AFME. If agents are on the local platform, messages are transferred directly. If agents are not on the same platform sockets are used. The message transport service connects to a remote server to receive incomming messages. If the service is operating in synchronous mode, outgoing messages are also sent through the message server. If the service is operating in asynchronous mode, messages are sent in their own socket.

Author:
Conor Muldoon

Constructor Summary
MessageTransportService(java.lang.String[] args, java.lang.Object[] agtNms, Scheduler scheduler, Platform plat)
          Creates an instance of MessageTransportService.
 
Method Summary
 FOS addHolder(FOS name, java.lang.String performative, AgentName an, FOS content, FOS addresses)
          If the service is operating in asynchronous mode, returns a first order structure that represent a message that is to be sent.
static FOS createOutMessage(java.lang.String serverAddress, FOS agentAddresses, FOS name, AgentName senderName, FOS content)
          Creates a first order structure representation of the outgoing message.
 void modifyBinding(java.lang.Object oldName, java.lang.Object newName)
          Changes the name of an agent in the service's registry if one exists.
 FOS processAction(AgentName agentName, int actionID, FOS action)
          Performs an action on the message transport service.
 FOS processPer(AgentName agentName, int perceptionID)
          Enables the agent to perceive information pertaining to message transport.
 void run()
          The message transport service periodically connect to a message server.
 void sendOut(java.io.DataOutputStream dos, java.io.DataInputStream dis, javax.microedition.io.StreamConnection conn)
          Sends messages to the specified data output stream and once finished closes the data output stream, data input stream, and stream connection.
 
Methods inherited from class com.agentfactory.cldc.Service
register
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageTransportService

public MessageTransportService(java.lang.String[] args,
                               java.lang.Object[] agtNms,
                               Scheduler scheduler,
                               Platform plat)
Creates an instance of MessageTransportService.

Parameters:
args - a string of arugments that are passed to the service.
agtNms - the names of the agents on the local platform.
scheduler - the scheduler that will periodically execute the run method of the message transport service.
plat - the local platform, upon which the agents reside.
Method Detail

modifyBinding

public void modifyBinding(java.lang.Object oldName,
                          java.lang.Object newName)
Description copied from class: Service
Changes the name of an agent in the service's registry if one exists.

Specified by:
modifyBinding in class Service
Parameters:
oldName - the old name of the agent.
newName - the new name of the agent.

addHolder

public FOS addHolder(FOS name,
                     java.lang.String performative,
                     AgentName an,
                     FOS content,
                     FOS addresses)
              throws MalformedLogicException
If the service is operating in asynchronous mode, returns a first order structure that represent a message that is to be sent. Otherwise, a message holder is create and the message holder is stored in the outgoing messages list. When the service connects to the message server, the message will be sent accordingly.

Parameters:
name - the name of the agent that the message is to be sent to.
performative - the performative of the message.
an - the name of the ageent that sent the message.
content - the information content of the message.
addresses - the address of the agent that sent the message.
Returns:
a first order structure representation of the message if operating in asynchronous mode, otherwise null.
Throws:
MalformedLogicException - if there is a logic error.

run

public void run()
The message transport service periodically connect to a message server. The run method registers the service with the server the first time the platform executes. It subsequently polls the message server to receive incomming messages. If the service is operating is synchronous mode, outgoing messages are also sent through the server.

Specified by:
run in interface java.lang.Runnable

sendOut

public void sendOut(java.io.DataOutputStream dos,
                    java.io.DataInputStream dis,
                    javax.microedition.io.StreamConnection conn)
             throws java.io.IOException
Sends messages to the specified data output stream and once finished closes the data output stream, data input stream, and stream connection.

Parameters:
dos - the data output stream to write messages to and subsequently close.
dis - the data input stream to close.
conn - the stream connection to close.
Throws:
java.io.IOException - if there is an I/O error.

processPer

public FOS processPer(AgentName agentName,
                      int perceptionID)
               throws MalformedLogicException
Enables the agent to perceive information pertaining to message transport. Four different types of information may be perceived. (1) Messages that the agent has received. (2) Agent IDs that the agent requires or has used. (3) Messages that are pending delivery. (4) The local residents on the platform.

Specified by:
processPer in class Service
Parameters:
agentName - the agent that wishes to perceive the information.
perceptionID - the ID of the information that is to be perceived.
Returns:
a first order structure that represents the information that has been perceived in the service.
Throws:
MalformedLogicException - if there is a logic error.

processAction

public FOS processAction(AgentName agentName,
                         int actionID,
                         FOS action)
                  throws MalformedLogicException
Performs an action on the message transport service. There are size different action that may be performed. (1) An agent can be informed of a message. (2) A request can be made to an agent. (3) An agent ID can be saved to a persistent storage medium. (4) An agent ID can be added. (5) An agent ID can be updated. (6) An agent can be registered.

Specified by:
processAction in class Service
Parameters:
agentName - the name of the agent that is performing the action.
actionID - the ID of the action that is to be performed.
action - that data that is to be used in performing the action.
Returns:
true if the action was performed successfully, false otherwise.
Throws:
MalformedLogicException - if there is a logic error.

createOutMessage

public static FOS createOutMessage(java.lang.String serverAddress,
                                   FOS agentAddresses,
                                   FOS name,
                                   AgentName senderName,
                                   FOS content)
Creates a first order structure representation of the outgoing message.

Parameters:
serverAddress - the address of the server to where the message is being sent.
agentAddresses - the sender address.
name - the name of the agent the message is being sent to.
senderName - the name of the agent sending the message.
content - the content of the message.
Returns:
the message to be sent.