Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.sync.synchronizer; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 8 | import org.mozilla.gecko.sync.repositories.FetchFailedException; |
michael@0 | 9 | import org.mozilla.gecko.sync.repositories.StoreFailedException; |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * A <code>SynchronizerSession</code> designed to be used between a remote |
michael@0 | 13 | * server and a local repository. |
michael@0 | 14 | * <p> |
michael@0 | 15 | * Handles failure cases as follows (in the order they will occur during a sync): |
michael@0 | 16 | * <ul> |
michael@0 | 17 | * <li>Remote fetch failures abort.</li> |
michael@0 | 18 | * <li>Local store failures are ignored.</li> |
michael@0 | 19 | * <li>Local fetch failures abort.</li> |
michael@0 | 20 | * <li>Remote store failures abort.</li> |
michael@0 | 21 | * </ul> |
michael@0 | 22 | */ |
michael@0 | 23 | public class ServerLocalSynchronizerSession extends SynchronizerSession { |
michael@0 | 24 | protected static final String LOG_TAG = "ServLocSynchronizerSess"; |
michael@0 | 25 | |
michael@0 | 26 | public ServerLocalSynchronizerSession(Synchronizer synchronizer, SynchronizerSessionDelegate delegate) { |
michael@0 | 27 | super(synchronizer, delegate); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | public void onFirstFlowCompleted(RecordsChannel recordsChannel, long fetchEnd, long storeEnd) { |
michael@0 | 31 | // Fetch failures always abort. |
michael@0 | 32 | int numRemoteFetchFailed = recordsChannel.getFetchFailureCount(); |
michael@0 | 33 | if (numRemoteFetchFailed > 0) { |
michael@0 | 34 | final String message = "Got " + numRemoteFetchFailed + " failures fetching remote records!"; |
michael@0 | 35 | Logger.warn(LOG_TAG, message + " Aborting session."); |
michael@0 | 36 | delegate.onSynchronizeFailed(this, new FetchFailedException(), message); |
michael@0 | 37 | return; |
michael@0 | 38 | } |
michael@0 | 39 | Logger.trace(LOG_TAG, "No failures fetching remote records."); |
michael@0 | 40 | |
michael@0 | 41 | // Local store failures are ignored. |
michael@0 | 42 | int numLocalStoreFailed = recordsChannel.getStoreFailureCount(); |
michael@0 | 43 | if (numLocalStoreFailed > 0) { |
michael@0 | 44 | final String message = "Got " + numLocalStoreFailed + " failures storing local records!"; |
michael@0 | 45 | Logger.warn(LOG_TAG, message + " Ignoring local store failures and continuing synchronizer session."); |
michael@0 | 46 | } else { |
michael@0 | 47 | Logger.trace(LOG_TAG, "No failures storing local records."); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | super.onFirstFlowCompleted(recordsChannel, fetchEnd, storeEnd); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | public void onSecondFlowCompleted(RecordsChannel recordsChannel, long fetchEnd, long storeEnd) { |
michael@0 | 54 | // Fetch failures always abort. |
michael@0 | 55 | int numLocalFetchFailed = recordsChannel.getFetchFailureCount(); |
michael@0 | 56 | if (numLocalFetchFailed > 0) { |
michael@0 | 57 | final String message = "Got " + numLocalFetchFailed + " failures fetching local records!"; |
michael@0 | 58 | Logger.warn(LOG_TAG, message + " Aborting session."); |
michael@0 | 59 | delegate.onSynchronizeFailed(this, new FetchFailedException(), message); |
michael@0 | 60 | return; |
michael@0 | 61 | } |
michael@0 | 62 | Logger.trace(LOG_TAG, "No failures fetching local records."); |
michael@0 | 63 | |
michael@0 | 64 | // Remote store failures abort! |
michael@0 | 65 | int numRemoteStoreFailed = recordsChannel.getStoreFailureCount(); |
michael@0 | 66 | if (numRemoteStoreFailed > 0) { |
michael@0 | 67 | final String message = "Got " + numRemoteStoreFailed + " failures storing remote records!"; |
michael@0 | 68 | Logger.warn(LOG_TAG, message + " Aborting session."); |
michael@0 | 69 | delegate.onSynchronizeFailed(this, new StoreFailedException(), message); |
michael@0 | 70 | return; |
michael@0 | 71 | } |
michael@0 | 72 | Logger.trace(LOG_TAG, "No failures storing remote records."); |
michael@0 | 73 | |
michael@0 | 74 | super.onSecondFlowCompleted(recordsChannel, fetchEnd, storeEnd); |
michael@0 | 75 | } |
michael@0 | 76 | } |