Added a delay for reading packets from the packet buffer so packets that are recieved out of order have time to order by timestamp in the priority queue #story[820]

This commit is contained in:
Peter Galloway
2017-04-29 18:56:41 +12:00
parent 02a35b4c02
commit 1e1e482b79
4 changed files with 29 additions and 31 deletions
@@ -4,8 +4,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.zip.CRC32;
@@ -15,8 +13,8 @@ import java.util.zip.Checksum;
public class StreamReceiver extends Thread {
private InputStream stream;
private Socket host;
private ByteArrayOutputStream crcBuffer;
private Thread t;
private ByteArrayOutputStream crcBuffer;
private Thread thread;
private String threadName;
public static PriorityBlockingQueue<StreamPacket> packetBuffer;
@@ -31,21 +29,20 @@ public class StreamReceiver extends Thread {
}
public void run(){
PriorityBlockingQueue<StreamPacket> pq = new PriorityBlockingQueue<>(256, new Comparator<StreamPacket>() {
packetBuffer = new PriorityBlockingQueue<>(256, new Comparator<StreamPacket>() {
@Override
public int compare(StreamPacket s1, StreamPacket s2) {
return (int) (s1.getTimeStamp() - s2.getTimeStamp());
}
});
packetBuffer = pq;
connect();
}
public void start () {
System.out.println("Starting " + threadName );
if (t == null) {
t = new Thread (this, threadName);
t.start ();
if (thread == null) {
thread = new Thread (this, threadName);
thread.start ();
}
}
@@ -141,15 +138,4 @@ public class StreamReceiver extends Thread {
}
return partialLong;
}
public static void main(String[] args) {
StreamReceiver sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1");
//StreamReceiver sr = new StreamReceiver("livedata.americascup.com", 4941, pq);
sr.start();
}
}