|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.lang.Thread
ksu.cis.mom.AgentConversation
ksu.cis.mom.BroadcastConversation
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.
| 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 |
public static final int START_CONVERSATION
public static final int CONTENT
protected DatagramSocket dSocket
protected Vector broadcast_queue
protected String conversation_name
| Constructor Detail |
public BroadcastConversation(MomObject c)
c - - Reference to parent MomObject class.
public BroadcastConversation(MomObject c,
InetAddress broadcast_address,
int port,
Vector broadcast_queue)
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.
public BroadcastConversation(MomObject c,
InetAddress broadcast_address,
int port,
Vector broadcast_queue,
Message m)
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 |
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.
m - - message to sendreplywith - - name of the originating conversation.inreplyto - - name of the destined conversation on the other sides of
agent.
IOException
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.
m - - message to sendreplywith - - name of the originating conversation.inreplyto - - name of the destined conversation on the other sides of
agent.
IOExceptionpublic 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.
conversation_name - - name of conversation to retrive message
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".
conversation_name - - name of conversation to retrive message
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.
Runnable.run()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||