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);
}
@Override
- public void close() throws Exception {
+ public void close() {
endWatch();
}
}
}
@Override
- public void close() throws Exception {
+ public void close() {
allProcessesCommands.close();
}
}
* <li>stop/restart a specific processes</li>
* </ul>
*
- * @see DefaultProcessCommands#DefaultProcessCommands(File, int)
+ * @see DefaultProcessCommands#main(File, int)
+ * @see DefaultProcessCommands#secondary(File, int)
*/
public interface ProcessCommands extends AutoCloseable {
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;
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) {
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);
}
}
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;
}
@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);
}
@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);