diff --git a/BaragonWatcher/src/main/java/com/hubspot/baragon/watcher/BaragonStateWatcher.java b/BaragonWatcher/src/main/java/com/hubspot/baragon/watcher/BaragonStateWatcher.java index 13144a408..db78d487c 100644 --- a/BaragonWatcher/src/main/java/com/hubspot/baragon/watcher/BaragonStateWatcher.java +++ b/BaragonWatcher/src/main/java/com/hubspot/baragon/watcher/BaragonStateWatcher.java @@ -1,5 +1,7 @@ package com.hubspot.baragon.watcher; +import java.io.Closeable; +import java.io.IOException; import java.util.ArrayDeque; import java.util.Collection; import java.util.Deque; @@ -10,6 +12,10 @@ import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.ThreadFactory; +import org.apache.curator.framework.listen.ListenerContainer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.common.base.Function; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -17,12 +23,9 @@ import com.hubspot.ringleader.watcher.Event; import com.hubspot.ringleader.watcher.EventListener; import com.hubspot.ringleader.watcher.PersistentWatcher; -import org.apache.curator.framework.listen.ListenerContainer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Singleton -public class BaragonStateWatcher { +public class BaragonStateWatcher implements Closeable { private static final Logger LOG = LoggerFactory.getLogger(BaragonStateWatcher.class); private final BaragonStateFetcher stateFetcher; @@ -71,6 +74,11 @@ public void run() { watcher.start(); } + @Override + public void close() throws IOException { + executor.shutdown(); + } + private void updateToLatestVersion() { Deque versions = new ArrayDeque<>(); versionQueue.drainTo(versions);