Bug 1140812 - React to Backoff and Retry-After headers from Reading List storage servers. r=rnewman

========

cd7edfa0b5
Author: Nick Alexander <nalexander@mozilla.com>
    Bug 1140812 - Part 3: React to Backoff and Retry-After headers.

========

8581f5a572
Author: Nick Alexander <nalexander@mozilla.com>
Date:   Fri Mar 27 15:30:33 2015 -0700

    Bug 1140812 - Part 2: Include request in HTTP response observation callbacks.

    This allows to only handle responses from certain hosts.

========

05b50325db
Author: Nick Alexander <nalexander@mozilla.com>
Date:   Fri Mar 27 14:47:38 2015 -0700

    Bug 1140812 - Part 1: Generalize from one to many HTTP response observers.

    CopyOnWriteArrayList is a reasonable choice here: we have few writes but
    many iterations.  See
    http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CopyOnWriteArrayList.html

========

5950219343
Author: Nick Alexander <nalexander@mozilla.com>
Date:   Fri Mar 27 16:04:07 2015 -0700

    Bug 1140812 - Pre: Modernize backoffInSeconds.

    Sync uses X-Backoff; newer services, including Reading List, use Backoff.
This commit is contained in:
Nick Alexander
2015-03-27 16:01:36 -07:00
parent 844e5eb8fb
commit 165fbc34b2
8 changed files with 159 additions and 37 deletions

View File

@@ -59,6 +59,7 @@ import org.mozilla.gecko.sync.stage.UploadMetaGlobalStage;
import android.content.Context;
import ch.boye.httpclientandroidlib.HttpResponse;
import ch.boye.httpclientandroidlib.client.methods.HttpUriRequest;
public class GlobalSession implements HttpResponseObserver {
private static final String LOG_TAG = "GlobalSession";
@@ -1124,8 +1125,8 @@ public class GlobalSession implements HttpResponseObserver {
* requests.
*/
protected void installAsHttpResponseObserver() {
Logger.debug(LOG_TAG, "Installing " + this + " as BaseResource HttpResponseObserver.");
BaseResource.setHttpResponseObserver(this);
Logger.debug(LOG_TAG, "Adding " + this + " as a BaseResource HttpResponseObserver.");
BaseResource.addHttpResponseObserver(this);
largestBackoffObserved.set(-1);
}
@@ -1133,15 +1134,23 @@ public class GlobalSession implements HttpResponseObserver {
* Stop observing HttpResponses for backoff requests.
*/
protected void uninstallAsHttpResponseObserver() {
Logger.debug(LOG_TAG, "Uninstalling " + this + " as BaseResource HttpResponseObserver.");
BaseResource.setHttpResponseObserver(null);
Logger.debug(LOG_TAG, "Removing " + this + " as a BaseResource HttpResponseObserver.");
BaseResource.removeHttpResponseObserver(this);
}
/**
* Observe all HTTP response for backoff requests on all status codes, not just errors.
*/
@Override
public void observeHttpResponse(HttpResponse response) {
public void observeHttpResponse(HttpUriRequest request, HttpResponse response) {
// Ignore non-Sync storage requests.
final URI clusterURL = config.getClusterURL();
if (clusterURL != null && !clusterURL.getHost().equals(request.getURI().getHost())) {
// It's possible to see requests without a clusterURL (in particular,
// during testing); allow some extra backoffs in this case.
return;
}
long responseBackoff = (new SyncResponse(response)).totalBackoffInMilliseconds(); // TODO: don't allocate object?
if (responseBackoff <= 0) {
return;