Flush match table on a scheduled rate.
#story[1196]
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user