public void await() {
        // Set to 1 for ourselves.
        readyCount = 1;

        // Send out-going confirmations.
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (ServerIdentifier identifier : servers) {
                    if (identifier.equals(myIdentifier)) {
                        continue;
                    }
                    try {
                        Socket outSocket = identifier.createSocket();
                        BufferedReader in = new BufferedReader(new InputStreamReader(outSocket.getInputStream()));
                        PrintWriter out = new PrintWriter(outSocket.getOutputStream(), true);

                        out.println(myIdentifier.toString());
                        // Wait for response.
                        String response = in.readLine();
                        if (BARRIER_ACK.equals(response)) {
                            markReady(identifier);
                        }

                        in.close();
                        out.close();
                        outSocket.close();
                    } catch (IOException e) {
                        // Problem connecting.
                    }
                }
            }
        }).start();

        // Accept in-coming confirmations.
        ServerSocket barrierSocket = null;
        try {
            barrierSocket = new ServerSocket(myIdentifier.getPort());
            barrierSocket.setSoTimeout(1000);
            while (readyCount < servers.size()) {
                Socket client;
                try {
                    client = barrierSocket.accept();
                } catch (IOException e) {
                    // Just a timeout, carry on.
                    continue;
                }
                BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
                PrintWriter out = new PrintWriter(client.getOutputStream(), true);

                ServerIdentifier identifier = ServerIdentifier.parse(in.readLine().trim());
                markReady(identifier);
                out.println(BARRIER_ACK);

                in.close();
                out.close();
                client.close();
            }
        } catch (IOException e) {
            throw new RuntimeException("Error waiting for all servers to initialize.", e);
        } finally {
            if (barrierSocket != null) {
                try {
                    barrierSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }