Fixed most of issue #19 with new master?
This commit is contained in:
@@ -37,6 +37,8 @@ public class ConnectionAcceptor implements Runnable {
|
||||
*/
|
||||
private ServerSocket serverSocket;
|
||||
|
||||
private Socket mockSocket = null;
|
||||
|
||||
|
||||
/**
|
||||
* List of client connections.
|
||||
@@ -114,7 +116,7 @@ public class ConnectionAcceptor implements Runnable {
|
||||
* Run the Acceptor
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
public void run(){
|
||||
|
||||
while(clientConnections.remainingCapacity() > 0) {
|
||||
|
||||
@@ -124,7 +126,9 @@ public class ConnectionAcceptor implements Runnable {
|
||||
break;
|
||||
}
|
||||
|
||||
Socket mockSocket = serverSocket.accept();
|
||||
try {
|
||||
this.mockSocket = serverSocket.accept();
|
||||
} catch (Exception e){}
|
||||
|
||||
Logger.getGlobal().log(Level.INFO, String.format("Client connected. client ip/port = %s. Local ip/port = %s.", mockSocket.getRemoteSocketAddress(), mockSocket.getLocalSocketAddress()));
|
||||
|
||||
|
||||
@@ -157,9 +157,9 @@ public class Event {
|
||||
}
|
||||
|
||||
public void endEvent() throws IOException {
|
||||
this.connectionThread.interrupt();
|
||||
this.connectionAcceptor.closeConnection();
|
||||
this.raceThread.interrupt();
|
||||
this.connectionThread.interrupt();
|
||||
this.connectionAcceptor.closeConnection();
|
||||
this.raceThread.interrupt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -103,6 +103,8 @@ public class MockOutput implements RunnableWithFramePeriod {
|
||||
Logger.getGlobal().log(Level.WARNING, "MockOutput.run() interrupted while putting message in queue.", e);
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class HeartBeatService implements RunnableWithFramePeriod {
|
||||
* Puts a HeartBeat message on the message queue.
|
||||
* @throws InterruptedException Thrown if the thread is interrupted.
|
||||
*/
|
||||
private void sendHeartBeat() throws InterruptedException {
|
||||
private void sendHeartBeat() throws Exception {
|
||||
|
||||
HeartBeat heartBeat = createHeartbeatMessage();
|
||||
|
||||
@@ -92,13 +92,17 @@ public class HeartBeatService implements RunnableWithFramePeriod {
|
||||
|
||||
while (!Thread.interrupted()) {
|
||||
long currentFrameTime = System.currentTimeMillis();
|
||||
waitForFramePeriod(lastHeartbeatTime, currentFrameTime, heartbeatPeriod);
|
||||
try {
|
||||
waitForFramePeriod(lastHeartbeatTime, currentFrameTime, heartbeatPeriod);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
lastHeartbeatTime = currentFrameTime;
|
||||
|
||||
try {
|
||||
sendHeartBeat();
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
} catch (Exception e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "HeartBeatService: " + this + " sendHeartBeat() was interrupted on thread: " + Thread.currentThread(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
|
||||
@@ -43,9 +43,17 @@ public class RaceLogic implements RunnableWithFramePeriod {
|
||||
public void run() {
|
||||
race.initialiseBoats();
|
||||
|
||||
countdown();
|
||||
try {
|
||||
countdown();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
raceLoop();
|
||||
try {
|
||||
raceLoop();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void boolFalse(){
|
||||
@@ -56,7 +64,7 @@ public class RaceLogic implements RunnableWithFramePeriod {
|
||||
/**
|
||||
* Countdown timer until race starts.
|
||||
*/
|
||||
private void countdown() {
|
||||
private void countdown() throws Exception {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
|
||||
@@ -95,7 +103,7 @@ public class RaceLogic implements RunnableWithFramePeriod {
|
||||
/**
|
||||
* Timer that runs for the duration of the race, until all boats finish.
|
||||
*/
|
||||
private void raceLoop() {
|
||||
private void raceLoop() throws Exception {
|
||||
|
||||
long previousFrameTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user