edu.UCL.xmiddle.controller
Class UDPAcknowledger

java.lang.Object
  |
  +--edu.UCL.xmiddle.framework.controller.Acknowledger
        |
        +--edu.UCL.xmiddle.controller.UDPAcknowledger

public class UDPAcknowledger
extends Acknowledger

UDPAcknowledger sends a specific DatagramPacket through a given DatagramSocket, waiting for that packet to be acknowledged. Upon initialisation, the UDPAcknowledger must know which packet to send, where to send it from and which is the Acknowledgement string that it must receive to decide that the packet has been acknowledged. It will then send the packet for a specified maximum number of times, waiting in between each time for a specified number of miliseconds, up until the packet is acknowledged, or the maximum number of times/tries has been exceeded. Note that the UDPAcknowledger does not receive data through the DatagramSocket. In order to verify that the packet has been acknowledged, it expects the module that did receive the acknowledgement (in this case, probably UDPNetwork to forward the acknowledgement, using match

See Also:
Acknowledger

Field Summary
 
Fields inherited from class edu.UCL.xmiddle.framework.controller.Acknowledger
maxtimes, timeout
 
Constructor Summary
UDPAcknowledger(long timeout, int maxtries, java.net.DatagramSocket connection, java.lang.String data, java.net.DatagramPacket packet)
          Creates a new UDPAcknowledger instance.
 
Method Summary
 void abort()
          Aborts the execution of the acknowledger.
 boolean match(java.lang.Object id)
          This method is called by the module that actually receives an acknowledgement
 boolean verify()
          Sends the packet to the remote host.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPAcknowledger

public UDPAcknowledger(long timeout,
                       int maxtries,
                       java.net.DatagramSocket connection,
                       java.lang.String data,
                       java.net.DatagramPacket packet)
Creates a new UDPAcknowledger instance.

Parameters:
timeout - The time to wait before re-trying
maxtries - The maximum number of times the message is going to be sent
connection - The connection though which the message is going rto be sent
data - The data that must be received to realise that the packet has been received by the target host
packet - the DatagramPacket to be sent
Method Detail

verify

public boolean verify()
Sends the packet to the remote host.

Specified by:
verify in class Acknowledger
Returns:
True if the packet has been acknowledged, or false if abort() was valled or the maximum number of retries has been exceeded and no acknowledgement has come in

match

public boolean match(java.lang.Object id)
This method is called by the module that actually receives an acknowledgement

Specified by:
match in class Acknowledger
Parameters:
id - The acknowledgement received
Returns:
true if the acknowledgement is the one that was expected or false otherwise

abort

public void abort()
Aborts the execution of the acknowledger.

Specified by:
abort in class Acknowledger