From b096cada959198f345b71cc9b0e65393c082d97e Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 10 Mar 2016 10:52:51 +0100 Subject: [PATCH] SONAR-7435 DefaultProcessCommands close() doesn't throw any exception this make writing try-with-resource easier --- .../org/sonar/process/monitor/Monitor.java | 19 ------------------- .../sonar/process/AllProcessesCommands.java | 2 +- .../sonar/process/DefaultProcessCommands.java | 2 +- .../org/sonar/process/ProcessCommands.java | 3 ++- .../server/app/ProcessCommandWrapperImpl.java | 8 +------- .../app/ProcessCommandWrapperImplTest.java | 5 +++-- 6 files changed, 8 insertions(+), 31 deletions(-) diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java index 4e5683d2e1b..8a28dcfb430 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java @@ -359,29 +359,10 @@ public class Monitor { if (processCommands.askedForStop()) { return true; } - } catch (IllegalArgumentException e) { - // DefaultProcessCommand currently wraps IOException into a IllegalArgumentException - // accessing the shared memory file may fail if a restart is in progress and the temp directory - // is currently deleted and not yet recreated - if (e.getCause() instanceof IOException) { - ignore((IOException) e.getCause()); - } else { - rethrow(e); - } - } catch (Exception e) { - rethrow(e); } return false; } - private void ignore(IOException e) { - trace("HardStopWatcherThread: Error checking stop flag in shared memory. Ignoring. Keep on watching.", e); - } - - private void rethrow(Exception e) { - throw new RuntimeException("Unexpected error occurred while watch for stop flag in shared memory", e); - } - private void delay() { try { Thread.sleep(WATCH_DELAY_MS); diff --git a/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java b/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java index 512cd788bab..d22a6ba1050 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java +++ b/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java @@ -269,7 +269,7 @@ public class AllProcessesCommands { } @Override - public void close() throws Exception { + public void close() { endWatch(); } } diff --git a/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java b/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java index a617ea4580b..04a608fef06 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java +++ b/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java @@ -117,7 +117,7 @@ public class DefaultProcessCommands implements ProcessCommands { } @Override - public void close() throws Exception { + public void close() { allProcessesCommands.close(); } } diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java index 1057ad54158..482029b81d8 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java @@ -28,7 +28,8 @@ import java.io.File; *
  • stop/restart a specific processes
  • * * - * @see DefaultProcessCommands#DefaultProcessCommands(File, int) + * @see DefaultProcessCommands#main(File, int) + * @see DefaultProcessCommands#secondary(File, int) */ public interface ProcessCommands extends AutoCloseable { diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java b/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java index 3278c80ad5e..9936a9f7e93 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java @@ -21,8 +21,6 @@ package org.sonar.server.app; import java.io.File; import org.sonar.api.config.Settings; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; import org.sonar.process.DefaultProcessCommands; import org.sonar.process.ProcessCommands; @@ -31,8 +29,6 @@ import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX; import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH; public class ProcessCommandWrapperImpl implements ProcessCommandWrapper { - private static final Logger LOG = Loggers.get(ProcessCommandWrapperImpl.class); - private final Settings settings; public ProcessCommandWrapperImpl(Settings settings) { @@ -52,10 +48,8 @@ public class ProcessCommandWrapperImpl implements ProcessCommandWrapper { private void call(VoidMethod command) { File shareDir = nonNullValueAsFile(PROPERTY_SHARED_PATH); int processNumber = nonNullAsInt(PROPERTY_PROCESS_INDEX); - try (ProcessCommands commands = DefaultProcessCommands.secondary(shareDir, processNumber)) { + try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(shareDir, processNumber)) { command.callOn(commands); - } catch (Exception e) { - LOG.warn("Failed to close ProcessCommands", e); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java index 40d6774dd31..8a394785681 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java @@ -20,6 +20,7 @@ package org.sonar.server.app; import java.io.File; +import java.io.IOException; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -63,7 +64,7 @@ public class ProcessCommandWrapperImplTest { } @Test - public void requestSQRestart_updates_shareMemory_file() throws Exception { + public void requestSQRestart_updates_shareMemory_file() throws IOException { File tmpDir = temp.newFolder().getAbsoluteFile(); settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath()); settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER); @@ -98,7 +99,7 @@ public class ProcessCommandWrapperImplTest { } @Test - public void notifyOperational_updates_shareMemory_file() throws Exception { + public void notifyOperational_updates_shareMemory_file() throws IOException { File tmpDir = temp.newFolder().getAbsoluteFile(); settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath()); settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER); -- 2.39.5