Bug 1291821 - Pre: remove unused SerialRecordConsumer r=rnewman draft
authorGrisha Kruglov <gkruglov@mozilla.com>
Sat, 08 Oct 2016 14:49:46 -0700
changeset 489481 d23b3f157fe7cf42e30a40c034970a355098c68c
parent 489279 6f2117c0b9895dfeb06fa74d2dc91bff660386ce
child 489482 b4ae0a3c286963f4c476c7c0ed768ad5a2b5bb8b
push id46825
push usergkruglov@mozilla.com
push dateFri, 24 Feb 2017 21:13:39 +0000
reviewersrnewman
bugs1291821
milestone54.0a1
Bug 1291821 - Pre: remove unused SerialRecordConsumer r=rnewman MozReview-Commit-ID: 3fiHVErUA1g
mobile/android/base/android-services.mozbuild
mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/SerialRecordConsumer.java
--- a/mobile/android/base/android-services.mozbuild
+++ b/mobile/android/base/android-services.mozbuild
@@ -1057,17 +1057,16 @@ sync_java_files = [TOPSRCDIR + '/mobile/
     'sync/SyncConfigurationException.java',
     'sync/SyncConstants.java',
     'sync/SyncException.java',
     'sync/synchronizer/ConcurrentRecordConsumer.java',
     'sync/synchronizer/RecordConsumer.java',
     'sync/synchronizer/RecordsChannel.java',
     'sync/synchronizer/RecordsChannelDelegate.java',
     'sync/synchronizer/RecordsConsumerDelegate.java',
-    'sync/synchronizer/SerialRecordConsumer.java',
     'sync/synchronizer/ServerLocalSynchronizer.java',
     'sync/synchronizer/ServerLocalSynchronizerSession.java',
     'sync/synchronizer/SessionNotBegunException.java',
     'sync/synchronizer/Synchronizer.java',
     'sync/synchronizer/SynchronizerDelegate.java',
     'sync/synchronizer/SynchronizerSession.java',
     'sync/synchronizer/SynchronizerSessionDelegate.java',
     'sync/synchronizer/UnbundleError.java',
deleted file mode 100644
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/SerialRecordConsumer.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.sync.synchronizer;
-
-import org.mozilla.gecko.background.common.log.Logger;
-import org.mozilla.gecko.sync.repositories.domain.Record;
-
-/**
- * Consume records from a queue inside a RecordsChannel, storing them serially.
- * @author rnewman
- *
- */
-class SerialRecordConsumer extends RecordConsumer {
-  private static final String LOG_TAG = "SerialRecordConsumer";
-  protected boolean stopEventually = false;
-  private volatile long counter = 0;
-
-  public SerialRecordConsumer(RecordsConsumerDelegate delegate) {
-    this.delegate = delegate;
-  }
-
-  private final Object monitor = new Object();
-  @Override
-  public void doNotify() {
-    synchronized (monitor) {
-      monitor.notify();
-    }
-  }
-
-  @Override
-  public void queueFilled() {
-    Logger.debug(LOG_TAG, "Queue filled.");
-    synchronized (monitor) {
-      this.stopEventually = true;
-      monitor.notify();
-    }
-  }
-
-  @Override
-  public void halt() {
-    Logger.debug(LOG_TAG, "Halting.");
-    synchronized (monitor) {
-      this.stopEventually = true;
-      this.stopImmediately = true;
-      monitor.notify();
-    }
-  }
-
-  private final Object storeSerializer = new Object();
-  @Override
-  public void stored() {
-    Logger.debug(LOG_TAG, "Record stored. Notifying.");
-    synchronized (storeSerializer) {
-      Logger.debug(LOG_TAG, "stored() took storeSerializer.");
-      counter++;
-      storeSerializer.notify();
-      Logger.debug(LOG_TAG, "stored() dropped storeSerializer.");
-    }
-  }
-  private void storeSerially(Record record) {
-    Logger.debug(LOG_TAG, "New record to store.");
-    synchronized (storeSerializer) {
-      Logger.debug(LOG_TAG, "storeSerially() took storeSerializer.");
-      Logger.debug(LOG_TAG, "Storing...");
-      try {
-        this.delegate.store(record);
-      } catch (Exception e) {
-        Logger.warn(LOG_TAG, "Got exception in store. Not waiting.", e);
-        return;      // So we don't block for a stored() that never comes.
-      }
-      try {
-        Logger.debug(LOG_TAG, "Waiting...");
-        storeSerializer.wait();
-      } catch (InterruptedException e) {
-        // TODO
-      }
-      Logger.debug(LOG_TAG, "storeSerially() dropped storeSerializer.");
-    }
-  }
-
-  private void consumerIsDone() {
-    long counterNow = this.counter;
-    Logger.info(LOG_TAG, "Consumer is done. Processed " + counterNow + ((counterNow == 1) ? " record." : " records."));
-    delegate.consumerIsDone(stopImmediately);
-  }
-
-  @Override
-  public void run() {
-    while (true) {
-      synchronized (monitor) {
-        Logger.debug(LOG_TAG, "run() took monitor.");
-        if (stopImmediately) {
-          Logger.debug(LOG_TAG, "Stopping immediately. Clearing queue.");
-          delegate.getQueue().clear();
-          Logger.debug(LOG_TAG, "Notifying consumer.");
-          consumerIsDone();
-          return;
-        }
-        Logger.debug(LOG_TAG, "run() dropped monitor.");
-      }
-      // The queue is concurrent-safe.
-      while (!delegate.getQueue().isEmpty()) {
-        Logger.debug(LOG_TAG, "Grabbing record...");
-        Record record = delegate.getQueue().remove();
-        // Block here, allowing us to process records
-        // serially.
-        Logger.debug(LOG_TAG, "Invoking storeSerially...");
-        this.storeSerially(record);
-        Logger.debug(LOG_TAG, "Done with record.");
-      }
-      synchronized (monitor) {
-        Logger.debug(LOG_TAG, "run() took monitor.");
-
-        if (stopEventually) {
-          Logger.debug(LOG_TAG, "Done with records and told to stop. Notifying consumer.");
-          consumerIsDone();
-          return;
-        }
-        try {
-          Logger.debug(LOG_TAG, "Not told to stop but no records. Waiting.");
-          monitor.wait(10000);
-        } catch (InterruptedException e) {
-          // TODO
-        }
-        Logger.debug(LOG_TAG, "run() dropped monitor.");
-      }
-    }
-  }
-}