Merge branch 'stable-3.1' into stable-3.2

* stable-3.1:
  Inject EventDispatcher as DynamicItem

Change-Id: I04bacde57ee3fa219662a9d4bb4a2b93fb185789
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandler.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandler.java
index 278ba4e..dcfd1b0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandler.java
@@ -14,6 +14,7 @@
 
 package com.googlesource.gerrit.plugins.multisite.forwarder;
 
+import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.server.events.Event;
 import com.google.gerrit.server.events.EventDispatcher;
 import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -33,11 +34,12 @@
 public class ForwardedEventHandler {
   private static final Logger log = LoggerFactory.getLogger(ForwardedEventHandler.class);
 
-  private final EventDispatcher dispatcher;
+  private final DynamicItem<EventDispatcher> dispatcher;
   private final OneOffRequestContext oneOffCtx;
 
   @Inject
-  public ForwardedEventHandler(EventDispatcher dispatcher, OneOffRequestContext oneOffCtx) {
+  public ForwardedEventHandler(
+      DynamicItem<EventDispatcher> dispatcher, OneOffRequestContext oneOffCtx) {
     this.dispatcher = dispatcher;
     this.oneOffCtx = oneOffCtx;
   }
@@ -51,7 +53,7 @@
     try (ManualRequestContext ctx = oneOffCtx.open()) {
       Context.setForwardedEvent(true);
       log.debug("dispatching event {}", event.getType());
-      dispatcher.postEvent(event);
+      dispatcher.get().postEvent(event);
     } finally {
       Context.unsetForwardedEvent();
     }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java
index 387fc41..704401b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedEventHandlerTest.java
@@ -18,8 +18,10 @@
 import static com.google.gerrit.testing.GerritJUnit.assertThrows;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import com.google.gerrit.exceptions.StorageException;
+import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.server.events.Event;
 import com.google.gerrit.server.events.EventDispatcher;
 import com.google.gerrit.server.events.ProjectCreatedEvent;
@@ -37,13 +39,15 @@
 public class ForwardedEventHandlerTest {
 
   @Rule public ExpectedException exception = ExpectedException.none();
+  @Mock private DynamicItem<EventDispatcher> dispatcherMockItem;
   @Mock private EventDispatcher dispatcherMock;
   @Mock OneOffRequestContext oneOffCtxMock;
   private ForwardedEventHandler handler;
 
   @Before
   public void setUp() throws Exception {
-    handler = new ForwardedEventHandler(dispatcherMock, oneOffCtxMock);
+    when(dispatcherMockItem.get()).thenReturn(dispatcherMock);
+    handler = new ForwardedEventHandler(dispatcherMockItem, oneOffCtxMock);
   }
 
   @Test