]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6036 : Remove KnownJavaCommand and clean the memory at the startup of the Proce...
authorEric Hartmann <hartmann.eric@gmail.com>
Sat, 21 Feb 2015 07:28:12 +0000 (08:28 +0100)
committerEric Hartmann <hartmann.eric@gmail.com>
Sat, 21 Feb 2015 07:28:12 +0000 (08:28 +0100)
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaCommand.java
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/KnownJavaCommand.java [deleted file]
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java
server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java
server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java
sonar-application/src/main/java/org/sonar/application/App.java

index f4593308b9b3750485f8c683c4b729368b2798f3..d4b774cb851cd11c3980306b9ed7b09253d408c2 100644 (file)
@@ -58,10 +58,7 @@ public class JavaCommand {
 
   public JavaCommand(String key) {
     this.key = key;
-    processIndex = KnownJavaCommand.lookIndexFor(key);
-    if (processIndex == -1) {
-      processIndex = Monitor.getNextProcessId();
-    }
+    processIndex = Monitor.getNextProcessId();
   }
 
   public String getKey() {
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/KnownJavaCommand.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/KnownJavaCommand.java
deleted file mode 100644 (file)
index ce9a49a..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.process.monitor;
-
-/**
- * Created by eric on 20/02/15.
- */
-public enum KnownJavaCommand {
-  APP("app", 0), WEB("web", 1), ELASTIC_SEARCH("search", 2), UNKNOWN("unknown", -1);
-
-  private String key;
-  private int index;
-
-  KnownJavaCommand(String key, int index) {
-    this.key = key;
-    this.index = index;
-  }
-
-  public String getKey() {
-    return key;
-  }
-
-  public int getIndex() {
-    return index;
-  }
-
-  public static KnownJavaCommand lookFor(String key) {
-    for (KnownJavaCommand knownJavaCommand : KnownJavaCommand.values()) {
-      if (knownJavaCommand.getKey().equals(key)) {
-        return knownJavaCommand;
-      }
-    }
-    return KnownJavaCommand.UNKNOWN;
-  }
-
-  public static int lookIndexFor(String key) {
-    return lookFor(key).getIndex();
-  }
-
-  public static int getFirstIndexAvailable() {
-    int result = 0;
-    for (KnownJavaCommand knownJavaCommand : KnownJavaCommand.values()) {
-      result = knownJavaCommand.getIndex() >= result ? knownJavaCommand.getIndex() + 1 : result;
-    }
-    return result;
-  }
-}
index ccbeb558db017e84e1d70e82e91d28d89ecb3d49..fd546b9df5dcf4bf5d774b33d7dfef84c66797fd 100644 (file)
@@ -40,7 +40,7 @@ public class Monitor {
 
   // used by awaitStop() to block until all processes are shutdown
   private final List<WatcherThread> watcherThreads = new CopyOnWriteArrayList<WatcherThread>();
-  static int nextProcessId = KnownJavaCommand.getFirstIndexAvailable();
+  static int nextProcessId = 0;
 
   Monitor(JavaProcessLauncher launcher, SystemExit exit, TerminatorThread terminator) {
     this.launcher = launcher;
index 4a27d50ed6239052aec30ab59f1b223b9a6ddbc1..e88b8d493793288bfcfd3778419995ddc5706317 100644 (file)
@@ -217,7 +217,7 @@ public class MonitorTest {
     } catch (IllegalStateException e) {
       assertThat(e).hasMessageStartingWith("The maximum number of processes launched has been reached ");
     } finally {
-      Monitor.nextProcessId = KnownJavaCommand.getFirstIndexAvailable();
+      Monitor.nextProcessId = 0;
     }
   }
 
index 0edd51d34565770dea8853d048edd5347e4be84f..c9eafb30e540b35824261bcaf5749ca546aab544 100644 (file)
@@ -84,6 +84,7 @@ public class ProcessCommands {
     try {
       sharedMemory = new RandomAccessFile(new File(directory, "sharedmemory"), "rw");
       mappedByteBuffer = sharedMemory.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, MAX_SHARED_MEMORY);
+      cleanData();
     } catch (IOException e) {
       throw new IllegalArgumentException("Unable to create shared memory : ", e);
     }
@@ -143,6 +144,12 @@ public class ProcessCommands {
     return result;
   }
 
+  private void cleanData() {
+    for (int i = offset(); i < BYTE_LENGTH_FOR_ONE_PROCESS; i++) {
+      mappedByteBuffer.put(i, EMPTY);
+    }
+  }
+
   public static final int getMaxProcesses() {
     return MAX_PROCESSES;
   }
index f5418d42ab86e816297c8cc53dd31e96caefd7bd..68cb982a8456813ace61b9080e54e73567f73f46 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.process.Props;
 import org.sonar.process.StopWatcher;
 import org.sonar.process.Stoppable;
 import org.sonar.process.monitor.JavaCommand;
-import org.sonar.process.monitor.KnownJavaCommand;
 import org.sonar.process.monitor.Monitor;
 
 import java.io.File;
@@ -55,7 +54,7 @@ public class App implements Stoppable {
   public void start(Props props) {
     if (props.valueAsBoolean(ProcessConstants.ENABLE_STOP_COMMAND, false)) {
       File tempDir = props.nonNullValueAsFile(ProcessConstants.PATH_TEMP);
-      ProcessCommands commands = new ProcessCommands(tempDir, KnownJavaCommand.APP.getIndex());
+      ProcessCommands commands = new ProcessCommands(tempDir, 0);
       stopWatcher = new StopWatcher(commands, this);
       stopWatcher.start();
     }