Adjust to updated EventDispatcher interface

Change-Id: I147248ccf5b7f33252473473c181cb148d5d4eee
diff --git a/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBroker.java b/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBroker.java
index f869097..5414c9d 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBroker.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBroker.java
@@ -18,10 +18,12 @@
 import com.google.gerrit.common.EventListener;
 import com.google.gerrit.common.UserScopedEventListener;
 import com.google.gerrit.extensions.registration.DynamicSet;
+import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.events.Event;
 import com.google.gerrit.server.notedb.ChangeNotes.Factory;
 import com.google.gerrit.server.project.ProjectCache;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 
 public class SyncEventBroker extends EventBroker {
 
@@ -29,8 +31,10 @@
   public SyncEventBroker(DynamicSet<UserScopedEventListener> listeners,
       DynamicSet<EventListener> unrestrictedListeners,
       ProjectCache projectCache,
-      Factory notesFactory) {
-    super(listeners, unrestrictedListeners, projectCache, notesFactory);
+      Factory notesFactory,
+      Provider<ReviewDb> dbProvider) {
+    super(listeners, unrestrictedListeners, projectCache, notesFactory,
+        dbProvider);
   }
 
   @Override
diff --git a/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServlet.java
index cbb903d..d83579b 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServlet.java
@@ -23,14 +23,12 @@
 import com.google.common.io.CharStreams;
 import com.google.common.net.MediaType;
 import com.google.gerrit.common.EventDispatcher;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.events.Event;
 import com.google.gerrit.server.events.EventDeserializer;
 import com.google.gerrit.server.events.SupplierDeserializer;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gwtorm.server.OrmException;
-import com.google.gwtorm.server.SchemaFactory;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
@@ -51,13 +49,10 @@
       .getLogger(SyncEventsRestApiServlet.class);
 
   private final EventDispatcher dispatcher;
-  private final SchemaFactory<ReviewDb> schema;
 
   @Inject
-  SyncEventsRestApiServlet(EventDispatcher dispatcher,
-      SchemaFactory<ReviewDb> schema) {
+  SyncEventsRestApiServlet(EventDispatcher dispatcher) {
     this.dispatcher = dispatcher;
-    this.schema = schema;
   }
 
   @Override
@@ -68,9 +63,7 @@
     try {
       Context.setForwardedEvent();
       Event event = getEventFromRequest(req);
-      try (ReviewDb db = schema.open()) {
-        dispatcher.postEvent(event, db);
-      }
+      dispatcher.postEvent(event);
       rsp.setStatus(SC_NO_CONTENT);
     } catch (OrmException e) {
       rsp.sendError(SC_NOT_FOUND, "Change not found\n");
diff --git a/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBrokerTest.java b/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBrokerTest.java
index f8a6e39..fa304e8 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBrokerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventBrokerTest.java
@@ -33,7 +33,7 @@
     listenerMock = createMock(EventListener.class);
     DynamicSet<EventListener> listeners = DynamicSet.emptySet();
     listeners.add(listenerMock);
-    broker = new SyncEventBroker(null, listeners, null, null);
+    broker = new SyncEventBroker(null, listeners, null, null, null);
   }
 
   @Test
diff --git a/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServletTest.java
index 37de2db..ecf73b9 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/syncevents/SyncEventsRestApiServletTest.java
@@ -14,8 +14,8 @@
 
 package com.ericsson.gerrit.plugins.syncevents;
 
-import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
 import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
+import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.isA;
@@ -23,12 +23,10 @@
 import com.google.common.net.MediaType;
 import com.google.gerrit.common.EventDispatcher;
 import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.events.EventTypes;
 import com.google.gerrit.server.events.RefEvent;
 import com.google.gwtorm.client.KeyUtil;
 import com.google.gwtorm.server.OrmException;
-import com.google.gwtorm.server.SchemaFactory;
 import com.google.gwtorm.server.StandardKeyEncoder;
 
 import org.easymock.EasyMockSupport;
@@ -58,11 +56,7 @@
 
   @Before
   public void createSyncEventsRestApiServlet() throws Exception {
-    @SuppressWarnings("unchecked")
-    SchemaFactory<ReviewDb> schema = createNiceMock(SchemaFactory.class);
-    ReviewDb db = createNiceMock(ReviewDb.class);
-    expect(schema.open()).andReturn(db).anyTimes();
-    syncEventsRestApiServlet = new SyncEventsRestApiServlet(dispatcher, schema);
+    syncEventsRestApiServlet = new SyncEventsRestApiServlet(dispatcher);
     req = createNiceMock(HttpServletRequest.class);
     rsp = createNiceMock(HttpServletResponse.class);
     expect(req.getContentType()).andReturn(MediaType.JSON_UTF_8.toString());
@@ -75,7 +69,7 @@
         + "\"ref-replication-done\",\"eventCreatedOn\":1451415011}";
     expect(req.getReader())
         .andReturn(new BufferedReader(new StringReader(event)));
-    dispatcher.postEvent(isA(RefReplicationDoneEvent.class), isA(ReviewDb.class));
+    dispatcher.postEvent(isA(RefReplicationDoneEvent.class));
     rsp.setStatus(SC_NO_CONTENT);
     expectLastCall().once();
     replayAll();
@@ -91,7 +85,7 @@
         + "\"ref-replication-done\",\"eventCreatedOn\":1451415011}";
     expect(req.getReader())
         .andReturn(new BufferedReader(new StringReader(event)));
-    dispatcher.postEvent(isA(RefReplicationDoneEvent.class), isA(ReviewDb.class));
+    dispatcher.postEvent(isA(RefReplicationDoneEvent.class));
     expectLastCall().andThrow(new OrmException("some Error"));
     rsp.sendError(SC_NOT_FOUND, "Change not found\n");
     expectLastCall().once();