ksu.cis.mom
Class Agent

java.lang.Object
  extended byksu.cis.mom.MomObject
      extended byksu.cis.mom.Agent
All Implemented Interfaces:
Runnable, Serializable

public abstract class Agent
extends MomObject
implements Runnable, Serializable

The Agent class is an abstract class that defines the minimum requirements for an agent to use agentMom package. This class inherits from MomObject class. It must be runnable as a separate thread, which requires a run method. It also has two required parameters that must be set for each agent, the name of the agent and the port number on which its message handler will listen for incoming messages.

Also, this class is associated with the MessageHandler, MulticastHandler, BroadcastHandler, SecureUnicastHandler and SecureMulticastHandler class.

An agent needs to start the correct handler to be able to receive the start of conversation from other agents. Furthermore, each agent must implement/override receive message method for each type of conversation. For unicast conversation, the agent must implement the receiveMessage method. For the other conversation, the agent must override the receive method corresponding to each conversation. The receive method will be called by the corresponding message handler when the agent has received a connection starting a new conversation. For example, the corresponding handler of receiveMulticastConversation method is MulticastHandler class, and the corresponding handler of receiveMessage method MessageHandler class.

History:
4 October 1999 - Creation Date
3 May 2001 - extended to allow conversations to work with either agents or conversations as their parents
Summer 2003 - Modify and Add more comments suitable for JavaDoc.
Fall 2003 - Add receiveMulticast, receiveBroadcast, receiveSecureUnicast receiveSecureMulticast method.

Since:
agentMom 1.0
See Also:
MomObject, MessageHandler, MulticastHandler, BroadcastHandler, SecureUnicastHandler, SecureMulticastHandler, Serialized Form

Field Summary
 Vector broadcast_queue
          Message queue for broadcast conversation.
 Vector multicast_queue
          Message queue for multicast conversation.
 Vector secure_multicast_queue
          Message queue for secured multicast conversation.
 
Fields inherited from class ksu.cis.mom.MomObject
broadcast_address, broadcast_port, group, multicast_port, name, parent, port, secure_multicast_port, secure_unicast_port
 
Constructor Summary
protected Agent()
          Default constructor.
  Agent(String name, int port)
          Constructor for using only unicast conversation.
  Agent(String name, int unicast_port, int[] multicast_port, int broadcast_port, int secure_unicast_port, int[] secure_multicast_port)
          Constructor for using any or all of five different conversations.
 
Method Summary
 void receiveBroadcastConversation(DatagramSocket bSocket, Message m, Vector broadcast_queue)
          Receive message method for the broadcast conversation.
abstract  void receiveMessage(Socket server, ObjectInputStream input, ObjectOutputStream output)
          Receive message method for the unicast conversation.
 void receiveMulticastConversation(MulticastSocket mSocket, Message m, Vector multicast_queue)
          Receive message method for the multicast conversation.
 void receiveMulticastJoin(Message m)
          Receive multicast join message method for the multicast conversation.
 void receiveMulticastLeave(Message m)
          Receive multicast leave message method for the multicast conversation.
 void receiveSecureMulticastConversation(MulticastSocket mSocket, Message m, Vector multicast_queue, Key k, String algorithm)
          Receive message method for the secured multicast conversation.
 void receiveSecureUnicastConversation(SSLSocket server, ObjectInputStream input, ObjectOutputStream output)
          Receive message method for the secured unicast conversation.
abstract  void run()
          An agent must be runnable as a separate thread, and each agent must implement this method.
 void sendInternal(Message m)
          Method for sending message between components within an agent.
 void write(String s)
          Method for printout a String information on terminal screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

broadcast_queue

public Vector broadcast_queue
Message queue for broadcast conversation.


multicast_queue

public Vector multicast_queue
Message queue for multicast conversation.


secure_multicast_queue

public Vector secure_multicast_queue
Message queue for secured multicast conversation.

Constructor Detail

Agent

protected Agent()
Default constructor. This is an empty constructor and does not require any argument.


Agent

public Agent(String name,
             int port)
Constructor for using only unicast conversation. It takes two argument, String of agent name and integer of unicast port.

Parameters:
name - - String name of the agent
port - - Integer port of unicast

Agent

public Agent(String name,
             int unicast_port,
             int[] multicast_port,
             int broadcast_port,
             int secure_unicast_port,
             int[] secure_multicast_port)

