org.planx.xmlstore.routing.messaging
Class MessageServer

java.lang.Object
  extended by org.planx.xmlstore.routing.messaging.MessageServer

public class MessageServer
extends Object

Listens for incoming UDP messages and provides a framework for sending messages and responding to received messages. Two threads are started: One that listens for incoming messages and one that handles timeout events.


Constructor Summary
MessageServer(int udpPort, MessageFactory factory, long timeout)
          Constructs a MessageServer listening on the specified UDP port using the specified MessageFactory for interpreting incoming messages.
 
Method Summary
 void close()
          Signals to the MessageServer thread that it should stop running.
 void reply(int comm, Message message, InetAddress ip, int port)
          Sends a reply to the message with the specified communication id.
 int send(Message message, InetAddress ip, int port, Receiver recv)
          Sends the specified Message and calls the specified Receiver when a reply for the message is received.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageServer

public MessageServer(int udpPort,
                     MessageFactory factory,
                     long timeout)
              throws SocketException
Constructs a MessageServer listening on the specified UDP port using the specified MessageFactory for interpreting incoming messages.

Parameters:
udpPort - The UDP port on which to listen for incoming messages
factory - Factory for creating Message and Receiver objects
timeout - The timeout period in milliseconds
Throws:
SocketException - if the socket could not be opened, or the socket could not bind to the specified local port
Method Detail

send

public int send(Message message,
                InetAddress ip,
                int port,
                Receiver recv)
         throws IOException
Sends the specified Message and calls the specified Receiver when a reply for the message is received. If recv is null any reply is ignored. Returns a unique communication id which can be used to identify a reply.

Throws:
IOException

reply

public void reply(int comm,
                  Message message,
                  InetAddress ip,
                  int port)
           throws IOException
Sends a reply to the message with the specified communication id.

Throws:
IOException

close

public void close()
Signals to the MessageServer thread that it should stop running.



Copyright © 2010. All Rights Reserved.