Decouple observable queue implementation from ReplicationQueue Prior to this change, AutoReloadRunnable used to depend on ReplicationQueue, which was used just to observe the status of the queue during the run() phase of the reloading. Decouple reloading of configuration from specific queue implementations by depending only on a way to observe the queue, rather than the queue itself. Incidentally, allow AutoReloadRunnable to be reused by implementations that use a different queueing systems, or no queuing at all, such as the pull-replication. Change-Id: I589c5bf3fb49a53734ba3a991d08db33bc189d3e
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadRunnable.java b/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadRunnable.java index 5b7c148..a1084a8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadRunnable.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadRunnable.java
@@ -29,7 +29,7 @@ private final SitePaths site; private final Path pluginDataDir; private final EventBus eventBus; - private final Provider<ReplicationQueue> replicationQueue; + private final Provider<ObservableQueue> queueObserverProvider; private final ReplicationConfigValidator configValidator; private ReplicationFileBasedConfig loadedConfig; @@ -43,21 +43,21 @@ SitePaths site, @PluginData Path pluginDataDir, EventBus eventBus, - Provider<ReplicationQueue> replicationQueue) { + Provider<ObservableQueue> queueObserverProvider) { this.loadedConfig = config; this.loadedConfigVersion = config.getVersion(); this.lastFailedConfigVersion = ""; this.site = site; this.pluginDataDir = pluginDataDir; this.eventBus = eventBus; - this.replicationQueue = replicationQueue; + this.queueObserverProvider = queueObserverProvider; this.configValidator = configValidator; } @Override public synchronized void run() { String pendingConfigVersion = loadedConfig.getVersion(); - ReplicationQueue queue = replicationQueue.get(); + ObservableQueue queue = queueObserverProvider.get(); if (pendingConfigVersion.equals(loadedConfigVersion) || pendingConfigVersion.equals(lastFailedConfigVersion) || !queue.isRunning()
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ObservableQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ObservableQueue.java new file mode 100644 index 0000000..1007ae5 --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ObservableQueue.java
@@ -0,0 +1,32 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.googlesource.gerrit.plugins.replication; + +/** Allows a queue activity to be observed */ +public interface ObservableQueue { + /** + * Indicates whether the observed queue is running + * + * @return true, when the queue is running, false otherwise + */ + boolean isRunning(); + + /** + * Indicates whether the observed queue is replaying queued events + * + * @return true, when the queue is replaying, false otherwise + */ + boolean isReplaying(); +}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java index da2b1b5..979c8e3 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java
@@ -52,6 +52,7 @@ protected void configure() { install(new FactoryModuleBuilder().build(Destination.Factory.class)); bind(ReplicationQueue.class).in(Scopes.SINGLETON); + bind(ObservableQueue.class).to(ReplicationQueue.class); bind(LifecycleListener.class) .annotatedWith(UniqueAnnotations.create()) .to(ReplicationQueue.class);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java index 2dd2751..0d15d7c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
@@ -40,7 +40,8 @@ /** Manages automatic replication to remote repositories. */ public class ReplicationQueue - implements LifecycleListener, + implements ObservableQueue, + LifecycleListener, GitReferenceUpdatedListener, ProjectDeletedListener, HeadUpdatedListener { @@ -91,10 +92,12 @@ } } + @Override public boolean isRunning() { return running; } + @Override public boolean isReplaying() { return replaying; }