in aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AWSAppSyncDeltaSync.java [426:487]
void runBaseQuery(final ResponseFetcher fetchPolicy) {
final CountDownLatch baseQueryCountdownLatch = new CountDownLatch(1);
final long baseQueryInitiationTime = System.currentTimeMillis();
//Setup an internal callback for the hand off
GraphQLCall.Callback<Query.Data> cb = new GraphQLCall.Callback<Query.Data>() {
@Override
public void onResponse(@Nonnull final Response<Query.Data> response) {
Log.v(TAG, "Delta Sync: Base query response received");
if (AppSyncResponseFetchers.NETWORK_ONLY.equals(fetchPolicy)) {
//Setup the scheduler for a future Sync
scheduleFutureSync(baseQueryInitiationTime);
//Update lastRunTime
lastRunTimeInMilliSeconds = baseQueryInitiationTime;
dbHelper.updateLastRunTime(id,lastRunTimeInMilliSeconds);
Log.v(TAG, "Delta Sync: Updating lastRunTime to [" + lastRunTimeInMilliSeconds + "]");
}
dbHelper.updateLastRunTime(id,lastRunTimeInMilliSeconds);
if (baseQueryCallback != null ) {
baseQueryCallback.onResponse(response);
}
Log.v(TAG, "Delta Sync: Base query response propagated");
baseQueryCountdownLatch.countDown();
}
@Override
public void onFailure(@Nonnull final ApolloException e) {
Log.e(TAG, "Delta Query: BaseQuery failed with [" + e.getLocalizedMessage() +"]");
e.printStackTrace();
deltaSyncOperationFailed = true;
if (baseQueryCallback != null ) {
baseQueryCallback.onFailure(e);
}
baseQueryCountdownLatch.countDown();
}
};
if (AppSyncResponseFetchers.CACHE_ONLY.equals(fetchPolicy)) {
Log.v(TAG, "Delta Sync: executing base query from cache");
}
else {
Log.v(TAG, "Delta Sync: executing base query from network");
}
//Execute the base query.
awsAppSyncClient.query(baseQuery)
.responseFetcher(fetchPolicy)
.enqueue(cb);
try {
baseQueryCountdownLatch.await();
}
catch (InterruptedException iex) {
Log.e(TAG, "Delta Sync: Base Query wait failed with [" + iex + "]");
deltaSyncOperationFailed = true;
}
}