private void waitTerminationAndNotifyClients()

in nailgun-server/src/main/java/com/facebook/nailgun/NGCommunicator.java [268:305]


  private void waitTerminationAndNotifyClients(NGClientDisconnectReason reason) {
    while (true) {
      List<NGClientListener> listeners = new ArrayList<>();
      synchronized (orchestratorEvent) {
        if (shutdown) {
          reason = NGClientDisconnectReason.SESSION_SHUTDOWN;
        }
        if (!clientListeners.isEmpty()) {
          listeners.addAll(clientListeners);
          clientListeners.clear();
        }
      }

      // release the lock and notify clients about disconnect
      for (NGClientListener listener : listeners) {
        listener.clientDisconnected(reason);
      }

      synchronized (orchestratorEvent) {
        if (!clientListeners.isEmpty()) {
          continue;
        }
        if (shutdown) {
          return;
        }
        try {
          // wait for any new other client listener to register, or shutdown
          // signal
          orchestratorEvent.wait();
        } catch (InterruptedException e) {
          // this thread can only be interrupted from terminateExecutor(), which
          // should not ever happen given the normal code flow, so
          // just do nothing and quit
          return;
        }
      }
    }
  }