2 * SonarQube :: Process Monitor
3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.process.monitor;
22 import java.util.List;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import static java.util.Objects.requireNonNull;
28 public class RestartRequestWatcherThread extends Thread {
29 private static final Logger LOG = LoggerFactory.getLogger(RestartRequestWatcherThread.class);
30 private static int instanceCounter = 0;
32 private final Monitor monitor;
33 private final List<ProcessRef> processes;
34 private final long delayMs;
36 private boolean watching = true;
38 public RestartRequestWatcherThread(Monitor monitor, List<ProcessRef> processes) {
39 this(monitor, processes, 500);
42 public RestartRequestWatcherThread(Monitor monitor, List<ProcessRef> processes, long delayMs) {
43 super("Restart watcher " + (instanceCounter++));
44 this.monitor = requireNonNull(monitor, "monitor can not be null");
45 this.processes = requireNonNull(processes, "processes can not be null");
46 this.delayMs = delayMs;
52 for (ProcessRef processCommands : processes) {
53 if (processCommands.getCommands().askedForRestart()) {
54 LOG.info("Process [{}] requested restart", processCommands.getKey());
55 monitor.restartAsync();
59 Thread.sleep(delayMs);
60 } catch (InterruptedException ignored) {
68 public void stopWatching() {
69 this.watching = false;
72 public boolean isWatching() {