]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5409 - added onStart and onStop abstract methods to Process
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 11 Jul 2014 09:31:26 +0000 (11:31 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 11 Jul 2014 09:32:05 +0000 (11:32 +0200)
server/sonar-process/src/main/java/org/sonar/process/Process.java
server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java

index d1070c3c1387f7c2bab17c4c4b21c14899336475..349999adff7a51323315d8031ec521083a161b18 100644 (file)
@@ -74,13 +74,20 @@ public abstract class Process implements Runnable {
 
     //Starting monitoring thread
     this.monitor = new Thread(this);
-    this.monitor.start();
   }
 
-  public abstract void execute();
+  public abstract void onStart();
+
+  public abstract void onStop();
+
+  public final void start() {
+    this.monitor.start();
+    onStart();
+  }
 
-  public void shutdown() {
+  public final void shutdown() {
     this.monitor.interrupt();
+    this.onStop();
   }
 
   @Override
index 6dd31880e6a3210200771a678e5274ec18ac49e0..4c528db7ed9065c25447069546675fead90e5363 100644 (file)
@@ -102,11 +102,12 @@ public class ElasticSearch extends org.sonar.process.Process {
 
     node = NodeBuilder.nodeBuilder()
       .settings(esSettings)
-      .build().start();
+      .build();
   }
 
   @Override
-  public void execute() {
+  public void onStart() {
+    node.start();
     try {
       Thread.currentThread().join();
     } catch (InterruptedException e) {
@@ -114,16 +115,15 @@ public class ElasticSearch extends org.sonar.process.Process {
     }
   }
 
-  public void shutdown() {
+  public void onStop() {
     if (node != null) {
       this.node.close();
     }
-    super.shutdown();
   }
 
   public static void main(String... args) {
     Props props = Props.create(System.getProperties());
     ElasticSearch elasticSearch = new ElasticSearch(props);
-    elasticSearch.execute();
+    elasticSearch.start();
   }
 }
\ No newline at end of file