Bug 1270213 - Update TelemetryUploadService to use doc ID. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 05 May 2016 16:52:58 -0700
changeset 364564 7585177671f75e6cd1a362e9ecaf4570c427dc4d
parent 364563 51271da24968ce2e6e7653c430dcaa5373b4f4a9
child 364565 c767ced9fc0db064522fb88740723cfc9d8025d7
push id17492
push usermichael.l.comella@gmail.com
push dateFri, 06 May 2016 21:43:40 +0000
reviewerssebastian
bugs1270213
milestone49.0a1
Bug 1270213 - Update TelemetryUploadService to use doc ID. r=sebastian This is not yet expected to compile. MozReview-Commit-ID: FQF6z5ni6jC
mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
@@ -22,16 +22,17 @@ import org.mozilla.gecko.telemetry.store
 import org.mozilla.gecko.util.NetworkUtils;
 import org.mozilla.gecko.util.StringUtils;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.security.GeneralSecurityException;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 /**
  * The service that handles retrieving a list of telemetry pings to upload from the given
  * {@link TelemetryPingStore}, uploading those payloads to the associated server, and reporting
  * back to the Store which uploads were a success.
  */
 public class TelemetryUploadService extends IntentService {
@@ -80,21 +81,21 @@ public class TelemetryUploadService exte
      */
     private static boolean uploadPendingPingsFromStore(final Context context, final TelemetryPingStore store) {
         final List<TelemetryPing> pingsToUpload = store.getAllPings();
         if (pingsToUpload.isEmpty()) {
             return true;
         }
 
         final String serverSchemeHostPort = getServerSchemeHostPort(context);
-        final HashSet<Integer> successfulUploadIDs = new HashSet<>(pingsToUpload.size()); // used for side effects.
+        final HashSet<String> successfulUploadIDs = new HashSet<>(pingsToUpload.size()); // used for side effects.
         final PingResultDelegate delegate = new PingResultDelegate(successfulUploadIDs);
         for (final TelemetryPing ping : pingsToUpload) {
             // TODO: It'd be great to re-use the same HTTP connection for each upload request.
-            delegate.setPingID(ping.getUniqueID());
+            delegate.setDocID(ping.getDocID());
             final String url = serverSchemeHostPort + "/" + ping.getURLPath();
             uploadPayload(url, ping.getPayload(), delegate);
 
             // There are minimal gains in trying to upload if we already failed one attempt.
             if (delegate.hadConnectionError()) {
                 break;
             }
         }
@@ -220,60 +221,60 @@ public class TelemetryUploadService exte
      * We use mutation on the set ID and the successful upload array to avoid object allocation.
      */
     private static class PingResultDelegate extends ResultDelegate {
         // We persist pings and don't need to worry about losing data so we keep these
         // durations short to save resources (e.g. battery).
         private static final int SOCKET_TIMEOUT_MILLIS = (int) TimeUnit.SECONDS.toMillis(30);
         private static final int CONNECTION_TIMEOUT_MILLIS = (int) TimeUnit.SECONDS.toMillis(30);
 
-        /** The store ID of the ping currently being uploaded. Use {@link #getPingID()} to access it. */
-        private int pingID = -1;
-        private final HashSet<Integer> successfulUploadIDs;
+        /** The store ID of the ping currently being uploaded. Use {@link #getDocID()} to access it. */
+        private String docID = null;
+        private final Set<String> successfulUploadIDs;
 
         private boolean hadConnectionError = false;
 
-        public PingResultDelegate(final HashSet<Integer> successfulUploadIDs) {
+        public PingResultDelegate(final Set<String> successfulUploadIDs) {
             super();
             this.successfulUploadIDs = successfulUploadIDs;
         }
 
         @Override
         public int socketTimeout() {
             return SOCKET_TIMEOUT_MILLIS;
         }
 
         @Override
         public int connectionTimeout() {
             return CONNECTION_TIMEOUT_MILLIS;
         }
 
-        private int getPingID() {
-            if (pingID < 0) {
+        private String getDocID() {
+            if (docID == null) {
                 throw new IllegalStateException("Expected ping ID to have been updated before retrieval");
             }
-            return pingID;
+            return docID;
         }
 
-        public void setPingID(final int id) {
-            pingID = id;
+        public void setDocID(final String id) {
+            docID = id;
         }
 
         @Override
         public String getUserAgent() {
             return TelemetryConstants.USER_AGENT;
         }
 
         @Override
         public void handleHttpResponse(final HttpResponse response) {
             final int status = response.getStatusLine().getStatusCode();
             switch (status) {
                 case 200:
                 case 201:
-                    successfulUploadIDs.add(getPingID());
+                    successfulUploadIDs.add(getDocID());
                     break;
                 default:
                     Log.w(LOGTAG, "Telemetry upload failure. HTTP status: " + status);
                     hadConnectionError = true;
             }
         }
 
         @Override