Flush match table on a scheduled rate.

#story[1196]
main
Connor Taylor-Brown 8 years ago
parent 2f8daf757a
commit 42ac733d72

@ -47,6 +47,7 @@ public class NetworkInterface {
this.serverSocket = new DatagramSocket(3779);
startBroadcast(10000);
scheduleFlush(300000);
this.run();
} catch (IOException e) {
System.err.println("Error listening on port: " + this.serverSocket.getLocalPort() + ".");
@ -55,6 +56,10 @@ public class NetworkInterface {
}
/**
* Broadcasts match table to clients at a requested interval
* @param period interval to broadcast table
*/
private void startBroadcast(int period) {
scheduler.scheduleAtFixedRate(new TimerTask() {
@Override
@ -79,6 +84,19 @@ public class NetworkInterface {
}, period, period);
}
/**
* Flushes the match table at a requested interval
* @param period interval to flush table
*/
private void scheduleFlush(int period) {
scheduler.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
matchTable.getMatchTable().clear();
}
}, period, period);
}
private void run() throws IOException{
while(true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

Loading…
Cancel
Save