Fix race condition when scheduling a replication

The state of PushOne object was modified after the operation was scheduled.
Depending on the delay parameter the PushOne.run() could be called before (when
the delay is zero or close to zero) or after (longer delay) the current thread
calls e.addState(ref, state). Thus, the thread executing PushOne.run() may or
may not see the update of its stateMap. Further, the stateMap is a
LinkedListMultimap which is not thread safe and the PushOne doesn't synchronize
access to it.

Change-Id: Ib26a5933a7993a6d2f0501e5daaf06a7892e597f
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index 603a70f..dd401af 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -295,13 +295,14 @@
       if (e == null) {
         e = opFactory.create(project, uri);
         addRef(e, ref);
+        e.addState(ref, state);
         pool.schedule(e, config.getDelay(), TimeUnit.SECONDS);
         pending.put(uri, e);
       } else if (!e.getRefs().contains(ref)) {
         addRef(e, ref);
+        e.addState(ref, state);
       }
       state.increasePushTaskCount(project.get(), ref);
-      e.addState(ref, state);
       repLog.info("scheduled {}:{} => {} to run after {}s", project, ref, e, config.getDelay());
     }
   }