diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-03-08 14:10:00 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-03-21 16:44:03 +0100 |
commit | ca0b3a94ced3ee10f76c9465ccfa19767d62884d (patch) | |
tree | 27a5bf6dc1717e2667034b8e89de8a95b5d3f87f /server/sonar-process-monitor | |
parent | 57ceade526c1319333b855d08319145c3471de52 (diff) | |
download | sonarqube-ca0b3a94ced3ee10f76c9465ccfa19767d62884d.tar.gz sonarqube-ca0b3a94ced3ee10f76c9465ccfa19767d62884d.zip |
SONAR-7435 move awaitTermination to ProcessUtils and add UTs
Diffstat (limited to 'server/sonar-process-monitor')
-rw-r--r-- | server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java index 1aef72c479c..a4e1bfd4b7f 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java @@ -26,13 +26,13 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.process.DefaultProcessCommands; import org.sonar.process.Lifecycle; import org.sonar.process.Lifecycle.State; import org.sonar.process.ProcessCommands; +import org.sonar.process.ProcessUtils; import org.sonar.process.SystemExit; public class Monitor { @@ -178,7 +178,7 @@ public class Monitor { public void awaitTermination() { while (awaitChildProcessesTermination()) { trace("await termination of restartor..."); - awaitTermination(restartor); + ProcessUtils.awaitTermination(restartor); } cleanAfterTermination(); } @@ -188,7 +188,7 @@ public class Monitor { trace("finished waiting, restartRequested={}", restartRequested); if (restartRequested) { trace("awaitTermination restartor={}", restartor); - awaitTermination(restartor); + ProcessUtils.awaitTermination(restartor); } return restartRequested; } @@ -197,7 +197,7 @@ public class Monitor { trace("await termination of child processes..."); List<WatcherThread> watcherThreadsCopy = new ArrayList<>(this.watcherThreads); for (WatcherThread watcherThread : watcherThreadsCopy) { - awaitTermination(watcherThread); + ProcessUtils.awaitTermination(watcherThread); } trace("all child processes done"); return hasRestartBeenRequested(watcherThreadsCopy); @@ -221,7 +221,7 @@ public class Monitor { trace("start hard stop async..."); stopAsync(State.HARD_STOPPING); trace("await termination of terminator..."); - awaitTermination(terminator); + ProcessUtils.awaitTermination(terminator); cleanAfterTermination(); trace("exit..."); systemExit.exit(0); @@ -232,7 +232,7 @@ public class Monitor { if (lifecycle.tryToMoveTo(State.STOPPED)) { trace("await termination of restartWatcher and hardStopWatcher..."); // wait for restartWatcher and hardStopWatcher to cleanly stop - awaitTermination(restartWatcher, hardStopWatcher); + ProcessUtils.awaitTermination(restartWatcher, hardStopWatcher); trace("restartWatcher done"); // removing shutdown hook to avoid called stop() unnecessarily unless already in shutdownHook if (!systemExit.isInShutdownHook()) { @@ -444,26 +444,6 @@ public class Monitor { } } - private static void awaitTermination(Thread... threads) { - for (Thread thread : threads) { - awaitTermination(thread); - } - } - - private static void awaitTermination(@Nullable Thread t) { - if (t == null || Thread.currentThread() == t) { - return; - } - - while (t.isAlive()) { - try { - t.join(); - } catch (InterruptedException e) { - // ignore and stop blocking - } - } - } - private static void trace(String s) { LOG.trace(s); } |