Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Closeable and shut down the executor #255

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,19 +12,20 @@
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;
import com.hubspot.baragon.models.BaragonServiceState;
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;
Expand Down Expand Up @@ -71,6 +74,11 @@ public void run() {
watcher.start();
}

@Override
public void close() throws IOException {
executor.shutdown();
}

private void updateToLatestVersion() {
Deque<Integer> versions = new ArrayDeque<>();
versionQueue.drainTo(versions);
Expand Down