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
16 changes: 8 additions & 8 deletions Parse/src/main/java/com/parse/CacheQueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public <T extends ParseObject> Task<List<T>> findAsync(
final String sessionToken = user != null ? user.getSessionToken() : null;
CommandDelegate<List<T>> callbacks = new CommandDelegate<List<T>>() {
@Override
public Task<List<T>> runOnNetworkAsync(boolean retry) {
return networkController.findAsync(state, sessionToken, retry, cancellationToken);
public Task<List<T>> runOnNetworkAsync() {
return networkController.findAsync(state, sessionToken, cancellationToken);
}

@Override
Expand All @@ -53,8 +53,8 @@ public <T extends ParseObject> Task<Integer> countAsync(
final String sessionToken = user != null ? user.getSessionToken() : null;
CommandDelegate<Integer> callbacks = new CommandDelegate<Integer>() {
@Override
public Task<Integer> runOnNetworkAsync(boolean retry) {
return networkController.countAsync(state, sessionToken, retry, cancellationToken);
public Task<Integer> runOnNetworkAsync() {
return networkController.countAsync(state, sessionToken, cancellationToken);
}

@Override
Expand Down Expand Up @@ -124,7 +124,7 @@ private <TResult> Task<TResult> runCommandWithPolicyAsync(final CommandDelegate<
switch (policy) {
case IGNORE_CACHE:
case NETWORK_ONLY:
return c.runOnNetworkAsync(true);
return c.runOnNetworkAsync();
case CACHE_ONLY:
return c.runFromCacheAsync();
case CACHE_ELSE_NETWORK:
Expand All @@ -133,13 +133,13 @@ private <TResult> Task<TResult> runCommandWithPolicyAsync(final CommandDelegate<
@Override
public Task<TResult> then(Task<TResult> task) throws Exception {
if (task.getError() instanceof ParseException) {
return c.runOnNetworkAsync(true);
return c.runOnNetworkAsync();
}
return task;
}
});
case NETWORK_ELSE_CACHE:
return c.runOnNetworkAsync(false).continueWithTask(new Continuation<TResult, Task<TResult>>() {
return c.runOnNetworkAsync().continueWithTask(new Continuation<TResult, Task<TResult>>() {
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public Task<TResult> then(Task<TResult> task) throws Exception {
Expand Down Expand Up @@ -167,7 +167,7 @@ public Task<TResult> then(Task<TResult> task) throws Exception {
*/
private interface CommandDelegate<T> {
// Fetches data from the network.
Task<T> runOnNetworkAsync(boolean retry);
Task<T> runOnNetworkAsync();

// Fetches data from the cache.
Task<T> runFromCacheAsync();
Expand Down
4 changes: 0 additions & 4 deletions Parse/src/main/java/com/parse/NetworkObjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public Task<ParseObject.State> fetchAsync(
state.objectId(),
state.className(),
sessionToken);
command.enableRetrying();

return command.executeAsync(client).onSuccess(new Continuation<JSONObject, ParseObject.State>() {
@Override
Expand Down Expand Up @@ -64,7 +63,6 @@ public Task<ParseObject.State> saveAsync(
state,
objectJSON,
sessionToken);
command.enableRetrying();
return command.executeAsync(client).onSuccess(new Continuation<JSONObject, ParseObject.State>() {
@Override
public ParseObject.State then(Task<JSONObject> task) throws Exception {
Expand Down Expand Up @@ -124,7 +122,6 @@ public ParseObject.State then(Task<JSONObject> task) throws Exception {
public Task<Void> deleteAsync(ParseObject.State state, String sessionToken) {
ParseRESTObjectCommand command = ParseRESTObjectCommand.deleteObjectCommand(
state, sessionToken);
command.enableRetrying();

return command.executeAsync(client).makeVoid();
}
Expand All @@ -139,7 +136,6 @@ public List<Task<Void>> deleteAllAsync(
ParseObject.State state = states.get(i);
ParseRESTObjectCommand command = ParseRESTObjectCommand.deleteObjectCommand(
state, sessionToken);
command.enableRetrying();
commands.add(command);
}

Expand Down
12 changes: 2 additions & 10 deletions Parse/src/main/java/com/parse/NetworkQueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public NetworkQueryController(ParseHttpClient restClient) {
public <T extends ParseObject> Task<List<T>> findAsync(
ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken) {
String sessionToken = user != null ? user.getSessionToken() : null;
return findAsync(state, sessionToken, true, cancellationToken);
return findAsync(state, sessionToken, cancellationToken);
}

@Override
public <T extends ParseObject> Task<Integer> countAsync(
ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken) {
String sessionToken = user != null ? user.getSessionToken() : null;
return countAsync(state, sessionToken, true, cancellationToken);
return countAsync(state, sessionToken, cancellationToken);
}

/**
Expand All @@ -50,14 +50,10 @@ public <T extends ParseObject> Task<Integer> countAsync(
/* package */ <T extends ParseObject> Task<List<T>> findAsync(
final ParseQuery.State<T> state,
String sessionToken,
boolean shouldRetry,
Task<Void> ct) {
final long queryStart = System.nanoTime();

final ParseRESTCommand command = ParseRESTQueryCommand.findCommand(state, sessionToken);
if (shouldRetry) {
command.enableRetrying();
}

final long querySent = System.nanoTime();
return command.executeAsync(restClient, ct).onSuccess(new Continuation<JSONObject, List<T>>() {
Expand Down Expand Up @@ -94,12 +90,8 @@ public List<T> then(Task<JSONObject> task) throws Exception {
/* package */ <T extends ParseObject> Task<Integer> countAsync(
final ParseQuery.State<T> state,
String sessionToken,
boolean shouldRetry,
Task<Void> ct) {
final ParseRESTCommand command = ParseRESTQueryCommand.countCommand(state, sessionToken);
if (shouldRetry) {
command.enableRetrying();
}

return command.executeAsync(restClient, ct).onSuccessTask(new Continuation<JSONObject, Task<JSONObject>>() {
@Override
Expand Down
30 changes: 21 additions & 9 deletions Parse/src/main/java/com/parse/Parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
public class Parse {
private static final String TAG = "com.parse.Parse";

private static final int DEFAULT_MAX_RETRIES = ParseRequest.DEFAULT_MAX_RETRIES;

/**
* Represents an opaque configuration for the {@code Parse} SDK configuration.
*/
Expand All @@ -50,6 +52,7 @@ public static final class Builder {
private String server;
private boolean localDataStoreEnabled;
private OkHttpClient.Builder clientBuilder;
private int maxRetries = DEFAULT_MAX_RETRIES;

/**
* Initialize a bulider with a given context.
Expand Down Expand Up @@ -179,6 +182,18 @@ public Builder clientBuilder(OkHttpClient.Builder builder) {
return this;
}

/**
* Set the max number of times to retry Parse operations before deeming them a failure
* <p>
*
* @param maxRetries The maximum number of times to retry. <=0 to never retry commands
* @return The same builder, for easy chaining.
*/
public Builder maxRetries(int maxRetries) {
this.maxRetries = maxRetries;
return this;
}

/**
* Construct this builder into a concrete {@code Configuration} instance.
*
Expand All @@ -195,6 +210,7 @@ public Configuration build() {
final String server;
final boolean localDataStoreEnabled;
final OkHttpClient.Builder clientBuilder;
final int maxRetries;


private Configuration(Builder builder) {
Expand All @@ -204,6 +220,7 @@ private Configuration(Builder builder) {
this.server = builder.server;
this.localDataStoreEnabled = builder.localDataStoreEnabled;
this.clientBuilder = builder.clientBuilder;
this.maxRetries = builder.maxRetries;
}
}

Expand Down Expand Up @@ -369,19 +386,14 @@ public static void initialize(Configuration configuration) {
// isLocalDataStoreEnabled() to perform additional behavior.
isLocalDatastoreEnabled = configuration.localDataStoreEnabled;

ParsePlugins.Android.initialize(configuration.context, configuration);
ParsePlugins.initialize(configuration.context, configuration);

try {
ParseRESTCommand.server = new URL(configuration.server);
} catch (MalformedURLException ex) {
throw new RuntimeException(ex);
}

Context applicationContext = configuration.context.getApplicationContext();

ParseHttpClient.setKeepAlive(true);
ParseHttpClient.setMaxConnections(20);

ParseObject.registerParseSubclasses();

if (configuration.localDataStoreEnabled) {
Expand Down Expand Up @@ -459,7 +471,7 @@ static boolean isInitialized() {

static Context getApplicationContext() {
checkContext();
return ParsePlugins.Android.get().applicationContext();
return ParsePlugins.get().applicationContext();
}

/**
Expand Down Expand Up @@ -580,7 +592,7 @@ static void checkCacheApplicationId() {
* processing any commands already stored in the on-disk queue.
*/
static ParseEventuallyQueue getEventuallyQueue() {
Context context = ParsePlugins.Android.get().applicationContext();
Context context = ParsePlugins.get().applicationContext();
return getEventuallyQueue(context);
}

Expand Down Expand Up @@ -621,7 +633,7 @@ static void checkInit() {
}

static void checkContext() {
if (ParsePlugins.Android.get().applicationContext() == null) {
if (ParsePlugins.get().applicationContext() == null) {
throw new RuntimeException("applicationContext is null. "
+ "You must call Parse.initialize(Context)"
+ " before using the Parse library.");
Expand Down
1 change: 0 additions & 1 deletion Parse/src/main/java/com/parse/ParseConfigController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public ParseConfigController(ParseHttpClient restClient,

public Task<ParseConfig> getAsync(String sessionToken) {
final ParseRESTCommand command = ParseRESTConfigCommand.fetchConfigCommand(sessionToken);
command.enableRetrying();
return command.executeAsync(restClient).onSuccessTask(new Continuation<JSONObject, Task<ParseConfig>>() {
@Override
public Task<ParseConfig> then(Task<JSONObject> task) throws Exception {
Expand Down
2 changes: 0 additions & 2 deletions Parse/src/main/java/com/parse/ParseFileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public Task<ParseFile.State> saveAsync(
.contentType(state.mimeType())
.sessionToken(sessionToken)
.build();
command.enableRetrying();

return command.executeAsync(
restClient,
Expand Down Expand Up @@ -145,7 +144,6 @@ public Task<ParseFile.State> saveAsync(
.contentType(state.mimeType())
.sessionToken(sessionToken)
.build();
command.enableRetrying();

return command.executeAsync(
restClient,
Expand Down
14 changes: 0 additions & 14 deletions Parse/src/main/java/com/parse/ParseHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ static ParseHttpClient createClient(@Nullable OkHttpClient.Builder builder) {
return new ParseHttpClient(builder);
}

private static final String MAX_CONNECTIONS_PROPERTY_NAME = "http.maxConnections";
private static final String KEEP_ALIVE_PROPERTY_NAME = "http.keepAlive";

static void setMaxConnections(int maxConnections) {
if (maxConnections <= 0) {
throw new IllegalArgumentException("Max connections should be large than 0");
}
System.setProperty(MAX_CONNECTIONS_PROPERTY_NAME, String.valueOf(maxConnections));
}

static void setKeepAlive(boolean isKeepAlive) {
System.setProperty(KEEP_ALIVE_PROPERTY_NAME, String.valueOf(isKeepAlive));
}

private OkHttpClient okHttpClient;
private boolean hasExecuted;

Expand Down
2 changes: 0 additions & 2 deletions Parse/src/main/java/com/parse/ParseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,6 @@ private ParseRESTObjectCommand currentSaveEventuallyCommand(
state,
objectJSON,
sessionToken);
command.enableRetrying();
return command;
}

Expand Down Expand Up @@ -1880,7 +1879,6 @@ public final Task<Void> deleteEventually() {
// See [1]
command = ParseRESTObjectCommand.deleteObjectCommand(
getState(), sessionToken);
command.enableRetrying();
command.setLocalId(localId);

runEventuallyTask = Parse.getEventuallyQueue().enqueueEventuallyAsync(command, ParseObject.this);
Expand Down
Loading