michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.sync.synchronizer; michael@0: michael@0: import org.mozilla.gecko.background.common.log.Logger; michael@0: import org.mozilla.gecko.sync.repositories.FetchFailedException; michael@0: import org.mozilla.gecko.sync.repositories.StoreFailedException; michael@0: michael@0: /** michael@0: * A SynchronizerSession designed to be used between a remote michael@0: * server and a local repository. michael@0: *

michael@0: * Handles failure cases as follows (in the order they will occur during a sync): michael@0: *

michael@0: */ michael@0: public class ServerLocalSynchronizerSession extends SynchronizerSession { michael@0: protected static final String LOG_TAG = "ServLocSynchronizerSess"; michael@0: michael@0: public ServerLocalSynchronizerSession(Synchronizer synchronizer, SynchronizerSessionDelegate delegate) { michael@0: super(synchronizer, delegate); michael@0: } michael@0: michael@0: public void onFirstFlowCompleted(RecordsChannel recordsChannel, long fetchEnd, long storeEnd) { michael@0: // Fetch failures always abort. michael@0: int numRemoteFetchFailed = recordsChannel.getFetchFailureCount(); michael@0: if (numRemoteFetchFailed > 0) { michael@0: final String message = "Got " + numRemoteFetchFailed + " failures fetching remote records!"; michael@0: Logger.warn(LOG_TAG, message + " Aborting session."); michael@0: delegate.onSynchronizeFailed(this, new FetchFailedException(), message); michael@0: return; michael@0: } michael@0: Logger.trace(LOG_TAG, "No failures fetching remote records."); michael@0: michael@0: // Local store failures are ignored. michael@0: int numLocalStoreFailed = recordsChannel.getStoreFailureCount(); michael@0: if (numLocalStoreFailed > 0) { michael@0: final String message = "Got " + numLocalStoreFailed + " failures storing local records!"; michael@0: Logger.warn(LOG_TAG, message + " Ignoring local store failures and continuing synchronizer session."); michael@0: } else { michael@0: Logger.trace(LOG_TAG, "No failures storing local records."); michael@0: } michael@0: michael@0: super.onFirstFlowCompleted(recordsChannel, fetchEnd, storeEnd); michael@0: } michael@0: michael@0: public void onSecondFlowCompleted(RecordsChannel recordsChannel, long fetchEnd, long storeEnd) { michael@0: // Fetch failures always abort. michael@0: int numLocalFetchFailed = recordsChannel.getFetchFailureCount(); michael@0: if (numLocalFetchFailed > 0) { michael@0: final String message = "Got " + numLocalFetchFailed + " failures fetching local records!"; michael@0: Logger.warn(LOG_TAG, message + " Aborting session."); michael@0: delegate.onSynchronizeFailed(this, new FetchFailedException(), message); michael@0: return; michael@0: } michael@0: Logger.trace(LOG_TAG, "No failures fetching local records."); michael@0: michael@0: // Remote store failures abort! michael@0: int numRemoteStoreFailed = recordsChannel.getStoreFailureCount(); michael@0: if (numRemoteStoreFailed > 0) { michael@0: final String message = "Got " + numRemoteStoreFailed + " failures storing remote records!"; michael@0: Logger.warn(LOG_TAG, message + " Aborting session."); michael@0: delegate.onSynchronizeFailed(this, new StoreFailedException(), message); michael@0: return; michael@0: } michael@0: Logger.trace(LOG_TAG, "No failures storing remote records."); michael@0: michael@0: super.onSecondFlowCompleted(recordsChannel, fetchEnd, storeEnd); michael@0: } michael@0: }