|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.lang.Thread
ksu.cis.mom.MulticastHandler
MulticastHandler is responsible for initializing and starting multicast socket, including joining/leaving multicast group. In generally, it handle multicast connection with other agents. It uses the MulticastSocket class to subscribe to multicast group.
When an agent is created, it needs to creates a new multicast handler thread to be able to receive a start of multicast conversation from other agents. When MulticastHandler class is created, it creates the multicast socket and join to specified multicast group. Then, it automatically sends a multicast message to the group indicating that this agent has join the group. When a MulticastHandler receives the message indicating the join, it calls the receiveMulticastJoin method in agent class. Below is how an agent can start the MessageHandler class.
MulticastHandler mh = new MessageHandler(this, this.port, 0, multicast_address); mh.start();
To create the MessageHandler, it requires four/five parameters,
port number, a reference to parent agent object, time to live of multicast
packet, multicast address and/or maximum datagram received packet size.
Note that the multicast address is actually a class D IP addresses that
are in the range 224.0.0.0 to 239.255.255.255.
When this class is started, the multicast handler starts a multicast socket
on the indicated port and waits for messages from other agents.
When multicast handler receives a message, it will check whether the message
is a start of new conversation/join/leave/conversation message. If it is a
start of conversation, the MulticastHandler simply calls the parent agent's
receiveMulticastcastConversation method with the multicast socket, received
message and multicast message queue.
The agent then verify the received message and start an appropriate
conversation. If the received message is for any multicast conversation
class, it adds the message to the multicast message queue. Then the
multicast conversation class can get the message from this queue later.
Note that the multicast communication has loopback effect(message also send to itself), but the MulticastHandler will ignore this message.
History:
06/12/2003 - creation date
| Field Summary | |
static int |
CONTENT
To indicate that the message is not a request to start conversation. |
protected InetAddress |
group
multicast group address |
static int |
JOIN
Identifies a JOIN multicast PDU |
protected boolean |
leave
Flag control receive thread execution |
static int |
LEAVE
Identifies a LEAVE multicast PDU |
int |
maxSize
Default maximum size of received multicast packet. |
MulticastSocket |
mSocket
Multicast socket used to send and receive multicast message |
int |
multicast_port
Multicast port |
Vector |
multicast_queue
Message queue for multicast conversation. |
Agent |
parent
Reference to parent agent class. |
static int |
START_CONVERSATION
To indicate that the message is a request to start conversation. |
int |
TimeToLive
Time-to-live for multicast packets sent out on this MulticastSocket in order to control the scope of the multicasts. |
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
MulticastHandler(Agent p,
int port,
int ttl,
InetAddress group)
Default constructor for MulticastHandler. |
|
MulticastHandler(Agent p,
int port,
int ttl,
InetAddress group,
int packetSize)
Default constructor for MulticastHandler. |
|
| Method Summary | |
void |
checkLeave()
To check the value of leave attribute. |
void |
queueMessage(Message m)
Method for adding new message to the queue. |
void |
run()
Run thread method for MulticastHandler.It simply waits for incoming multicast message from other agents. |
void |
sendJoin()
Sends a multicast JOIN message to notify other agents. |
void |
sendLeave()
Sends a multicast LEAVE message to notify other agents. |
void |
setLeave(boolean leave)
Set value for leave. |
void |
write(String s)
Method for easily printout information on screen. |
| 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 int maxSize
public static final int START_CONVERSATION
public static final int CONTENT
public static final int JOIN
public static final int LEAVE
public Agent parent
public int TimeToLive
public MulticastSocket mSocket
public int multicast_port
public Vector multicast_queue
protected InetAddress group
protected boolean leave
| Constructor Detail |
public MulticastHandler(Agent p,
int port,
int ttl,
InetAddress group)
p - - reference to parent agent class.port - - port number for listening for multicast message.ttl - - time to live of datagram packet.group - - multicast address, in the range 224.0.0.0-239.255.255.255
public MulticastHandler(Agent p,
int port,
int ttl,
InetAddress group,
int packetSize)
Note that the received packet size must be greater than or equal to the sent packet. Otherwise, packet will be partially received.
p - reference to parent agent class.port - - port number for listening for broadcast message.ttl - - time to live of datagram packet.group - - multicast address, in the range 224.0.0.0-239.255.255.255packetSize - - user defined maximum size in byte of received
multicast packet.| Method Detail |
public void sendJoin()
throws IOException
Sends a multicast JOIN message to notify other agents. We need to convert Message object to Byte type to be able to send it using multicast socket.
IOException
public void sendLeave()
throws IOException
Sends a multicast LEAVE message to notify other agents. We need to convert Message object to Byte type to be able to send it using multicast socket.
IOExceptionpublic void run()
Note that this is a blocking read message.
public void write(String s)
s - java.lang.Stringpublic void queueMessage(Message m)
m - - message to be retrived by multicast conversation.public void setLeave(boolean leave)
leave - - if value is true, it will make the handler thread to
stop the next time this value is checked in the run method.public void checkLeave()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||