PushOne: Factor metrics out to a separate class

Instead of being an inner class, make it a package class and rename it to
be more generic. This will allow to add other measurements in addition to
the replication execution time.

Change-Id: Icda4053ed240e8193e15e8e94db208dcab2ec07e
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
index a6360ae..85b9ed7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
@@ -24,9 +24,6 @@
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Sets;
 import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
-import com.google.gerrit.metrics.Description;
-import com.google.gerrit.metrics.Field;
-import com.google.gerrit.metrics.MetricMaker;
 import com.google.gerrit.metrics.Timer1;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.reviewdb.client.RefNames;
@@ -43,7 +40,6 @@
 import com.google.gwtorm.server.OrmException;
 import com.google.gwtorm.server.SchemaFactory;
 import com.google.inject.Inject;
-import com.google.inject.Singleton;
 import com.google.inject.assistedinject.Assisted;
 
 import com.googlesource.gerrit.plugins.replication.ReplicationState.RefPushResult;
@@ -116,7 +112,7 @@
   private int lockRetryCount;
   private final int id;
   private final long createdAt;
-  private final ExecTimeMetric execTimeMetric;
+  private final ReplicationMetrics metrics;
 
   @Inject
   PushOne(final GitRepositoryManager grm,
@@ -130,7 +126,7 @@
       final ReplicationQueue rq,
       final IdGenerator ig,
       final ReplicationStateListener sl,
-      final ExecTimeMetric etm,
+      final ReplicationMetrics m,
       @Assisted final Project.NameKey d,
       @Assisted final URIish u) {
     gitManager = grm;
@@ -149,7 +145,7 @@
     id = ig.next();
     stateLog = sl;
     createdAt = System.nanoTime();
-    execTimeMetric = etm;
+    metrics = m;
   }
 
   @Override
@@ -290,7 +286,7 @@
     }
 
     repLog.info("Replication to " + uri + " started...");
-    Timer1.Context context = execTimeMetric.start(config.getName());
+    Timer1.Context context = metrics.start(config.getName());
     try {
       long startedAt = context.getStartTime();
       git = gitManager.openRepository(projectName);
@@ -357,25 +353,6 @@
     }
   }
 
-  @Singleton
-  public static class ExecTimeMetric {
-    Timer1<String> execTime;
-
-    @Inject
-    ExecTimeMetric(MetricMaker metricMaker) {
-      execTime = metricMaker.newTimer(
-          "replication_latency",
-          new Description("Time spent pushing to remote destination.")
-            .setCumulative()
-            .setUnit(Description.Units.SECONDS),
-          Field.ofString("destination"));
-    }
-
-    Timer1.Context start(String name) {
-      return execTime.start(name);
-    }
-  }
-
   private void createRepository() {
     if (pool.isCreateMissingRepos()) {
       try {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationMetrics.java
new file mode 100644
index 0000000..ad266da
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationMetrics.java
@@ -0,0 +1,42 @@
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.replication;
+
+import com.google.gerrit.metrics.Description;
+import com.google.gerrit.metrics.Field;
+import com.google.gerrit.metrics.MetricMaker;
+import com.google.gerrit.metrics.Timer1;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+public class ReplicationMetrics {
+  Timer1<String> executionTime;
+
+  @Inject
+  ReplicationMetrics(MetricMaker metricMaker) {
+    executionTime = metricMaker.newTimer(
+        "replication_latency",
+        new Description("Time spent pushing to remote destination.")
+          .setCumulative()
+          .setUnit(Description.Units.SECONDS),
+        Field.ofString("destination"));
+  }
+
+  Timer1.Context start(String name) {
+    return executionTime.start(name);
+  }
+
+}