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();
            }
        }
    }
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) {
                           
                            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();
            }
        }
    }
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) { 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(); } } }