private final static Logger LOGGER = LoggerFactory.getLogger(Process.class);
protected Long heartBeatInterval = 1000L;
- protected final Thread monitor;
+ protected Thread monitor;
final String name;
final Integer port;
public abstract void onStop();
public final void start() {
+ LOGGER.info("Process[{}]::start", name);
onStart();
}
public final void shutdown() {
+ LOGGER.info("Process[{}]::shutdown", name);
this.monitor.interrupt();
+ this.monitor = null;
this.onStop();
}
@Override
public void run() {
- LOGGER.debug("Setting up heartbeat on port '{}'", port);
+ LOGGER.info("Process[{}]::heartbeat({}) START", name, port);
try {
byte[] data = name.getBytes();
DatagramPacket pack =
} catch (IOException e) {
throw new IllegalStateException("Heartbeat Thread for " + name + " could not communicate to socket", e);
}
+ LOGGER.warn("Process[{}]::heartbeat OVER", name);
}
}
\ No newline at end of file
private final static String SONAR_HOME = "SONAR_HOME";
private final Env env;
- private final ExecutorService executor;
- private final MonitorService monitor;
private final String esPort;
private final Map<String, String> properties;
+ private ExecutorService executor;
+ private MonitorService monitor;
private ProcessWrapper elasticsearch;
private ProcessWrapper sonarqube;
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
- LOGGER.info("Shutting down sonar Node");
- if (elasticsearch != null) {
- elasticsearch.shutdown();
- }
- if (sonarqube != null) {
- sonarqube.shutdown();
- }
- executor.shutdown();
- try {
- executor.awaitTermination(10L, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- LOGGER.warn("Executing terminated", e);
- }
+ shutdown();
}
});
+
+ monitor.start();
}
private DatagramSocket systemAvailableSocket() throws IOException {
return new DatagramSocket(0);
}
+ public void shutdown() {
+ LOGGER.info("Shutting down sonar Node");
+ if (monitor != null) {
+ monitor.interrupt();
+ monitor = null;
+ }
+ if (elasticsearch != null) {
+ elasticsearch.shutdown();
+ elasticsearch = null;
+ }
+
+ if (sonarqube != null) {
+ sonarqube.shutdown();
+ sonarqube = null;
+ }
+
+ if (executor != null) {
+ executor.shutdown();
+ try {
+ executor.awaitTermination(10L, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ LOGGER.warn("Executing terminated", e);
+ }
+ executor = null;
+ }
+ }
+
public void start() {
// Start ES
this.startSQ();
// And monitor the activity
- monitor.run();
- LOGGER.warn("Shutting down the node...");
-
- // If monitor is finished, we're done. Cleanup
- executor.shutdownNow();
-
+ try {
+ monitor.join();
+ } catch (InterruptedException e) {
+ LOGGER.warn("Shutting down the node...");
+ }
+ shutdown();
}
private void registerProcess(ProcessWrapper process) {
public static void main(String... args) throws InterruptedException, IOException, URISyntaxException {
- String home = System.getenv(SONAR_HOME);
+ //String home = System.getenv(SONAR_HOME);
+ String home = "/Volumes/data/sonar/sonarqube/sonar-start/target/sonarqube-4.5-SNAPSHOT";
//Check if we have a SONAR_HOME
if (StringUtils.isEmpty(home)) {