/** Shut down the HTTP server and all its workers, and close the listener socket. */
  public void stopServer() {
    shouldRun = false;
    try {
      listener.close();
    } catch (IOException ex) {
      // Don't care
    }
    while (true) {
      synchronized (allWorkers) {
        if (allWorkers.isEmpty()) {
          break;
        }
        for (Worker w : allWorkers) {
          w.stopSocket();
          w.interrupt();
        }
      }
    }

    try {
      listener.close();
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
  @Override
  public void run() {
    setName("Mock HTTP Listener: " + listener.socket().getInetAddress());
    while (shouldRun) {
      Socket incoming;
      try {
        incoming = listener.accept().socket();
        HttpServerConnection conn = connectionFactory.createConnection(incoming);
        Worker worker = new Worker(conn, incoming);

        synchronized (allWorkers) {
          allWorkers.add(worker);
        }
        worker.start();

      } catch (IOException ex) {
        if (shouldRun) {
          ex.printStackTrace();
        }
      }
    }
  }