void handleMutationCancellation(Mutation canceledMutation ) { Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Handling cancellation for mutation [" + canceledMutation +"]"); //Check if the mutation being cancelled is the one currently being executed. if (currentMutation != null && currentMutation.request != null && canceledMutation.equals(currentMutation.request.operation)) { Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Mutation being canceled is the one currently in progress. Handling it "); setInProgressMutationAsCompleted(currentMutation.recordIdentifier); queueHandler.sendEmptyMessage(MessageNumberUtil.FAIL_EXEC); return; } //Otherwise, it is further down in the queue. Add it to the cancelled Mutations tests so that it can be handled when it reaches the front //of the queue. Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Lodging mutation in cancelled mutations list "); inMemoryOfflineMutationManager.addCancelledMutation(canceledMutation); //Remove it from the persistent queue InMemoryOfflineMutationObject inMemoryOfflineMutationObject = inMemoryOfflineMutationManager.getMutationObject(canceledMutation); if ( inMemoryOfflineMutationObject != null ) { persistentOfflineMutationManager.removePersistentMutationObject(inMemoryOfflineMutationObject.recordIdentifier); } }
setInProgressMutationAsCompleted(currentMutation.recordIdentifier); inMemoryOfflineMutationManager.removeCancelledMutation((Mutation) currentMutation.request.operation); queueHandler.sendEmptyMessage(MessageNumberUtil.FAIL_EXEC);
@Override public void onResponse(@Nonnull InterceptorResponse response) { callBack.onResponse(response); if ( callbackForPersistentMutation != null) { JSONObject jsonObject; try { jsonObject = new JSONObject(response.clonedBufferString.get()); callbackForPersistentMutation.onResponse(new PersistentMutationsResponse( jsonObject.getJSONObject("data"), jsonObject.getJSONArray("errors"), request.operation.getClass().getSimpleName(), object.recordIdentifier)); } catch (Exception e) { callbackForPersistentMutation.onFailure(new PersistentMutationsError( request.operation.getClass().getSimpleName(), object.recordIdentifier, new ApolloParseException(e.getLocalizedMessage())) ); } } appSyncOfflineMutationManager.setInProgressPersistentMutationAsCompleted(object.recordIdentifier); queueHandler.clearInMemoryOfflineMutationObjectBeingExecuted(); queueHandler.clearPersistentOfflineMutationObjectBeingExecuted(); queueHandler.sendEmptyMessage(MessageNumberUtil.SUCCESSFUL_EXEC); }
queueHandler.sendEmptyMessage(MessageNumberUtil.FAIL_EXEC); return; queueHandler.sendEmptyMessage(MessageNumberUtil.FAIL_EXEC); return; queueHandler.sendEmptyMessage(MessageNumberUtil.FAIL_EXEC); return;
queueHandler.sendEmptyMessage(MessageNumberUtil.FAIL_EXEC);
sendEmptyMessage(MessageNumberUtil.FAIL_EXEC); sendEmptyMessage(MessageNumberUtil.FAIL_EXEC);
@Override public void onFailure(@Nonnull ApolloException e) { callBack.onFailure(e); if ( callbackForPersistentMutation != null) { callbackForPersistentMutation.onFailure( new PersistentMutationsError(request.operation.getClass().getSimpleName(), object.recordIdentifier, e)); } appSyncOfflineMutationManager.setInProgressPersistentMutationAsCompleted(object.recordIdentifier); queueHandler.clearPersistentOfflineMutationObjectBeingExecuted(); queueHandler.clearInMemoryOfflineMutationObjectBeingExecuted(); queueHandler.sendEmptyMessage(MessageNumberUtil.FAIL_EXEC); }