@Test public void testGetAsyncFromMemory() throws Exception { CachedCurrentInstallationController controller = new CachedCurrentInstallationController(null, null); ParseInstallation currentInstallationInMemory = new ParseInstallation(); controller.currentInstallation = currentInstallationInMemory; ParseInstallation currentInstallation = ParseTaskUtils.wait(controller.getAsync()); assertSame(currentInstallationInMemory, currentInstallation); }
@Override public Task<ParseInstallation> getAsync() { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return taskQueue.enqueue(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> toAwait) { return toAwait.continueWithTask(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> task) { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return store.getAsync().continueWith(new Continuation<ParseInstallation, ParseInstallation>() { @Override public ParseInstallation then(Task<ParseInstallation> task) { ParseInstallation current = task.getResult(); if (current == null) { current = ParseObject.create(ParseInstallation.class); current.updateDeviceInfo(installationId); } else { installationId.set(current.getInstallationId()); PLog.v(TAG, "Successfully deserialized Installation object"); } synchronized (mutex) { currentInstallation = current; } return current; } }, ParseExecutors.io()); } }); } }); }
CachedCurrentInstallationController implements ParseCurrentInstallationController { @Override public Task<ParseInstallation> getAsync() { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return taskQueue.enqueue(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> toAwait) { return toAwait.continueWithTask(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> task) { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return store.getAsync().continueWith(new Continuation<ParseInstallation, ParseInstallation>() { @Override public ParseInstallation then(Task<ParseInstallation> task) { ParseInstallation current = task.getResult(); if (current == null) { current = ParseObject.create(ParseInstallation.class); current.updateDeviceInfo(installationId); } else { installationId.set(current.getInstallationId()); PLog.v(TAG, "Successfully deserialized Installation object"); } synchronized (mutex) { currentInstallation = current; } return current; } }, ParseExecutors.io()); } }); } }); } }
CachedCurrentInstallationController implements ParseCurrentInstallationController { @Override public Task<ParseInstallation> getAsync() { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return taskQueue.enqueue(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> toAwait) { return toAwait.continueWithTask(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> task) { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return store.getAsync().continueWith(new Continuation<ParseInstallation, ParseInstallation>() { @Override public ParseInstallation then(Task<ParseInstallation> task) { ParseInstallation current = task.getResult(); if (current == null) { current = ParseObject.create(ParseInstallation.class); current.updateDeviceInfo(installationId); } else { installationId.set(current.getInstallationId()); PLog.v(TAG, "Successfully deserialized Installation object"); } synchronized (mutex) { currentInstallation = current; } return current; } }, ParseExecutors.io()); } }); } }); } CachedCurrentInstallationController(
            ParseObjectStore<ParseInstallation> store, InstallationId installationId); }
CachedCurrentInstallationController implements ParseCurrentInstallationController { @Override public Task<ParseInstallation> getAsync() { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return taskQueue.enqueue(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> toAwait) { return toAwait.continueWithTask(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> task) { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return store.getAsync().continueWith(new Continuation<ParseInstallation, ParseInstallation>() { @Override public ParseInstallation then(Task<ParseInstallation> task) { ParseInstallation current = task.getResult(); if (current == null) { current = ParseObject.create(ParseInstallation.class); current.updateDeviceInfo(installationId); } else { installationId.set(current.getInstallationId()); PLog.v(TAG, "Successfully deserialized Installation object"); } synchronized (mutex) { currentInstallation = current; } return current; } }, ParseExecutors.io()); } }); } }); } CachedCurrentInstallationController(
            ParseObjectStore<ParseInstallation> store, InstallationId installationId); @Override Task<Void> setAsync(final ParseInstallation installation); @Override Task<ParseInstallation> getAsync(); @Override Task<Boolean> existsAsync(); @Override void clearFromMemory(); @Override void clearFromDisk(); @Override boolean isCurrent(ParseInstallation installation); }
CachedCurrentInstallationController implements ParseCurrentInstallationController { @Override public Task<ParseInstallation> getAsync() { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return taskQueue.enqueue(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> toAwait) { return toAwait.continueWithTask(new Continuation<Void, Task<ParseInstallation>>() { @Override public Task<ParseInstallation> then(Task<Void> task) { synchronized (mutex) { if (currentInstallation != null) { return Task.forResult(currentInstallation); } } return store.getAsync().continueWith(new Continuation<ParseInstallation, ParseInstallation>() { @Override public ParseInstallation then(Task<ParseInstallation> task) { ParseInstallation current = task.getResult(); if (current == null) { current = ParseObject.create(ParseInstallation.class); current.updateDeviceInfo(installationId); } else { installationId.set(current.getInstallationId()); PLog.v(TAG, "Successfully deserialized Installation object"); } synchronized (mutex) { currentInstallation = current; } return current; } }, ParseExecutors.io()); } }); } }); } CachedCurrentInstallationController(
            ParseObjectStore<ParseInstallation> store, InstallationId installationId); @Override Task<Void> setAsync(final ParseInstallation installation); @Override Task<ParseInstallation> getAsync(); @Override Task<Boolean> existsAsync(); @Override void clearFromMemory(); @Override void clearFromDisk(); @Override boolean isCurrent(ParseInstallation installation);  }