Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Parse/src/main/java/com/parse/GcmRegistrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* A class that manages registering for GCM and updating the registration if it is out of date.
Expand Down Expand Up @@ -286,7 +287,7 @@ private static class Request {
final private String senderId;
final private Random random;
final private int identifier;
final private Task<String>.TaskCompletionSource tcs;
final private TaskCompletionSource<String> tcs;
final private PendingIntent appIntent;
final private AtomicInteger tries;
final private PendingIntent retryIntent;
Expand All @@ -304,7 +305,7 @@ private Request(Context context, String senderId) {
this.senderId = senderId;
this.random = new Random();
this.identifier = this.random.nextInt();
this.tcs = Task.create();
this.tcs = new TaskCompletionSource<>();
this.appIntent = PendingIntent.getBroadcast(this.context, identifier, new Intent(), 0);
this.tries = new AtomicInteger(0);

Expand Down
3 changes: 2 additions & 1 deletion Parse/src/main/java/com/parse/LocationNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import bolts.Capture;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* LocationNotifier is a wrapper around fetching the current device's location. It looks for the GPS
Expand Down Expand Up @@ -58,7 +59,7 @@
*/
/* package */ static Task<Location> getCurrentLocationAsync(Context context,
long timeout, Criteria criteria) {
final Task<Location>.TaskCompletionSource tcs = Task.create();
final TaskCompletionSource<Location> tcs = new TaskCompletionSource<>();
final Capture<ScheduledFuture<?>> timeoutFuture = new Capture<ScheduledFuture<?>>();
final LocationManager manager =
(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Expand Down
5 changes: 3 additions & 2 deletions Parse/src/main/java/com/parse/OfflineStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import bolts.Capture;
import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/** package */ class OfflineStore {

Expand Down Expand Up @@ -188,7 +189,7 @@ public Void then(Task<String> task) throws Exception {
*/
private Task<String> getOrCreateUUIDAsync(final ParseObject object, ParseSQLiteDatabase db) {
final String newUUID = UUID.randomUUID().toString();
final Task<String>.TaskCompletionSource tcs = Task.create();
final TaskCompletionSource<String> tcs = new TaskCompletionSource<>();

synchronized (lock) {
Task<String> uuidTask = objectToUuidMap.get(object);
Expand Down Expand Up @@ -484,7 +485,7 @@ public List<T> then(Task<Void> task) throws Exception {
/* package for OfflineQueryLogic */ <T extends ParseObject> Task<T> fetchLocallyAsync(
final T object,
final ParseSQLiteDatabase db) {
final Task<T>.TaskCompletionSource tcs = Task.create();
final TaskCompletionSource<T> tcs = new TaskCompletionSource<>();
Task<String> uuidTask;

synchronized (lock) {
Expand Down
7 changes: 4 additions & 3 deletions Parse/src/main/java/com/parse/ParseCommandCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import bolts.Capture;
import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* ParseCommandCache manages an on-disk cache of commands to be executed, and a thread with a
Expand Down Expand Up @@ -78,7 +79,7 @@ public static int getPendingCount() {
// Map of filename to TaskCompletionSource, for all commands that are in the queue from this run
// of the program. This is necessary so that the original objects can be notified after their
// saves complete.
private HashMap<File, Task<JSONObject>.TaskCompletionSource> pendingTasks = new HashMap<>();
private HashMap<File, TaskCompletionSource<JSONObject>> pendingTasks = new HashMap<>();

private boolean running; // Is the run loop executing commands from the disk cache running?

Expand Down Expand Up @@ -289,7 +290,7 @@ public Task<JSONObject> enqueueEventuallyAsync(ParseRESTCommand command,
private Task<JSONObject> enqueueEventuallyAsync(ParseRESTCommand command, boolean preferOldest,
ParseObject object) {
Parse.requirePermission(Manifest.permission.ACCESS_NETWORK_STATE);
Task<JSONObject>.TaskCompletionSource tcs = Task.create();
TaskCompletionSource<JSONObject> tcs = new TaskCompletionSource<>();
byte[] json;
try {
// If this object doesn't have an objectId yet, store the localId so we can remap it to the
Expand Down Expand Up @@ -508,7 +509,7 @@ private void maybeRunAllCommandsNow(int retriesRemaining) {

// Convert the command from a string.
final ParseRESTCommand command;
final Task<JSONObject>.TaskCompletionSource tcs =
final TaskCompletionSource<JSONObject> tcs =
pendingTasks.containsKey(file) ? pendingTasks.get(file) : null;

try {
Expand Down
17 changes: 9 additions & 8 deletions Parse/src/main/java/com/parse/ParseFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* {@code ParseFile} is a local representation of a file that is saved to the Parse cloud.
Expand Down Expand Up @@ -139,8 +140,8 @@ public String url() {
/* package for tests */ File file;

/* package for tests */ final TaskQueue taskQueue = new TaskQueue();
private Set<Task<?>.TaskCompletionSource> currentTasks = Collections.synchronizedSet(
new HashSet<Task<?>.TaskCompletionSource>());
private Set<TaskCompletionSource<?>> currentTasks = Collections.synchronizedSet(
new HashSet<TaskCompletionSource<?>>());

/**
* Creates a new file from a file pointer.
Expand Down Expand Up @@ -345,7 +346,7 @@ public Task<Void> then(Task<State> task) throws Exception {
* @return A Task that will be resolved when the save completes.
*/
public Task<Void> saveInBackground(final ProgressCallback uploadProgressCallback) {
final Task<Void>.TaskCompletionSource cts = Task.create();
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
currentTasks.add(cts);

return ParseUser.getCurrentSessionTokenAsync().onSuccessTask(new Continuation<String, Task<Void>>() {
Expand Down Expand Up @@ -425,7 +426,7 @@ public byte[] getData() throws ParseException {
* @return A Task that is resolved when the data has been fetched.
*/
public Task<byte[]> getDataInBackground(final ProgressCallback progressCallback) {
final Task<Void>.TaskCompletionSource cts = Task.create();
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
currentTasks.add(cts);

return taskQueue.enqueue(new Continuation<Void, Task<byte[]>>() {
Expand Down Expand Up @@ -511,7 +512,7 @@ public File getFile() throws ParseException {
* @return A Task that is resolved when the file pointer of this object has been fetched.
*/
public Task<File> getFileInBackground(final ProgressCallback progressCallback) {
final Task<Void>.TaskCompletionSource cts = Task.create();
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
currentTasks.add(cts);

return taskQueue.enqueue(new Continuation<Void, Task<File>>() {
Expand Down Expand Up @@ -593,7 +594,7 @@ public InputStream getDataStream() throws ParseException {
* @return A Task that is resolved when the data stream of this object has been fetched.
*/
public Task<InputStream> getDataStreamInBackground(final ProgressCallback progressCallback) {
final Task<Void>.TaskCompletionSource cts = Task.create();
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
currentTasks.add(cts);

return taskQueue.enqueue(new Continuation<Void, Task<InputStream>>() {
Expand Down Expand Up @@ -686,8 +687,8 @@ public Task<File> then(Task<Void> task) throws Exception {
*/
//TODO (grantland): Deprecate and replace with CancellationToken
public void cancel() {
Set<Task<?>.TaskCompletionSource> tasks = new HashSet<>(currentTasks);
for (Task<?>.TaskCompletionSource tcs : tasks) {
Set<TaskCompletionSource<?>> tasks = new HashSet<>(currentTasks);
for (TaskCompletionSource<?> tcs : tasks) {
tcs.trySetCancelled();
}
currentTasks.removeAll(tasks);
Expand Down
3 changes: 2 additions & 1 deletion Parse/src/main/java/com/parse/ParseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import bolts.Capture;
import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* The {@code ParseObject} is a local representation of data that can be saved and retrieved from
Expand Down Expand Up @@ -559,7 +560,7 @@ public static void registerSubclass(Class<? extends ParseObject> subclass) {
static <T> Task<T> enqueueForAll(final List<? extends ParseObject> objects,
Continuation<Void, Task<T>> taskStart) {
// The task that will be complete when all of the child queues indicate they're ready to start.
final Task<Void>.TaskCompletionSource readyToStart = Task.create();
final TaskCompletionSource<Void> readyToStart = new TaskCompletionSource<>();

// First, we need to lock the mutex for the queue for every object. We have to hold this
// from at least when taskStart() is called to when obj.taskQueue enqueue is called, so
Expand Down
17 changes: 9 additions & 8 deletions Parse/src/main/java/com/parse/ParsePinningEventuallyQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* Manages all *Eventually calls when the local datastore is enabled.
Expand All @@ -40,7 +41,7 @@
/**
* TCS that is held until a {@link ParseOperationSet} is completed.
*/
private HashMap<String, Task<JSONObject>.TaskCompletionSource> pendingOperationSetUUIDTasks =
private HashMap<String, TaskCompletionSource<JSONObject>> pendingOperationSetUUIDTasks =
new HashMap<>();

/**
Expand All @@ -67,7 +68,7 @@
*
* If an error is set, it means that we are trying to clear out the taskQueues.
*/
private Task<Void>.TaskCompletionSource connectionTaskCompletionSource = Task.create();
private TaskCompletionSource<Void> connectionTaskCompletionSource = new TaskCompletionSource<>();
private final Object connectionLock = new Object();
private final ParseHttpClient httpClient;

Expand Down Expand Up @@ -129,7 +130,7 @@ public int pendingCount() {
}

public Task<Integer> pendingCountAsync() {
final Task<Integer>.TaskCompletionSource tcs = Task.create();
final TaskCompletionSource<Integer> tcs = new TaskCompletionSource<>();

taskQueue.enqueue(new Continuation<Void, Task<Void>>() {
@Override
Expand Down Expand Up @@ -218,7 +219,7 @@ private Task<Void> waitForConnectionAsync() {
public Task<JSONObject> enqueueEventuallyAsync(final ParseRESTCommand command,
final ParseObject object) {
Parse.requirePermission(Manifest.permission.ACCESS_NETWORK_STATE);
final Task<JSONObject>.TaskCompletionSource tcs = Task.create();
final TaskCompletionSource<JSONObject> tcs = new TaskCompletionSource<>();

taskQueue.enqueue(new Continuation<Void, Task<Void>>() {
@Override
Expand All @@ -231,7 +232,7 @@ public Task<Void> then(Task<Void> toAwait) throws Exception {
}

private Task<Void> enqueueEventuallyAsync(final ParseRESTCommand command,
final ParseObject object, Task<Void> toAwait, final Task<JSONObject>.TaskCompletionSource tcs) {
final ParseObject object, Task<Void> toAwait, final TaskCompletionSource<JSONObject> tcs) {
return toAwait.continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(Task<Void> toAwait) throws Exception {
Expand Down Expand Up @@ -373,7 +374,7 @@ public Task<Void> then(Task<JSONObject> task) throws Exception {
notifyTestHelper(TestHelper.COMMAND_SUCCESSFUL);
}

Task<JSONObject>.TaskCompletionSource tcs =
TaskCompletionSource<JSONObject> tcs =
pendingOperationSetUUIDTasks.remove(eventuallyPin.getUUID());
if (tcs != null) {
if (error != null) {
Expand All @@ -397,7 +398,7 @@ public Task<Void> then(Task<JSONObject> task) throws Exception {
/**
* Map of eventually operation UUID to TCS that is resolved when the operation is complete.
*/
private HashMap<String, Task<JSONObject>.TaskCompletionSource> pendingEventuallyTasks =
private HashMap<String, TaskCompletionSource<JSONObject>> pendingEventuallyTasks =
new HashMap<>();

/**
Expand Down Expand Up @@ -429,7 +430,7 @@ public Task<Void> then(Task<JSONObject> task) throws Exception {
}

final String uuid; // The key we use to join the taskQueues
final Task<JSONObject>.TaskCompletionSource tcs;
final TaskCompletionSource<JSONObject> tcs;

synchronized (taskQueueSyncLock) {
if (operationSet != null && eventuallyPin == null) {
Expand Down
3 changes: 2 additions & 1 deletion Parse/src/main/java/com/parse/ParseQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* The {@code ParseQuery} class defines a query that is used to fetch {@link ParseObject}s. The most
Expand Down Expand Up @@ -886,7 +887,7 @@ public String toString() {

private final Object lock = new Object();
private boolean isRunning = false;
private Task<Void>.TaskCompletionSource cts;
private TaskCompletionSource<Void> cts;

/**
* Constructs a query for a {@link ParseObject} subclass type. A default query with no further
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/** package */ class ParseRESTObjectBatchCommand extends ParseRESTCommand {
public final static int COMMAND_OBJECT_BATCH_MAX_SIZE = 50;
Expand Down Expand Up @@ -50,9 +51,9 @@ public static List<Task<JSONObject>> executeBatch(
return tasks;
}

final List<Task<JSONObject>.TaskCompletionSource> tcss = new ArrayList<>(batchSize);
final List<TaskCompletionSource<JSONObject>> tcss = new ArrayList<>(batchSize);
for (int i = 0; i < batchSize; i++) {
Task<JSONObject>.TaskCompletionSource tcs = Task.create();
TaskCompletionSource<JSONObject> tcs = new TaskCompletionSource<>();
tcss.add(tcs);
tasks.add(tcs.getTask());
}
Expand Down Expand Up @@ -81,7 +82,7 @@ public static List<Task<JSONObject>> executeBatch(
command.executeAsync(client).continueWith(new Continuation<JSONObject, Void>() {
@Override
public Void then(Task<JSONObject> task) throws Exception {
Task<JSONObject>.TaskCompletionSource tcs;
TaskCompletionSource<JSONObject> tcs;

if (task.isFaulted() || task.isCancelled()) {
// REST command failed or canceled, fail or cancel all tasks
Expand Down
3 changes: 2 additions & 1 deletion Parse/src/main/java/com/parse/ParseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/**
* ParseRequest takes an arbitrary HttpUriRequest and retries it a number of times with
Expand Down Expand Up @@ -229,7 +230,7 @@ public Task<Response> then(Task<Response> task) throws Exception {
PLog.i("com.parse.ParseRequest", "Request failed. Waiting " + delay
+ " milliseconds before attempt #" + (attemptsMade + 1));

final Task<Response>.TaskCompletionSource retryTask = Task.create();
final TaskCompletionSource<Response> retryTask = new TaskCompletionSource<>();
ParseExecutors.scheduled().schedule(new Runnable() {
@Override
public void run() {
Expand Down
3 changes: 2 additions & 1 deletion Parse/src/main/java/com/parse/ParseSQLiteDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/** package */ class ParseSQLiteDatabase {

Expand Down Expand Up @@ -50,7 +51,7 @@ public Task<ParseSQLiteDatabase> then(Task<Void> task) throws Exception {
private SQLiteDatabase db;
private Task<Void> current = null;
private final Object currentLock = new Object();
private final Task<Void>.TaskCompletionSource tcs = Task.create();
private final TaskCompletionSource<Void> tcs = new TaskCompletionSource<>();

private int openFlags;

Expand Down
3 changes: 2 additions & 1 deletion Parse/src/main/java/com/parse/ParseTaskUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import bolts.AggregateException;
import bolts.Continuation;
import bolts.Task;
import bolts.TaskCompletionSource;

/** package */ class ParseTaskUtils {

Expand Down Expand Up @@ -96,7 +97,7 @@ public void done(Void aVoid, ParseException e) {
if (callback == null) {
return task;
}
final Task<T>.TaskCompletionSource tcs = Task.create();
final TaskCompletionSource<T> tcs = new TaskCompletionSource();
task.continueWith(new Continuation<T, Void>() {
@Override
public Void then(final Task<T> task) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.Test;

import bolts.Task;
import bolts.TaskCompletionSource;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -151,7 +152,7 @@ public void testGetAsyncWithNoInstallationRaceCondition() throws ParseException
when(installationId.get()).thenReturn("testInstallationId");
//noinspection unchecked
ParseObjectStore<ParseInstallation> store = mock(ParseObjectStore.class);
Task<ParseInstallation>.TaskCompletionSource tcs = Task.create();
TaskCompletionSource<ParseInstallation> tcs = new TaskCompletionSource();
when(store.getAsync()).thenReturn(tcs.getTask());

// Create test controller
Expand Down
Loading