aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-08-30 16:30:36 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-09-05 14:24:13 +0200
commitc9f779dc009b42cf8e1bc5c5a335462be0c3e971 (patch)
tree54d206fef7d3ab76d5ca7fa91a0d8eceed318882 /server/sonar-process/src
parent0e2b5bb24f1fcead00fd32e459c8756c7f9342e5 (diff)
downloadsonarqube-c9f779dc009b42cf8e1bc5c5a335462be0c3e971.tar.gz
sonarqube-c9f779dc009b42cf8e1bc5c5a335462be0c3e971.zip
SONAR-9715 improve documentation of process management
Diffstat (limited to 'server/sonar-process/src')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/Monitored.java10
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java4
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/StopperThread.java19
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java4
4 files changed, 21 insertions, 16 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Monitored.java b/server/sonar-process/src/main/java/org/sonar/process/Monitored.java
index b37d929e54d..2fa65b1c571 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/Monitored.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/Monitored.java
@@ -19,6 +19,11 @@
*/
package org.sonar.process;
+/**
+ * Base interface for the processes started by the bootstrap process.
+ * It provides the information and operations required by {@link ProcessEntryPoint}
+ * to handle the lifecycle of the process.
+ */
public interface Monitored {
/**
@@ -37,9 +42,12 @@ public interface Monitored {
}
/**
- * Blocks until the process is terminated
+ * Blocks until the process is stopped
*/
void awaitStop();
+ /**
+ * Stop process and wait until it's stopped.
+ */
void stop();
}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
index b1476fba53e..76b89a007f9 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
@@ -29,7 +29,7 @@ public class ProcessEntryPoint implements Stoppable {
public static final String PROPERTY_PROCESS_KEY = "process.key";
public static final String PROPERTY_PROCESS_INDEX = "process.index";
- public static final String PROPERTY_TERMINATION_TIMEOUT = "process.terminationTimeout";
+ public static final String PROPERTY_TERMINATION_TIMEOUT_MS = "process.terminationTimeout";
public static final String PROPERTY_SHARED_PATH = "process.sharedDir";
private final Props props;
@@ -171,7 +171,7 @@ public class ProcessEntryPoint implements Stoppable {
@Override
public void stopAsync() {
if (lifecycle.tryToMoveTo(Lifecycle.State.STOPPING)) {
- stopperThread = new StopperThread(monitored, commands, Long.parseLong(props.nonNullValue(PROPERTY_TERMINATION_TIMEOUT)));
+ stopperThread = new StopperThread(monitored, commands, Long.parseLong(props.nonNullValue(PROPERTY_TERMINATION_TIMEOUT_MS)));
stopperThread.start();
stopWatcher.stopWatching();
}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/StopperThread.java b/server/sonar-process/src/main/java/org/sonar/process/StopperThread.java
index 746cd31dc1e..14fe192cd9c 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/StopperThread.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/StopperThread.java
@@ -27,35 +27,32 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.sonar.process.sharedmemoryfile.ProcessCommands;
+import static java.lang.String.format;
+
/**
* Gracefully stops process in a timely fashion
*/
class StopperThread extends Thread {
private final Monitored monitored;
- private final long terminationTimeout;
+ private final long terminationTimeoutMs;
private final ProcessCommands commands;
- StopperThread(Monitored monitored, ProcessCommands commands, long terminationTimeout) {
+ StopperThread(Monitored monitored, ProcessCommands commands, long terminationTimeoutMs) {
super("Stopper");
this.monitored = monitored;
- this.terminationTimeout = terminationTimeout;
+ this.terminationTimeoutMs = terminationTimeoutMs;
this.commands = commands;
}
@Override
public void run() {
ExecutorService executor = Executors.newSingleThreadExecutor();
- Future future = executor.submit(new Runnable() {
- @Override
- public void run() {
- monitored.stop();
- }
- });
try {
- future.get(terminationTimeout, TimeUnit.MILLISECONDS);
+ Future future = executor.submit(monitored::stop);
+ future.get(terminationTimeoutMs, TimeUnit.MILLISECONDS);
} catch (Exception e) {
- LoggerFactory.getLogger(getClass()).error(String.format("Can not stop in %dms", terminationTimeout), e);
+ LoggerFactory.getLogger(getClass()).error(format("Can not stop in %dms", terminationTimeoutMs), e);
}
executor.shutdownNow();
commands.endWatch();
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
index 3b7a4659d31..ccffe816e58 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.mock;
import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX;
import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_KEY;
import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH;
-import static org.sonar.process.ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT;
+import static org.sonar.process.ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT_MS;
public class ProcessEntryPointTest {
@@ -159,7 +159,7 @@ public class ProcessEntryPointTest {
props.set(PROPERTY_SHARED_PATH, temp.newFolder().getAbsolutePath());
props.set(PROPERTY_PROCESS_INDEX, "1");
props.set(PROPERTY_PROCESS_KEY, "test");
- props.set(PROPERTY_TERMINATION_TIMEOUT, "30000");
+ props.set(PROPERTY_TERMINATION_TIMEOUT_MS, "30000");
return props;
}