void clearMutationQueue(){ inMemoryOfflineMutationManager.clearMutationQueue(); persistentOfflineMutationManager.clearMutationQueue(); } }
public PersistentOfflineMutationManager(AppSyncMutationSqlCacheOperations mutationSqlCacheOperations, AppSyncCustomNetworkInvoker networkInvoker) { Log.v(TAG,"Thread:[" + Thread.currentThread().getId() +"]:In Constructor"); this.mutationSqlCacheOperations = mutationSqlCacheOperations; this.networkInvoker = networkInvoker; //Get all the previously persisted mutations and house them in the persistentOfflineMutationObjectList and persistentOfflineMutationObjectMap Log.v(TAG,"Thread:[" + Thread.currentThread().getId() +"]:Priming the pump - Fetching all the queued mutations from the persistent store"); persistentOfflineMutationObjectList = fetchPersistentMutationsList(); persistentOfflineMutationObjectMap = new HashMap<>(); for (PersistentOfflineMutationObject object: persistentOfflineMutationObjectList) { persistentOfflineMutationObjectMap.put(object.recordIdentifier, object); } timedOutMutations = new HashSet<PersistentOfflineMutationObject>(); networkInvoker.setPersistentOfflineMutationManager(this); Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]:Exiting the constructor. There are [" + persistentOfflineMutationObjectList.size() + "] mutations in the persistent queue"); }
public PersistentOfflineMutationObject processNextMutationObject() { Log.v(TAG,"Thread:[" + Thread.currentThread().getId() +"]:In processNextMutationObject"); PersistentOfflineMutationObject mutationRequestObject = getFirstInQueue(); if ( mutationRequestObject != null ) { // kick off originalMutation here through the custom network invoker networkInvoker.executeRequest(mutationRequestObject); } return mutationRequestObject; }
private void setMutationExecutionAsCompletedAndRemoveFromQueue (PersistentOfflineMutationObject p) { //This mutation is completed. So remove it from the queue. persistentOfflineMutationManager.removePersistentMutationObject(p.recordIdentifier); if (persistentOfflineMutationManager.getTimedoutMutations().contains(p)) { //Mutation has been tagged as timed out. Remove this from the timedOutList. //The queueHandler will manage getting the queue unblocked for this case. persistentOfflineMutationManager.removeTimedoutMutation(p); } else { //Mutation not tagged as timed out. Signal queueHandler that this mutation is done. queueHandler.setMutationInProgressStatusToFalse(); } }
if (!persistentOfflineMutationManager.isQueueEmpty()) { if (queueHandler.setMutationInProgress()) { Log.d(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Processing next from persistent queue"); PersistentOfflineMutationObject p = persistentOfflineMutationManager.processNextMutationObject();
appSyncOfflineMutationManager.persistentOfflineMutationManager.addTimedoutMutation(persistentOfflineMutationObjectBeingExecuted); appSyncOfflineMutationManager.persistentOfflineMutationManager.removePersistentMutationObject(persistentOfflineMutationObjectBeingExecuted.recordIdentifier);
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); } }
boolean mutationQueueEmpty() { return ( persistentOfflineMutationManager.isQueueEmpty() && inMemoryOfflineMutationManager.isQueueEmpty()); }
public AppSyncOfflineMutationManager(Context context, final Map<ScalarType, CustomTypeAdapter> customTypeAdapters, final AppSyncMutationSqlCacheOperations mutationSqlCacheOperations, final AppSyncCustomNetworkInvoker persistentMutationsNetworkInvoker) { this.context = context; //Setup HandlerThread handlerThread = new HandlerThread(TAG + "-AWSAppSyncOfflineMutationsHandlerThread"); handlerThread.start(); //Setup InMemory and Persistent Queue this.inMemoryOfflineMutationManager = new InMemoryOfflineMutationManager(); persistentOfflineMutationManager = new PersistentOfflineMutationManager(mutationSqlCacheOperations, persistentMutationsNetworkInvoker); //Setup Network Monitoring objects this.networkUpdateHandler = new NetworkUpdateHandler(handlerThread.getLooper()); this.networkInfoReceiver = new NetworkInfoReceiver(context, this.networkUpdateHandler); context.getApplicationContext().registerReceiver(networkInfoReceiver, new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION)); //Setup ancillary stuff this.scalarTypeAdapters = new ScalarTypeAdapters(customTypeAdapters); this.mutationSqlCacheOperations = mutationSqlCacheOperations; }
persistentOfflineMutationManager.addPersistentMutationObject( new PersistentOfflineMutationObject( mutationObject.recordIdentifier, persistentOfflineMutationManager.addPersistentMutationObject( new PersistentOfflineMutationObject( mutationObject.recordIdentifier,
void setInProgressPersistentMutationAsCompleted(String recordIdentifier) { persistentOfflineMutationManager.removePersistentMutationObject(recordIdentifier); queueHandler.setMutationInProgressStatusToFalse(); queueHandler.clearInMemoryOfflineMutationObjectBeingExecuted(); queueHandler.clearPersistentOfflineMutationObjectBeingExecuted(); }
void setInProgressMutationAsCompleted(String recordIdentifier) { persistentOfflineMutationManager.removePersistentMutationObject(recordIdentifier); inMemoryOfflineMutationManager.removeFromQueue(recordIdentifier); queueHandler.setMutationInProgressStatusToFalse(); queueHandler.clearInMemoryOfflineMutationObjectBeingExecuted(); queueHandler.clearPersistentOfflineMutationObjectBeingExecuted(); }