mirror of
https://github.com/torproject/collector.git
synced 2025-02-16 23:37:46 +00:00
Fix non-RunOnce mode.
This was accidentally broken in #32554. The RunOnce mode worked just fine, but the non-RunOnce mode terminated immediately after scheduling tasks.
This commit is contained in:
parent
c75f0c781e
commit
a6359c6074
@ -1,4 +1,9 @@
|
||||
# Changes in version 1.1?.? - 2020-0?-??
|
||||
# Changes in version 1.14.1 - 2020-01-16
|
||||
|
||||
* Medium changes
|
||||
- Stay alive after scheduling (daemon) threads for modules. This
|
||||
was broken by taking out the periodic check for configuration
|
||||
file updates.
|
||||
|
||||
|
||||
# Changes in version 1.14.0 - 2020-01-15
|
||||
|
@ -87,12 +87,16 @@ public class Main {
|
||||
} else {
|
||||
conf.loadAndCheckConfiguration(confPath);
|
||||
}
|
||||
Scheduler.getInstance().scheduleModuleRuns(collecTorMains, conf);
|
||||
if (!Scheduler.getInstance().scheduleModuleRuns(collecTorMains, conf)) {
|
||||
return;
|
||||
}
|
||||
} catch (ConfigurationException ce) {
|
||||
printUsage(ce.getMessage());
|
||||
return;
|
||||
}
|
||||
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
|
||||
ShutdownHook shutdownHook = new ShutdownHook();
|
||||
Runtime.getRuntime().addShutdownHook(shutdownHook);
|
||||
shutdownHook.stayAlive();
|
||||
}
|
||||
|
||||
private static void printUsage(String msg) {
|
||||
|
@ -50,10 +50,10 @@ public final class Scheduler implements ThreadFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule all classes given according to the parameters in the
|
||||
* the configuration.
|
||||
* Schedule all classes given according to the parameters in the configuration
|
||||
* and return whether the caller should wait for completion.
|
||||
*/
|
||||
public void scheduleModuleRuns(Map<Key,
|
||||
public boolean scheduleModuleRuns(Map<Key,
|
||||
Class<? extends CollecTorMain>> collecTorMains, Configuration conf) {
|
||||
try {
|
||||
gracePeriodMinutes = conf.getLong(Key.ShutdownGraceWaitMinutes);
|
||||
@ -89,11 +89,13 @@ public final class Scheduler implements ThreadFactory {
|
||||
try {
|
||||
if (conf.getBool(Key.RunOnce)) {
|
||||
scheduler.invokeAll(runOnceMains);
|
||||
return false;
|
||||
}
|
||||
} catch (ConfigurationException | InterruptedException
|
||||
| RejectedExecutionException | NullPointerException ex) {
|
||||
logger.error("Cannot schedule run-once: {}", ex.getMessage(), ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void scheduleExecutions(CollecTorMain ctm, int offset, int period) {
|
||||
|
@ -13,15 +13,36 @@ public final class ShutdownHook extends Thread {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ShutdownHook.class);
|
||||
|
||||
private boolean stayAlive = true;
|
||||
|
||||
/** Names the shutdown thread for debugging purposes. */
|
||||
public ShutdownHook() {
|
||||
super("CollecTor-ShutdownThread");
|
||||
}
|
||||
|
||||
/**
|
||||
* Stay alive until the shutdown thread gets run.
|
||||
*/
|
||||
public void stayAlive() {
|
||||
synchronized (this) {
|
||||
while (this.stayAlive) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
/* Nothing we can do about this. */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("Shutdown in progress ... ");
|
||||
Scheduler.getInstance().shutdownScheduler();
|
||||
synchronized (this) {
|
||||
this.stayAlive = false;
|
||||
this.notify();
|
||||
}
|
||||
log.info("Shutdown finished. Exiting.");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user