//TODO refactor operations according to the protocol message
public synchronized void start() throws IOException, InterruptedException {
        final AtomicBoolean bound = new AtomicBoolean();
        running.set(true);
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ServerSocket ss = new ServerSocket(port);
                    synchronized (bound) {
                        bound.set(true);
                        bound.notifyAll();
                    }
                    Socket[] conn = new Socket[nDataGens];
                    try {
                        for (int i = 0; i < nDataGens; i++) {
                            conn[i] = ss.accept();
                        }
                        for (int n = 0; n < nIntervals; ++n) {
                            //TODO refactor operations according to the protocol message
                            if (flagStopResume) {
                                for (int i = 0; i < nDataGens; i++) {
                                    receiveStopped(conn[i]);
                                }
                                protocolActions[n].perform();
                                if (n != nIntervals - 1) {
                                    for (int i = 0; i < nDataGens; i++) {
                                        sendResume(conn[i]);
                                    }
                                }
                            } else {
                                for (int i = 0; i < nDataGens; i++) {
                                    receiveReached(conn[i]);
                                }
                                protocolActions[n].perform();
                            }
                        }
                    } finally {
                        for (int i = 0; i < conn.length; ++i) {
                            if (conn[i] != null) {
                                conn[i].close();
                            }
                        }
                        ss.close();
                    }
                    running.set(false);
                    synchronized (OrchestratorServer.this) {
                        OrchestratorServer.this.notifyAll();
                    }
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }
        });
        t.start();
        synchronized (bound) {
            while (!bound.get()) {
                bound.wait();
            }
        }
    }
}
for (int n = 0; n < nIntervals; ++n) {
//TODO refactor operations according to the protocol message
if (flagStopResume) {
for (int i = 0; i < nDataGens; i++) {
synchronized (bound) {
bound.set(true);
bound.notifyAll();
}
Socket[] conn = new Socket[nDataGens];
try {
for (int i = 0; i < nDataGens; i++) {
conn[i] = ss.accept();
}
for (int n = 0; n < nIntervals; ++n) {
//TODO refactor operations according to the protocol message
if (flagStopResume) {
for (int i = 0; i < nDataGens; i++) {
receiveStopped(conn[i]);
}
protocolActions[n].perform();
if (n != nIntervals - 1) {
for (int i = 0; i < nDataGens; i++) {
sendResume(conn[i]);
}
}
public synchronized void start() throws IOException, InterruptedException {
final AtomicBoolean bound = new AtomicBoolean();
running.set(true);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
ServerSocket ss = new ServerSocket(port);
synchronized (bound) {
bound.set(true);
bound.notifyAll();
}
Socket[] conn = new Socket[nDataGens];
try {
for (int i = 0; i < nDataGens; i++) {
conn[i] = ss.accept();
}
for (int n = 0; n < nIntervals; ++n) {
//TODO refactor operations according to the protocol message
if (flagStopResume) {
for (int i = 0; i < nDataGens; i++) {
receiveStopped(conn[i]);
}
protocolActions[n].perform();
if (n != nIntervals - 1) {
for (int i = 0; i < nDataGens; i++) {
sendResume(conn[i]);
}
}
} else {
for (int i = 0; i < nDataGens; i++) {
receiveReached(conn[i]);
}
protocolActions[n].perform();
}
}
} finally {
for (int i = 0; i < conn.length; ++i) {
if (conn[i] != null) {