Make SharedRefDatabaseWrapper a singleton
The SharedRefDatabaseWrapper has optional injections on one of its
fields (sharedRefDbDynamicItem) which is resolved at the multi-site
and high-availability plugins startup phase.
The initial instance created during the plugin startup was injected
correctly thanks to the explicit call to inject fields; however, because
the SharedRefDatabaseWrapper was not a singleton, the subsequent
injections were done without the optional field, causing unexpected
behaviours.
Having a common singleton everywhere assures that the members injection
performed at startup would apply to all uses of SharedRefDatabaseWrapper.
Change-Id: Idb32bbd179629221d8d21c2986a1ad4b9f9077bf
diff --git a/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapper.java b/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapper.java
index cf0a727..c3b41e8 100644
--- a/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapper.java
+++ b/src/main/java/com/gerritforge/gerrit/globalrefdb/validation/SharedRefDatabaseWrapper.java
@@ -24,6 +24,7 @@
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.metrics.Timer0.Context;
import com.google.inject.Inject;
+import com.google.inject.Singleton;
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@@ -33,6 +34,7 @@
* binding. Such instance is bound optionally and, in case no explicit binding is registered a
* {@link NoopSharedRefDatabase} instance is wrapped instead.
*/
+@Singleton
public class SharedRefDatabaseWrapper implements GlobalRefDatabase {
private static final FluentLogger log = FluentLogger.forEnclosingClass();
private static final GlobalRefDatabase NOOP_REFDB = new NoopSharedRefDatabase();