Track datagrams received out of order and missed datagrams.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6047 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2010-03-18 20:36:25 +00:00
parent 5ecfff4bcb
commit bd6a35677a
3 changed files with 23 additions and 6 deletions
@@ -470,7 +470,7 @@ public class BlockingCommunicator extends Communicator
if (debugLogMessages()) {
log.info("RECEIVE " + msg);
}
_client.getMessageTracker().messageReceived(false, size, msg);
_client.getMessageTracker().messageReceived(false, size, msg, 0);
return msg;
} catch (ClassNotFoundException cnfe) {
@@ -496,15 +496,16 @@ public class BlockingCommunicator extends Communicator
// decode through the sequencer
try {
DownstreamMessage msg = (DownstreamMessage)_sequencer.readDatagram();
if (_client != null) {
_client.getMessageTracker().messageReceived(
true, size, msg, (msg == null) ? 0 : _sequencer.getMissedCount());
}
if (msg == null) {
return null; // received out of order
}
if (debugLogMessages()) {
log.info("DATAGRAM " + msg);
}
if (_client != null) {
_client.getMessageTracker().messageReceived(true, size, msg);
}
return msg;
} catch (ClassNotFoundException cnfe) {
@@ -36,7 +36,8 @@ public interface MessageTracker
public static final MessageTracker NOOP = new MessageTracker() {
public void messageSent (boolean datagram, int size, UpstreamMessage msg) {
}
public void messageReceived (boolean datagram, int size, DownstreamMessage msg) {
public void messageReceived (
boolean datagram, int size, DownstreamMessage msg, int missed) {
}
};
@@ -47,6 +48,9 @@ public interface MessageTracker
/**
* Notes that a message has been received.
*
* @param msg the received message, or <code>null</code> if received out of order.
* @param missed the number of messages missed between this message and the one before it.
*/
public void messageReceived (boolean datagram, int size, DownstreamMessage msg);
public void messageReceived (boolean datagram, int size, DownstreamMessage msg, int missed);
}
@@ -102,6 +102,7 @@ public class DatagramSequencer
if (number <= _lastReceived) {
return null;
}
_missedCount = number - _lastReceived - 1;
_lastReceived = number;
// read the acknowledge number and process all send records up to that one
@@ -132,6 +133,14 @@ public class DatagramSequencer
return datagram;
}
/**
* Returns the number of datagrams missed between the last and the one before it.
*/
public int getMissedCount ()
{
return _missedCount;
}
/**
* A record of a sent datagram.
*/
@@ -168,6 +177,9 @@ public class DatagramSequencer
/** The most recent sequence number received. */
protected int _lastReceived;
/** The number of datagrams missed between the last and the one before it. */
protected int _missedCount;
/** Records of datagrams sent. */
protected ArrayList<SendRecord> _sendrecs = Lists.newArrayList();
}