Make AlertManager#stop() synchronized so that the call from beforeClose waits if an stop is being performed already.

This prevents the test framework to complain about the fact that threads are lingering around when the test cluster has been shutdown.

Original commit: elastic/x-pack-elasticsearch@315be3f376
This commit is contained in:
Martijn van Groningen 2014-11-20 11:12:25 +01:00
parent 42dda5b975
commit ca00e59911
1 changed files with 5 additions and 1 deletions

View File

@ -151,7 +151,11 @@ public class AlertManager extends AbstractComponent {
}
public void stop() {
// This is synchronized, because this may first be called from the cluster changed event and then from before close
// when a node closes. The stop also stops the scheduler which has several background threads. If this method is
// invoked in that order that node closes and the test framework complains then about the fact that there are still
// threads alive.
public synchronized void stop() {
if (state.compareAndSet(State.LOADING, State.STOPPED) || state.compareAndSet(State.STARTED, State.STOPPED)) {
logger.info("Stopping alert manager...");
scheduler.stop();