/** * Blocks until stopped in a timely fashion (see {@link org.sonar.process.StopperThread}) */ void stop() { stopAsync(); try { // stopperThread is not null for sure // join() does nothing if thread already finished stopperThread.join(); lifecycle.tryToMoveTo(Lifecycle.State.STOPPED); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } exit.exit(0); }
@Test public void exit_if_not_in_shutdown_hook() { final AtomicInteger got = new AtomicInteger(); SystemExit systemExit = new SystemExit() { @Override void doExit(int code) { got.set(code); } }; assertThat(systemExit.isInShutdownHook()).isFalse(); systemExit.exit(1); assertThat(got.get()).isEqualTo(1); } }
@Test public void do_not_exit_if_in_shutdown_hook() { SystemExit systemExit = new SystemExit(); systemExit.setInShutdownHook(); assertThat(systemExit.isInShutdownHook()).isTrue(); systemExit.exit(0); // still there }
public void start(String[] cliArguments) throws IOException { AppSettingsLoader settingsLoader = new AppSettingsLoaderImpl(cliArguments); AppSettings settings = settingsLoader.load(); // order is important - logging must be configured before any other components (AppFileSystem, ...) AppLogging logging = new AppLogging(settings); logging.configure(); AppFileSystem fileSystem = new AppFileSystem(settings); try (AppState appState = new AppStateFactory(settings).create()) { appState.registerSonarQubeVersion(getSonarqubeVersion()); appState.registerClusterName(settings.getProps().nonNullValue(CLUSTER_NAME.getKey())); AppReloader appReloader = new AppReloaderImpl(settingsLoader, fileSystem, appState, logging); fileSystem.reset(); CommandFactory commandFactory = new CommandFactoryImpl(settings.getProps(), fileSystem.getTempDir(), System2.INSTANCE); try (ProcessLauncher processLauncher = new ProcessLauncherImpl(fileSystem.getTempDir())) { Scheduler scheduler = new SchedulerImpl(settings, appReloader, commandFactory, processLauncher, appState); // intercepts CTRL-C Runtime.getRuntime().addShutdownHook(new ShutdownHook(scheduler)); scheduler.schedule(); stopRequestWatcher = StopRequestWatcherImpl.create(settings, scheduler, fileSystem); stopRequestWatcher.startWatching(); scheduler.awaitTermination(); stopRequestWatcher.stopWatching(); } } systemExit.exit(0); }
/** * Blocks until stopped in a timely fashion (see {@link org.sonar.process.StopperThread}) */ void stop() { stopAsync(); try { // stopperThread is not null for sure // join() does nothing if thread already finished stopperThread.join(); lifecycle.tryToMoveTo(Lifecycle.State.STOPPED); } catch (InterruptedException e) { // nothing to do, the process is going to be exited } exit.exit(0); }