Constructor for using any or all of five different conversations. It takes six argument, String of agent name, integer of port used in each conversation. If any port is assigned to be less than one, then it indicates the conversation is not going to be used.
Note that the arguments multicast_port and secure_multicast_port are an array of integer type. It is because we allows agent to subscribe to multiple groups. Thus, one port is used for one group. Assigning the first element less than one indicates that the multicast will not be used.

Parameters:
name - - String name of the agent
unicast_port - - Integer port number used for unicast conversation
multicast_port - - Array of integer port number used for multicast conversation
broadcast_port - - Integer port number used for broadcast conversation
secure_unicast_port - - Integer port number used for secured unicast conversation
secure_multicast_port - - Array of integer port number used for secured multicast conversation
Method Detail

receiveMessage

public abstract void receiveMessage(Socket server,
                                    ObjectInputStream input,
                                    ObjectOutputStream output)

Receive message method for the unicast conversation. Agent must implement this method and defines all possible of unicast conversations here.
This method will be called by the MessageHandler when the agent has received connection starting a new conversation.

Parameters:
server - - Socket for the unicast conversation
input - - ObjectInputStream for the unicast conversation
output - - ObjectOutputStream for the unicast conversation

receiveBroadcastConversation

public void receiveBroadcastConversation(DatagramSocket bSocket,
                                         Message m,
                                         Vector broadcast_queue)

Receive message method for the broadcast conversation. Agent must override this method and defines all possible of secured multicast conversations here.
This is the method that will be called by the BroadcastHandler when the agent has received connection starting a new broadcast conversation.

Parameters:
bSocket - - datagram socket for handling broadcast conversation
m - - message from other agents
broadcast_queue - - message queue for broadcast conversation

receiveMulticastConversation

public void receiveMulticastConversation(MulticastSocket mSocket,
                                         Message m,
                                         Vector multicast_queue)

Receive message method for the multicast conversation. Agent must override this method and defines all possible of multicast conversations here.
This is the method that will be called by the MulticastHandler when the agent has received connection starting a new multicast conversation.

Parameters:
mSocket - - multicast socket for handling multicast conversation
m - - Message from other agents
multicast_queue - - message queue for multicast conversation

receiveMulticastJoin

public void receiveMulticastJoin(Message m)

Receive multicast join message method for the multicast conversation. Agent can override this method and performs some tasks. For example, agent can keep track of other agents who join the group after itself.
This is the method that will be called by the MulticastHandler when the agent has received join message from other agents.


receiveMulticastLeave

public void receiveMulticastLeave(Message m)

Receive multicast leave message method for the multicast conversation. Agent can override this method and performs some tasks. For example, agent can keep track of other agents who leave.
This is the method that will be called by the MulticastHandler when the agent has received leave message from other agents.


receiveSecureMulticastConversation

public void receiveSecureMulticastConversation(MulticastSocket mSocket,
                                               Message m,
                                               Vector multicast_queue,
                                               Key k,
                                               String algorithm)

Receive message method for the secured multicast conversation. Agent must override this method and defines all possible of secured multicast conversations here.
This is the method that will be called by the SecureMulticastHandler when the agent has received connection starting a new secured multicast conversation.

Parameters:
mSocket - - secured multicast socket for handling secured multicast conversation
m - - message from other agents
multicast_queue - - message queue for secured multicast conversation
k - - symmetric private key.
algorithm - - symmetric key algorithm name

receiveSecureUnicastConversation

public void receiveSecureUnicastConversation(SSLSocket server,
                                             ObjectInputStream input,
                                             ObjectOutputStream output)

Receive message method for the secured unicast conversation. Agent must override this method and defines all possible of secured unicast conversations here.
This is the method that will be called by the SecureUnicastHandler when the agent has received connection starting a new secured unicast conversation.

Parameters:
server - - Secured socket for the secured unicast conversation
input - - ObjectInputStream for the secured unicast conversation
output - - ObjectOutputStream for the secured unicast conversation

run

public abstract void run()

An agent must be runnable as a separate thread, and each agent must implement this method.

Specified by:
run in interface Runnable

sendInternal

public void sendInternal(Message m)

Method for sending message between components within an agent. This method simply broadcast message to all active components of the agent.

Specified by:
sendInternal in class MomObject
Parameters:
m - - message for internal conversation among the component.

write

public void write(String s)

Method for printout a String information on terminal screen.

Parameters:
s - String to print out on the terminal screen.