mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
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:
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user