@Override public void run() { Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: processing Mutations"); Message message = new Message(); message.obj = new MutationInterceptorMessage(); message.what = MessageNumberUtil.SUCCESSFUL_EXEC; queueHandler.sendMessage(message); queueHandler.postDelayed(this, QUEUE_POLL_INTERVAL); } }, QUEUE_POLL_INTERVAL);
@Override public void onFailure(@Nonnull ApolloException e) { Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: onFailure() " + e.getLocalizedMessage()); if (e instanceof ApolloNetworkException ) { //Happened due to a network error. Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Network Exception " + e.getLocalizedMessage()); Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Will retry mutation when back on network"); queueHandler.setMutationInProgressStatusToFalse(); return; } shouldRetry = false; //Call the customer's callback customerCallBack.onFailure(e); //Set the mutation as completed. appSyncOfflineMutationManager.setInProgressMutationAsCompleted(recordIdentifier); //Send a message to the QueueHandler to process the next mutation in queue Message message = new Message(); message.obj = new MutationInterceptorMessage(originalMutation, currentMutation); message.what = MessageNumberUtil.FAIL_EXEC; queueHandler.sendMessage(message); return; }
@Override public void handleMessage(Message msg) { if (msg.what == MSG_CHECK) { // remove messages of the same type networkUpdateHandler.removeMessages(MSG_CHECK); // set shouldProcess to true Log.d(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Internet CONNECTED."); synchronized (shouldProcessMutationsLock) { shouldProcessMutations = true; } // Send EXEC message to queueHandler if (queueHandler != null ) { Message message = new Message(); message.obj = new MutationInterceptorMessage(); message.what = MessageNumberUtil.SUCCESSFUL_EXEC; queueHandler.sendMessage(message); } //Trigger DeltaSync to handle Network up events. AWSAppSyncDeltaSync.handleNetworkUpEvent(); } else if (msg.what == MSG_DISCONNECT) { // Network Disconnected, pause mutations Log.d(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Internet DISCONNECTED."); synchronized (shouldProcessMutationsLock) { shouldProcessMutations = false; } //Propagate network down event to DeltaSync AWSAppSyncDeltaSync.handleNetworkDownEvent(); } } }
message.obj = new MutationInterceptorMessage(); message.what = MessageNumberUtil.SUCCESSFUL_EXEC; queueHandler.sendMessage(message);
@Override public void onResponse(@Nonnull ApolloInterceptor.InterceptorResponse response) { Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: onResponse()"); if(shouldRetry && ConflictResolutionHandler.conflictPresent(response.parsedResponse)) { //Set shouldRetry to false. Conflicts will only be attempted once. shouldRetry = false; //Found Conflict String conflictString = new JSONObject((Map)((Error) response.parsedResponse.get().errors().get(0)).customAttributes().get("data")).toString(); //Send a message to the Queue handler to retry Message message = new Message(); MutationInterceptorMessage msg = new MutationInterceptorMessage(originalMutation, currentMutation); msg.serverState = conflictString; msg.clientState = clientState; msg.requestIdentifier = recordIdentifier; msg.requestClassName = currentMutation.getClass().getSimpleName(); message.obj = msg; message.what = MessageNumberUtil.RETRY_EXEC; queueHandler.sendMessage(message); return; } //Call the customer's callback customerCallBack.onResponse(response); //Set the mutation as completed. appSyncOfflineMutationManager.setInProgressMutationAsCompleted(recordIdentifier); //Send a message to the QueueHandler to process the next mutation in queue Message message = new Message(); message.obj = new MutationInterceptorMessage(); message.what = MessageNumberUtil.SUCCESSFUL_EXEC; queueHandler.sendMessage(message); }