Issue 19 changes.
This commit is contained in:
@@ -101,6 +101,13 @@ public class ConnectionAcceptor implements Runnable {
|
||||
return serverPort;
|
||||
}
|
||||
|
||||
public void closeConnection() throws IOException {
|
||||
this.raceLogic.boolFalse();
|
||||
if(!this.serverSocket.isClosed()){
|
||||
this.serverSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -113,6 +120,9 @@ public class ConnectionAcceptor implements Runnable {
|
||||
|
||||
try {
|
||||
|
||||
if(Thread.currentThread().isInterrupted()){
|
||||
break;
|
||||
}
|
||||
|
||||
Socket mockSocket = serverSocket.accept();
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ public class Event {
|
||||
*/
|
||||
private SourceIdAllocator sourceIdAllocator;
|
||||
|
||||
private Thread raceThread;
|
||||
|
||||
private Thread connectionThread;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,7 +134,8 @@ public class Event {
|
||||
this.latestMessages,
|
||||
this.compositeCommand);
|
||||
|
||||
new Thread(newRace, "Event.Start()->RaceLogic thread").start();
|
||||
this.raceThread = new Thread(newRace, "Event.Start()->RaceLogic thread");
|
||||
raceThread.start();
|
||||
|
||||
|
||||
//Create connection acceptor.
|
||||
@@ -143,13 +148,20 @@ public class Event {
|
||||
}
|
||||
|
||||
|
||||
new Thread(connectionAcceptor, "Event.Start()->ConnectionAcceptor thread").start();
|
||||
this.connectionThread = new Thread(connectionAcceptor, "Event.Start()->ConnectionAcceptor thread");
|
||||
connectionThread.start();
|
||||
|
||||
sendXMLs();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void endEvent() throws IOException {
|
||||
this.connectionThread.interrupt();
|
||||
this.connectionAcceptor.closeConnection();
|
||||
this.raceThread.interrupt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,8 @@ public class RaceLogic implements RunnableWithFramePeriod {
|
||||
|
||||
private CompositeCommand commands;
|
||||
|
||||
private boolean loopBool = true;
|
||||
|
||||
/**
|
||||
* Initialises race loop with state and server message queue
|
||||
* @param race state of race to modify
|
||||
@@ -46,6 +48,10 @@ public class RaceLogic implements RunnableWithFramePeriod {
|
||||
raceLoop();
|
||||
}
|
||||
|
||||
public void boolFalse(){
|
||||
loopBool = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Countdown timer until race starts.
|
||||
@@ -54,7 +60,7 @@ public class RaceLogic implements RunnableWithFramePeriod {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
|
||||
while (race.getRaceStatusEnum() != RaceStatusEnum.STARTED) {
|
||||
while (race.getRaceStatusEnum() != RaceStatusEnum.STARTED && loopBool) {
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
@@ -93,7 +99,7 @@ public class RaceLogic implements RunnableWithFramePeriod {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
|
||||
while (race.getRaceStatusEnum() != RaceStatusEnum.FINISHED) {
|
||||
while (race.getRaceStatusEnum() != RaceStatusEnum.FINISHED && loopBool) {
|
||||
|
||||
//Get the current time.
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user