com.amazonaws.mobileconnectors.cognito
Interface Dataset.SyncCallback

Enclosing interface:
Dataset

public static interface Dataset.SyncCallback

This is the callback used in Dataset.synchronize(SyncCallback).


Method Summary
 boolean onConflict(Dataset dataset, java.util.List<SyncConflict> conflicts)
          This can be triggered during two phases.
 boolean onDatasetDeleted(Dataset dataset, java.lang.String datasetName)
          This is triggered when the given dataset is deleted remotely.
 boolean onDatasetsMerged(Dataset dataset, java.util.List<java.lang.String> datasetNames)
          If two or more datasets are merged as a result of identity merge, this will be triggered.
 void onFailure(DataStorageException dse)
          This is called when an exception occurs during sync.
 void onSuccess(Dataset dataset, java.util.List<Record> updatedRecords)
          This is called after remote changes are downloaded to local storage and local changes are uploaded to remote storage.
 

Method Detail

onSuccess

void onSuccess(Dataset dataset,
               java.util.List<Record> updatedRecords)
This is called after remote changes are downloaded to local storage and local changes are uploaded to remote storage. Updated records from remote storage are passed in the callback. If conflicts occur during synchronize and are resolved in onConflict(com.amazonaws.mobileconnectors.cognito.Dataset, java.util.List) after several retries, then updatedRecords will be what are pulled down from remote in the last retry.

Parameters:
dataset - the dataset that performed sync
updatedRecords - new records from remote storage that are downloaded

onConflict

boolean onConflict(Dataset dataset,
                   java.util.List<SyncConflict> conflicts)
This can be triggered during two phases. One is when the remote changes are about to be written to local storage. The other is when local changes are uploaded to remote storage and got rejected. Here is an example:
 List<Record> resolved = new ArrayList<Record>();
 for (SyncConflict conflict : conflicts) {
     resolved.add(conflicts.resolveWithRemoteRecord());
 }
 dataset.save(resolved);
 return true; // so that synchronize() can retry
 
If you prefer to add additional logic when resolving conflict, you can use SyncConflict.resolveWithValue(String)
 int remoteMoney = Integer.valueOf(conflicts.getRemote().getValue());
 int localMoney = Integer.valueOf(conflicts.getLocal().getValue());
 int total = remoteMoney + localMoney;
 Record resolve = conflicts.resolveWithValue(String.valueOf(total));
 

Parameters:
dataset - the dataset that performed sync
conflicts - conflicting records
Returns:
true if conflicts are resolved so that synchronize will retry, false otherwise.

onDatasetDeleted

boolean onDatasetDeleted(Dataset dataset,
                         java.lang.String datasetName)
This is triggered when the given dataset is deleted remotely. Return true if you want to remove local dataset, or false if you want to keep it.

Parameters:
dataset - dataset handler
datasetName - the name of the dataset that is deleted remotely
Returns:
true to remove local dataset, or false to keep it

onDatasetsMerged

boolean onDatasetsMerged(Dataset dataset,
                         java.util.List<java.lang.String> datasetNames)
If two or more datasets are merged as a result of identity merge, this will be triggered. A list of names of merged datasets' is passed in. The merged dataset name will be appended with its old identity id. One can open the merged dataset, synchronize the content, reconcile with the current dataset, and remove it. This callback will fire off until the merged dataset is removed.

Parameters:
dataset - dataset handler
datasetNames - a list of names of merged datasets'
Returns:

onFailure

void onFailure(DataStorageException dse)
This is called when an exception occurs during sync.

Parameters:
dse - exception


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.