info.jedi.net
Class ReliableHandler

java.lang.Object
  |
  +--info.jedi.net.DefaultPacketHandler
        |
        +--info.jedi.net.ReliableHandler

public class ReliableHandler
extends DefaultPacketHandler
implements java.lang.Runnable

This class adds reliability to JEDI packets. It provides methods for handling incoming reliability packets and for adding reliability to outgoing packets. It includes a background thread for resending packets that are never acknowledged. Every packet that is sent out will be acknowledged when it is received. The sender will resend a packet until it is acknowledged, so if a receiver gets multiple sent packets it should assume that its first acknowledgement was lost and send another.

See Also:
MailDaemon, RMCHandler, CommunicationPort, LocationID

Field Summary
static int DEFAULT_TIMEOUT
          The default timeout in milliseconds is 60000 (60 seconds)
static byte RELIABLE_HANDLER_NUMBER
          The index of the ReliableHandler in the MailDaemon dispatch table
static int RESEND_INTERVAL
          How many milliseconds between resending packets
 
Method Summary
protected  void acknowledge(InputPacket packet)
          Sends an acknowledgement packet for the receipt of this InputPacket
protected  CommunicationPort getPort(Packet packet)
          Gets the CommunicationPort associated with the address and port of the Packet, creating one if necessary
 boolean handlePacket(InputPacket packet)
          handles an incoming reliable packet.
 void initializePacket(OutputPacket packet)
          Adds reliability to an outgoing packet.
 void run()
          This is the background thread that resends messages that have not yet been acknowledged
 boolean sendPacket(OutputPacket packet)
          Does the work necessary just before a reliable OutputPacket is sent.
 
Methods inherited from class info.jedi.net.DefaultPacketHandler
handleError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RELIABLE_HANDLER_NUMBER

public static final byte RELIABLE_HANDLER_NUMBER
The index of the ReliableHandler in the MailDaemon dispatch table

RESEND_INTERVAL

public static final int RESEND_INTERVAL
How many milliseconds between resending packets

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
The default timeout in milliseconds is 60000 (60 seconds)
Method Detail

initializePacket

public void initializePacket(OutputPacket packet)
                      throws java.io.IOException
Adds reliability to an outgoing packet. The packet will be resent periodically until it is acknowledged by the receiver
Overrides:
initializePacket in class DefaultPacketHandler
Tags copied from class: DefaultPacketHandler
Throws:
java.io.IOException - may be thrown by subclasses

sendPacket

public boolean sendPacket(OutputPacket packet)
                   throws java.io.IOException
Does the work necessary just before a reliable OutputPacket is sent. It adds it to the sending list so that it will be resent if no acknowledgement returns
Overrides:
sendPacket in class DefaultPacketHandler
Tags copied from class: DefaultPacketHandler
Throws:
java.io.IOException - may be thrown by subclasses

handlePacket

public boolean handlePacket(InputPacket packet)
                     throws java.io.IOException
handles an incoming reliable packet. If this packet has been recevied, it is acknowledged then ignored. If not, it is acknowledged and passed on to the next appropriate handler. Finally, if this is an acknowlegement, the original reliable message is removed from the list of messages to resend (because we know it has been received)
Overrides:
handlePacket in class DefaultPacketHandler
Tags copied from class: DefaultPacketHandler
Returns:
true, meaning that processing of this packet is complete
Throws:
java.io.IOException - may be thrown by subclasses

getPort

protected CommunicationPort getPort(Packet packet)
Gets the CommunicationPort associated with the address and port of the Packet, creating one if necessary

acknowledge

protected void acknowledge(InputPacket packet)
                    throws java.io.IOException
Sends an acknowledgement packet for the receipt of this InputPacket

run

public void run()
This is the background thread that resends messages that have not yet been acknowledged
Specified by:
run in interface java.lang.Runnable