|
|
|
@ -51,10 +51,10 @@ public class ConnectionAcceptor implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public ConnectionAcceptor(LatestMessages latestMessages) throws IOException {
|
|
|
|
public ConnectionAcceptor(LatestMessages latestMessages) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
this.latestMessages =latestMessages;
|
|
|
|
this.latestMessages = latestMessages;
|
|
|
|
this.serverSocket = new ServerSocket(serverPort);
|
|
|
|
this.serverSocket = new ServerSocket(serverPort);
|
|
|
|
CheckClientConnection checkClientConnection = new CheckClientConnection(mockOutputList);
|
|
|
|
CheckClientConnection checkClientConnection = new CheckClientConnection(mockOutputList);
|
|
|
|
new Thread(checkClientConnection).start();
|
|
|
|
new Thread(checkClientConnection, "ConnectionAcceptor()->CheckClientConnection thread").start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getAddress() throws UnknownHostException {
|
|
|
|
public String getAddress() throws UnknownHostException {
|
|
|
|
@ -70,19 +70,30 @@ public class ConnectionAcceptor implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
while(true){//should be connections not filled up
|
|
|
|
|
|
|
|
|
|
|
|
while(mockOutputList.remainingCapacity() > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Waiting for a connection...");//TEMP DEBUG REMOVE
|
|
|
|
System.out.println("Waiting for a connection...");//TEMP DEBUG REMOVE
|
|
|
|
|
|
|
|
|
|
|
|
Socket mockSocket = serverSocket.accept();
|
|
|
|
Socket mockSocket = serverSocket.accept();
|
|
|
|
|
|
|
|
//TODO at this point we need to assign the connection a boat source ID, if they requested to participate.
|
|
|
|
|
|
|
|
|
|
|
|
DataOutputStream outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
|
|
|
DataOutputStream outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
|
|
|
MockOutput mockOutput = new MockOutput(latestMessages, outToVisualiser);
|
|
|
|
MockOutput mockOutput = new MockOutput(latestMessages, outToVisualiser);
|
|
|
|
ControllerServer controllerServer = new ControllerServer(mockSocket);
|
|
|
|
ControllerServer controllerServer = new ControllerServer(mockSocket); //TODO probably pass assigned boat source ID into ControllerServer.
|
|
|
|
new Thread(mockOutput).start();
|
|
|
|
|
|
|
|
new Thread(controllerServer).start();
|
|
|
|
new Thread(mockOutput, "ConnectionAcceptor.run()->MockOutput thread" + mockOutput).start();
|
|
|
|
|
|
|
|
new Thread(controllerServer, "ConnectionAcceptor.run()->ControllerServer thread" + controllerServer).start();
|
|
|
|
|
|
|
|
|
|
|
|
mockOutputList.add(mockOutput);
|
|
|
|
mockOutputList.add(mockOutput);
|
|
|
|
System.out.println(String.format("%d number of Visualisers Connected.", mockOutputList.size()));
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(String.format("%d number of Visualisers Connected.", mockOutputList.size()));//TEMP
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();//TODO handle this properly
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -111,7 +122,7 @@ public class ConnectionAcceptor implements Runnable {
|
|
|
|
double timeSinceLastHeartBeat = System.currentTimeMillis();
|
|
|
|
double timeSinceLastHeartBeat = System.currentTimeMillis();
|
|
|
|
while(true) {
|
|
|
|
while(true) {
|
|
|
|
//System.out.println(mocks.size());//used to see current amount of visualisers connected.
|
|
|
|
//System.out.println(mocks.size());//used to see current amount of visualisers connected.
|
|
|
|
ArrayBlockingQueue<MockOutput> m = new ArrayBlockingQueue(16, true, mocks);
|
|
|
|
ArrayBlockingQueue<MockOutput> m = new ArrayBlockingQueue<>(16, true, mocks);
|
|
|
|
for (MockOutput mo : m) {
|
|
|
|
for (MockOutput mo : m) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mo.sendHeartBeat();
|
|
|
|
mo.sendHeartBeat();
|
|
|
|
|