aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process-monitor
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-10-04 14:46:47 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-10-05 14:19:56 +0200
commitefff409c5850df93e9fb4f6123fd2818353668b9 (patch)
treeafa9943bc239f9b5e206edc3b258ccd2c0bce101 /server/sonar-process-monitor
parentb6a96c82c5949a67a678a2835115bee17c895275 (diff)
downloadsonarqube-efff409c5850df93e9fb4f6123fd2818353668b9.tar.gz
sonarqube-efff409c5850df93e9fb4f6123fd2818353668b9.zip
Fix Quality flaws, including handling of InterruptedException
Diffstat (limited to 'server/sonar-process-monitor')
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java18
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java9
2 files changed, 15 insertions, 12 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 6b62cafd60c..182155ff9fb 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
@@ -82,7 +82,7 @@ public class Monitor {
* @throws java.lang.IllegalStateException if already started or if at least one process failed to start. In this case
* all processes are terminated. No need to execute {@link #stop()}
*/
- public void start(List<JavaCommand> commands) {
+ public void start(List<JavaCommand> commands) throws InterruptedException {
if (commands.isEmpty()) {
throw new IllegalArgumentException("At least one command is required");
}
@@ -101,7 +101,7 @@ public class Monitor {
startProcesses();
}
- private void startProcesses() {
+ private void startProcesses() throws InterruptedException {
// do no start any child process if not in state INIT or RESTARTING (a stop could be in progress too)
if (lifecycle.tryToMoveTo(State.STARTING)) {
resetFileSystem();
@@ -137,14 +137,14 @@ public class Monitor {
}
}
- private void startAndMonitorProcesses() {
+ private void startAndMonitorProcesses() throws InterruptedException{
File tempDir = fileSystem.getTempDir();
this.launcher = new JavaProcessLauncher(TIMEOUTS, tempDir);
for (JavaCommand command : javaCommands) {
try {
ProcessRef processRef = launcher.launch(command);
monitor(processRef);
- } catch (RuntimeException e) {
+ } catch (InterruptedException | RuntimeException e) {
// fail to start or to monitor
stop();
throw e;
@@ -152,7 +152,7 @@ public class Monitor {
}
}
- private void monitor(ProcessRef processRef) {
+ private void monitor(ProcessRef processRef) throws InterruptedException {
// physically watch if process is alive
WatcherThread watcherThread = new WatcherThread(processRef, this);
watcherThread.start();
@@ -283,7 +283,13 @@ public class Monitor {
@Override
public void run() {
stopProcesses();
- startProcesses();
+ try {
+ startProcesses();
+ } catch (InterruptedException e) {
+ // Startup was interrupted. Processes are being stopped asynchronously.
+ // Restoring the interruption state.
+ Thread.currentThread().interrupt();
+ }
}
}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
index d3523ed2ed4..83d8bb14c30 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
@@ -58,18 +58,14 @@ class ProcessRef {
return commands;
}
- void waitForUp() {
+ void waitForUp() throws InterruptedException {
boolean up = false;
while (!up) {
if (isStopped()) {
throw new MessageException(String.format("%s failed to start", this));
}
up = commands.isUp();
- try {
- Thread.sleep(200L);
- } catch (InterruptedException e) {
- throw new IllegalStateException(String.format("Interrupted while waiting for %s to be up", this), e);
- }
+ Thread.sleep(200L);
}
}
@@ -98,6 +94,7 @@ class ProcessRef {
} catch (InterruptedException e) {
// can't wait for the termination of process. Let's assume it's down.
LoggerFactory.getLogger(getClass()).warn(String.format("Interrupted while stopping process %s", key), e);
+ Thread.currentThread().interrupt();
}
}
ProcessUtils.closeStreams(process);