public void stop() {
   CompositeStoppable stoppable;
   lock.lock();
   try {
     stoppable = CompositeStoppable.stoppable(hub, discoveryBroadcast, executor);
   } finally {
     connections.clear();
     lock.unlock();
   }
   stoppable.stop();
 }
Esempio n. 2
0
  /**
   * Stops the daemon, blocking until any current requests/connections have been satisfied.
   *
   * <p>This is the semantically the same as sending the daemon the Stop command.
   *
   * <p>This method does not quite conform to the semantics of the Stoppable contract in that it
   * will NOT wait for any executing builds to stop before returning. This is by design as we
   * currently have no way of gracefully stopping a build process and blocking until it's done would
   * not allow us to tear down the jvm like we need to. This may change in the future if we create a
   * way to interrupt a build.
   *
   * <p>What will happen though is that the daemon will immediately disconnect from any clients and
   * remove itself from the registry.
   */
  public void stop() {
    LOGGER.debug("stop() called on daemon");
    lifecyleLock.lock();
    try {
      if (stateCoordinator == null) {
        throw new IllegalStateException("cannot stop daemon as it has not been started.");
      }

      LOGGER.info(DaemonMessages.REMOVING_PRESENCE_DUE_TO_STOP);

      // Stop the pipeline:
      // 1. mark daemon as stopped, so that any incoming requests will be rejected with 'daemon
      // unavailable'
      // 2. remove presence from registry
      // 3. stop accepting new connections
      // 4. wait for commands in progress to finish (except for abandoned long running commands,
      // like running a build)

      CompositeStoppable.stoppable(stateCoordinator, registryUpdater, connector, connectionHandler)
          .stop();
    } finally {
      lifecyleLock.unlock();
    }
  }