edu.UCL.xmiddle.controller
Class UDPLocator

java.lang.Object
  |
  +--edu.UCL.xmiddle.framework.controller.Locator
        |
        +--edu.UCL.xmiddle.controller.UDPLocator
All Implemented Interfaces:
java.lang.Runnable

public class UDPLocator
extends Locator

The UDPLocator is responsible for "showing" to other hosts that we are online and realising which other hosts are currently in reach. It does this, by multicasting an online message (which includes information such as the primaryID, the secondary ID, the ip address, the linktable (linkedFrom and exports tables) etc, and by receiving similar messages multicasted by the other hosts that are in reach. A host is deemed to be offline, if a specified amount of time has passed since the last time the Locator received its online message. UDPLocator contains three inner classes/threads: OnlineMessage that multicasts to other hosts that we are on line, OfflineTimer that realises when a host is off line and MessageQueueParser that parses all messages received by the Locator. UDPLocator is also responsible for passing HostListener events to the localhost.

See Also:
Locator

Field Summary
 
Fields inherited from class edu.UCL.xmiddle.framework.controller.Locator
caller, inReach, localhost
 
Constructor Summary
UDPLocator(LocalHost localhost, java.net.MulticastSocket connection, int port, java.lang.String groupAddress, int PORT, int segmentSize)
          Creates a new UDPLocator instance.
 
Method Summary
 void exit()
          Signifies that the platform is about to exit, and exits all threads
 Host getHost(java.lang.Object primaryID)
          Returns the Host representation for the given primary ID, if the host is currently in reach.
 Host getHostByAddress(java.lang.String address)
          Returns a host representation (if the host is in reach) by its IP address
 boolean isInReach(java.lang.Object primaryID)
          Shows if the given host is in reach at the moment
 void pause()
          Signifies that the Locator and its threads should stop processing/sending/receiving
 void run()
          Receives packets from the network.
 void setConnection(java.net.MulticastSocket socket)
          Describe setConnection method here.
 void setPort(int port)
          Changes the private listening port
 void start()
          Signifies that the Locator and its threads should start processing/sending/receiving
 
Methods inherited from class edu.UCL.xmiddle.framework.controller.Locator
getHosts, setLocalHost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPLocator

public UDPLocator(LocalHost localhost,
                  java.net.MulticastSocket connection,
                  int port,
                  java.lang.String groupAddress,
                  int PORT,
                  int segmentSize)
Creates a new UDPLocator instance.

Parameters:
localhost - a reference to the LocalHost, so that we can have access to the LinkTable
connection - The MulticastSocket that provides the connection to the network
port - The port (UDP) at which the host is listening for requests
groupAddress - The multicast group's ip address
PORT - The multicast group's port
segmentSize - The maximum segment size that this host can accept
Method Detail

setPort

public void setPort(int port)
Changes the private listening port

Parameters:
port - an int value

isInReach

public boolean isInReach(java.lang.Object primaryID)
Shows if the given host is in reach at the moment

Specified by:
isInReach in class Locator
Parameters:
primaryID - The primary ID of the host which we need to find out if it is in reach.
Returns:
TRUE if the host is in reach or FALSE otherwise

getHost

public Host getHost(java.lang.Object primaryID)
Returns the Host representation for the given primary ID, if the host is currently in reach.

Specified by:
getHost in class Locator
Parameters:
primaryID - The primaryID of the host
Returns:
a Host value

exit

public void exit()
Signifies that the platform is about to exit, and exits all threads

Specified by:
exit in class Locator

pause

public void pause()
Signifies that the Locator and its threads should stop processing/sending/receiving

Specified by:
pause in class Locator

start

public void start()
Signifies that the Locator and its threads should start processing/sending/receiving

Specified by:
start in class Locator

getHostByAddress

public Host getHostByAddress(java.lang.String address)
Returns a host representation (if the host is in reach) by its IP address

Parameters:
address - The ip address of the host
Returns:
a Host value

run

public void run()
Receives packets from the network.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class Locator

setConnection

public void setConnection(java.net.MulticastSocket socket)
Describe setConnection method here.

Parameters:
socket - a MulticastSocket value