aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 15:29:57 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 15:29:57 +0200
commit3166381a9020db85e45bfef8ebea9f841736af69 (patch)
treeb78c6b8222bd2e6d9bf525ba053644761b78a641 /server/sonar-process
parent008297c01720142798feb575d7caa09b5f0db485 (diff)
downloadsonarqube-3166381a9020db85e45bfef8ebea9f841736af69.tar.gz
sonarqube-3166381a9020db85e45bfef8ebea9f841736af69.zip
SONAR-4898 simplify MonitoredProcess implementations
Diffstat (limited to 'server/sonar-process')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java12
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java10
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java10
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java18
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java5
5 files changed, 47 insertions, 8 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java b/server/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
index 6ee84d00744..11ddf54beec 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
@@ -22,10 +22,20 @@ package org.sonar.process;
public interface MonitoredProcess extends Terminable {
/**
- * Starts and blocks until ready
+ * Starts process. No need to block until fully started and operational.
*/
void start();
+ /**
+ * True if the process is started and operational (-> can accept requests), false if
+ * it's still starting. An exception is thrown is process failed to start (not starting
+ * nor started).
+ */
+ boolean isReady();
+
+ /**
+ * Blocks until the process is terminated
+ */
void awaitTermination();
}
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 6990545a571..7137a41fa12 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
@@ -75,10 +75,17 @@ public class ProcessEntryPoint implements ProcessMXBean {
try {
monitoredProcess.start();
+ boolean ready = false;
+ while (!ready) {
+ ready = monitoredProcess.isReady();
+ Thread.sleep(200L);
+ }
if (lifecycle.tryToMoveTo(State.STARTED)) {
monitoredProcess.awaitTermination();
}
- } catch (Exception ignored) {
+ } catch (Exception e) {
+ LoggerFactory.getLogger(getClass()).warn("Fail to start", e);
+
} finally {
terminate();
}
@@ -86,7 +93,6 @@ public class ProcessEntryPoint implements ProcessMXBean {
@Override
public boolean isReady() {
- LoggerFactory.getLogger(getClass()).warn("Received JMX request isReady: " + (lifecycle.getState() == State.STARTED));
return lifecycle.getState() == State.STARTED;
}
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 55bf8d679d1..03cd7409a49 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
@@ -194,6 +194,11 @@ public class ProcessEntryPointTest {
}
@Override
+ public boolean isReady() {
+ return true;
+ }
+
+ @Override
public void awaitTermination() {
}
@@ -212,6 +217,11 @@ public class ProcessEntryPointTest {
}
@Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
public void awaitTermination() {
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java
index 307abed6d0b..f6ca587a588 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java
@@ -42,6 +42,7 @@ import java.io.IOException;
public class HttpProcess implements MonitoredProcess {
private final Server server;
+ private boolean ready = false;
// temp dir is specific to this process
private final File tempDir = new File(System.getProperty("java.io.tmpdir"));
@@ -70,17 +71,24 @@ public class HttpProcess implements MonitoredProcess {
});
try {
server.start();
- while (!server.isStarted()) {
- Thread.sleep(100L);
- }
- writeTimeToFile("readyAt");
-
} catch (Exception e) {
throw new IllegalStateException("Fail to start Jetty", e);
}
}
@Override
+ public boolean isReady() {
+ if (ready) {
+ return true;
+ }
+ if (server.isStarted()) {
+ ready = true;
+ writeTimeToFile("readyAt");
+ }
+ return false;
+ }
+
+ @Override
public void awaitTermination() {
try {
server.join();
diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java
index 121784f633b..4c1a33221c6 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java
@@ -51,6 +51,11 @@ public class StandardProcess implements MonitoredProcess {
}
@Override
+ public boolean isReady() {
+ return state == State.STARTED;
+ }
+
+ @Override
public void awaitTermination() {
try {
daemon.join();