Example #1
0
  private void stopProcesses() {
    List<WatcherThread> watcherThreadsCopy = new ArrayList<>(this.watcherThreads);
    // create a copy and reverse it to terminate in reverse order of startup (dependency order)
    Collections.reverse(watcherThreadsCopy);

    for (WatcherThread watcherThread : watcherThreadsCopy) {
      ProcessRef ref = watcherThread.getProcessRef();
      if (!ref.isStopped()) {
        LOG.info("{} is stopping", ref);
        ref.askForGracefulAsyncStop();

        long killAt = System.currentTimeMillis() + TIMEOUTS.getTerminationTimeout();
        while (!ref.isStopped() && System.currentTimeMillis() < killAt) {
          try {
            Thread.sleep(10L);
          } catch (InterruptedException e) {
            // stop asking for graceful stops, Monitor will hardly kill all processes
            break;
          }
        }
        if (!ref.isStopped()) {
          LOG.info("{} failed to stop in a timely fashion. Killing it.", ref);
        }
        ref.stop();
        LOG.info("{} is stopped", ref);
      }
    }

    // all processes are stopped, no need to keep references to these WatcherThread anymore
    trace("all processes stopped, clean list of watcherThreads...");
    this.watcherThreads.clear();
  }
Example #2
0
 private static boolean hasRestartBeenRequested(List<WatcherThread> watcherThreads) {
   for (WatcherThread watcherThread : watcherThreads) {
     if (watcherThread.isAskedForRestart()) {
       trace("one child process requested restart");
       return true;
     }
   }
   trace("no child process requested restart");
   return false;
 }
Example #3
0
 private boolean didAnyProcessRequestRestart() {
   for (WatcherThread watcherThread : watcherThreads) {
     ProcessRef processRef = watcherThread.getProcessRef();
     if (processRef.getCommands().askedForRestart()) {
       LOG.info("Process [{}] requested restart", processRef.getKey());
       return true;
     }
   }
   return false;
 }
Example #4
0
  private void monitor(ProcessRef processRef) {
    // physically watch if process is alive
    WatcherThread watcherThread = new WatcherThread(processRef, this);
    watcherThread.start();
    watcherThreads.add(watcherThread);

    // wait for process to be ready (accept requests or so on)
    processRef.waitForReady();

    LOG.info("{} is up", processRef);
  }