com.agentfactory.cldc.p2pmts
Class PeerToPeerMTS

java.lang.Object
  extended by com.agentfactory.cldc.Service
      extended by com.agentfactory.cldc.p2pmts.PeerToPeerMTS
All Implemented Interfaces:
java.lang.Runnable

public class PeerToPeerMTS
extends Service
implements java.lang.Runnable

The peer to peer message transport service facilitates communication between agents in AFME in a peer to peer manner. If agents are on the local platform, messages are transferred directly. If agents are not on the same platform, sockets are used.

Author:
Conor Muldoon

Constructor Summary
PeerToPeerMTS(java.lang.String[] args, java.lang.Object[] agtNms, Scheduler scheduler, Platform plat)
          Creates an instance of PeerToPeerMTS.
 
Method Summary
 boolean messageAdd(AgentName targetName, java.lang.String performative, AgentName senderName, java.lang.String url, FOS content)
          Adds a message to the message container of the target agent.
 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 peer to peer message transport service.
 FOS processPer(AgentName agentName, int perceptionID)
          Enables the agent to perceive information pertaining to message transport.
 void run()
          Receives incomming socket connections and adds messages to the service.
 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

PeerToPeerMTS

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

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.

run

public void run()
Receives incomming socket connections and adds messages to the service.

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 peer to peer 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.

messageAdd

public boolean messageAdd(AgentName targetName,
                          java.lang.String performative,
                          AgentName senderName,
                          java.lang.String url,
                          FOS content)
Adds a message to the message container of the target agent.

Parameters:
targetName - the name of the agent the message is intended for.
performative - the performative of the message.
senderName - the name of the agent that sent the message.
url - the address of the agent that sent the message.
content - the information content of the message.
Returns:
true if there is no agent container for the target agent, false otherwise.