ksu.cis.mom
Class BroadcastConversation

java.lang.Object
  extended byjava.lang.Thread
      extended byksu.cis.mom.AgentConversation
          extended byksu.cis.mom.BroadcastConversation
All Implemented Interfaces:
Runnable

public abstract class BroadcastConversation
extends AgentConversation

The BroadcastConversation class is an abstract class that actually carries out the broadcast message to all agent under the same local network. This class provides two main services, read broadcast message and send broadcast message. It is responsible for passing the messages back and forth using datagram socket.

There are really two types of conversation classes that can be derived from the BroadcastConversation class, one for the conversation initiator and one for the conversation respondent. The basic difference lies in which constructor is used and the details in the abstract run method, which must be implemented in the concrete class derived from the BroadcastConversation class.

History
09/12/2003: creation date
11/11/2003: Add more comments suitable for JavaDoc.
12/20/2003: Modify code to make this class extends AgentConversation class instead of Thread class.

Since:
agentMom 2.0

Field Summary
protected  Vector broadcast_queue
          Message queue for broadcast conversation.
static int CONTENT
          To indicate that the message is not a request to start conversation.
protected  String conversation_name
          Name of the broadcast conversation.
protected  DatagramSocket dSocket
          Datagram socket used to send and receive broadcast conversation.
static int START_CONVERSATION
          To indicate that the message is a request to start conversation.
 
Fields inherited from class ksu.cis.mom.AgentConversation
connectionHost, connectionPort, m, parent
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BroadcastConversation(MomObject c)
          Default Conversation constructor.
BroadcastConversation(MomObject c, InetAddress broadcast_address, int port, Vector broadcast_queue)
          Constructor for conversation initiator
BroadcastConversation(MomObject c, InetAddress broadcast_address, int port, Vector broadcast_queue, Message m)
          Constructor for conversation respondent.
 
Method Summary
 Message nonblockedReadMessage(String conversation_name, long timeout)
          Method to fetch broadcast message from broadcast message queue destined for this conversation.
 Message readMessage(String conversation_name)
          Method to fetch broadcast message from broadcast message queue destined for this conversation.
abstract  void run()
          run method for BroadcastConversation class.
 void sendMessage(Message m, String replywith, String inreplyto)
          This method is responsible for sending the Message m through the datagram socket.
 void startConversation(Message m, String replywith, String inreplyto)
          This method is responsible for sending message request a start of new conversation.
 
Methods inherited from class ksu.cis.mom.AgentConversation
write
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

START_CONVERSATION

public static final int START_CONVERSATION
To indicate that the message is a request to start conversation.

See Also:
Constant Field Values

CONTENT

public static final int CONTENT
To indicate that the message is not a request to start conversation.

See Also:
Constant Field Values

dSocket

protected DatagramSocket dSocket
Datagram socket used to send and receive broadcast conversation.


broadcast_queue

protected Vector broadcast_queue
Message queue for broadcast conversation. It is a Vector type that stores broadcast message sent to this agent.


conversation_name

protected String conversation_name
Name of the broadcast conversation. This name must be unique from others broadcast conversations within agent since it is used for identifying the destined conversation when broadcast message is received.

Constructor Detail

BroadcastConversation

public BroadcastConversation(MomObject c)
Default Conversation constructor.

Parameters:
c - - Reference to parent MomObject class.

BroadcastConversation

public BroadcastConversation(MomObject c,
                             InetAddress broadcast_address,
                             int port,
                             Vector broadcast_queue)
Constructor for conversation initiator

Parameters:
c - - reference to parent class.
broadcast_address - - IP address to send broadcast message.
port - - port for broadcast conversation.
broadcast_queue - - message queue for broadcast conversation.

BroadcastConversation

public BroadcastConversation(MomObject c,
                             InetAddress broadcast_address,
                             int port,
                             Vector broadcast_queue,
                             Message m)
Constructor for conversation respondent.

Parameters:
c - - reference to parent class.
broadcast_address - - IP address to send broadcast message.
port - - port for broadcast conversation.
broadcast_queue - - message queue for broadcast conversation.
m - - ksu.cis.mom.Message
Method Detail

sendMessage

public void sendMessage(Message m,
                        String replywith,
                        String inreplyto)
                 throws IOException

This method is responsible for sending the Message m through the datagram socket. It also automatically fill the sender, host, port, replywith and inreplyto fields in the Message object m using the parent agent’s name and port attributes and automatically gets the host name from the system.
It also converts Message type Object to byte array to be able to send through datagram socket.
Note that to send message request a start of new conversation the correct method is startConversation.

Parameters:
m - - message to send
replywith - - name of the originating conversation.
inreplyto - - name of the destined conversation on the other sides of agent.
Throws:
IOException

startConversation

public void startConversation(Message m,
                              String replywith,
                              String inreplyto)
                       throws IOException

This method is responsible for sending message request a start of new conversation. The Message m is sent through the datagram socket. It also automatically fill the sender, host, port, replywith and inreplyto fields in the Message object m using the parent agent’s name and port attributes and automatically gets the host name from the system.

It also converts Message type Object to byte array to be able to send through datagram socket.

Parameters:
m - - message to send
replywith - - name of the originating conversation.
inreplyto - - name of the destined conversation on the other sides of agent.
Throws:
IOException

readMessage

public Message readMessage(String conversation_name)

Method to fetch broadcast message from broadcast message queue destined for this conversation. This method can be considered a blocked read. This method search message destined for specified conversation name by comparing the String parameter with the inreplyto field in the message. If there is no message for specified conversation, it wait for 1000 miilisecond and try again.

Parameters:
conversation_name - - name of conversation to retrive message
Returns:
ksu.cis.mom.Message

nonblockedReadMessage

public Message nonblockedReadMessage(String conversation_name,
                                     long timeout)

Method to fetch broadcast message from broadcast message queue destined for this conversation. This method can be considered a nonblocked read. This method search message destined for specified conversation name by comparing the String parameter with the inreplyto field in the message. If there is no message for specified conversation, it wait for the amount of specified timeout in miilisecond and then try again. If there is still no message on the second try, it returns Message with content field "timeout".

Parameters:
conversation_name - - name of conversation to retrive message
Returns:
Message with content field "timeout" if there is no message destine for specified conversation.

run

public abstract void run()

run method for BroadcastConversation class. Each derived conversation must be run as separate thread and must implement this method regarding to the type of conversation, initiator or repondent conversation.

See Also:
Runnable.run()