Fix pull-replication plugin startup which was always failing The startup of the pull-replication plugin was constantly failing because the DynamicItem brokerApi was never an instance of ExtendedBrokerApi, which is expected: they are always different types and represent different classes. The error was not spotted during review because of the incorrect naming of the DynamicItem as eventsBroker, which is a bad name because it isn't the broker but just a DynamicItem pointing to a broker. Rename eventsBroker as eventsBrokerDi and check for the real brokerApi being an instance of ExtendedBrokerApi. Change-Id: I42f1738dcffcf438e5bd2a0b6978e098f838fdad
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java index 13b038e..a21a48c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/event/EventsBrokerMessageConsumer.java
@@ -34,7 +34,7 @@ public class EventsBrokerMessageConsumer implements Consumer<Event>, LifecycleListener { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - private final DynamicItem<BrokerApi> eventsBroker; + private final DynamicItem<BrokerApi> eventsBrokerDi; private final StreamEventListener eventListener; private final ShutdownState shutdownState; private final String eventsTopicName; @@ -48,7 +48,7 @@ @Named(STREAM_EVENTS_TOPIC_NAME) String eventsTopicName, @Nullable @Named(STREAM_EVENTS_GROUP_ID) String groupId) { - this.eventsBroker = eventsBroker; + this.eventsBrokerDi = eventsBroker; this.eventListener = eventListener; this.shutdownState = shutdownState; this.eventsTopicName = eventsTopicName; @@ -67,18 +67,18 @@ @Override public void start() { - BrokerApi brokerApi = eventsBroker.get(); + BrokerApi brokerApi = eventsBrokerDi.get(); if (groupId == null) { brokerApi.receiveAsync(eventsTopicName, this); return; } - if (!(eventsBroker instanceof ExtendedBrokerApi)) { + if (!(brokerApi instanceof ExtendedBrokerApi)) { throw new IllegalArgumentException( String.format( "Failed to load the pull-replication plugin: %s does not support the custom group-id '%s'.\n" + "Remove replication.eventBrokerGroupId from replication.config or install a different event-broker plugin.", - eventsBroker.getClass(), groupId)); + brokerApi.getClass(), groupId)); } ((ExtendedBrokerApi) brokerApi).receiveAsync(eventsTopicName, groupId, this); @@ -87,6 +87,6 @@ @Override public void stop() { shutdownState.setIsShuttingDown(true); - eventsBroker.get().disconnect(); + eventsBrokerDi.get().disconnect(); } }