Leverage ShutdownState in SourcesCollection

SourcesCollection uses a `shuttingDown` boolean variable to check
whether the configuration should be reloaded.

Updates to the `shuttingDown` variable are done within a synchronized
block, so ensure only one thread at a time can access it.

Since change Ic672c7df5 introduced the `ShutdownState` singleton
however, that should be used to signal and check the shutdown state
of the plugin.

Note that the `ShutdownState` also properly sets the state in a
thread-safe manner, as an equivalent replacement for the syncrhonized
block.

Change-Id: I1022d46f37a89f94fa70721daccf8436617cdfad
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourcesCollection.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourcesCollection.java
index 7be4971..3d8af69 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourcesCollection.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/SourcesCollection.java
@@ -35,8 +35,8 @@
   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
 
   private final Source.Factory sourceFactory;
+  private final ShutdownState shutdownState;
   private volatile List<Source> sources;
-  private boolean shuttingDown;
   private final Provider<ReplicationQueue> replicationQueue;
 
   @Inject
@@ -45,9 +45,11 @@
       ConfigParser configParser,
       Source.Factory sourceFactory,
       EventBus eventBus,
-      Provider<ReplicationQueue> replicationQueue)
+      Provider<ReplicationQueue> replicationQueue,
+      ShutdownState shutdownState)
       throws ConfigInvalidException {
     this.sourceFactory = sourceFactory;
+    this.shutdownState = shutdownState;
     this.sources =
         allSources(sourceFactory, configParser.parseRemotes(replicationConfig.getConfig()));
     this.replicationQueue = replicationQueue;
@@ -70,7 +72,7 @@
 
   @Override
   public void startup(WorkQueue workQueue) {
-    shuttingDown = false;
+    shutdownState.setIsShuttingDown(false);
     for (Source cfg : sources) {
       cfg.start(workQueue);
     }
@@ -91,9 +93,7 @@
    */
   @Override
   public int shutdown() {
-    synchronized (this) {
-      shuttingDown = true;
-    }
+    shutdownState.setIsShuttingDown(true);
 
     int discarded = 0;
     for (Source cfg : sources) {
@@ -109,7 +109,7 @@
 
   @Subscribe
   public synchronized void onReload(List<RemoteConfiguration> sourceConfigurations) {
-    if (shuttingDown) {
+    if (shutdownState.isShuttingDown()) {
       logger.atWarning().log("Shutting down: configuration reload ignored");
       return;
     }