Skip to content

Remove ParseRequest defaultClient #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2015
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
8 changes: 4 additions & 4 deletions Parse/src/main/java/com/parse/Parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ public static void initialize(Context context, String applicationId, String clie

ParseHttpClient.setKeepAlive(true);
ParseHttpClient.setMaxConnections(20);
ParseRequest.setDefaultClient(ParsePlugins.get().restClient());
// If we have interceptors in list, we have to initialize all http clients and add interceptors
if (interceptors != null) {
initializeParseHttpClientsWithParseNetworkInterceptors();
Expand Down Expand Up @@ -414,15 +413,16 @@ static void checkCacheApplicationId() {
|| (isLocalDatastoreEnabled && eventuallyQueue instanceof ParseCommandCache)
|| (!isLocalDatastoreEnabled && eventuallyQueue instanceof ParsePinningEventuallyQueue)) {
checkContext();
ParseHttpClient httpClient = ParsePlugins.get().restClient();
eventuallyQueue = isLocalDatastoreEnabled
? new ParsePinningEventuallyQueue(context)
: new ParseCommandCache(context);
? new ParsePinningEventuallyQueue(context, httpClient)
: new ParseCommandCache(context, httpClient);

// We still need to clear out the old command cache even if we're using Pinning in case
// anything is left over when the user upgraded. Checking number of pending and then
// initializing should be enough.
if (isLocalDatastoreEnabled && ParseCommandCache.getPendingCount() > 0) {
new ParseCommandCache(context);
new ParseCommandCache(context, httpClient);
}
}
return eventuallyQueue;
Expand Down
8 changes: 6 additions & 2 deletions Parse/src/main/java/com/parse/ParseCommandCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public static int getPendingCount() {

private Logger log; // Why is there a custom logger? To prevent Mockito deadlock!

private final ParseHttpClient httpClient;

ConnectivityNotifier notifier;
ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() {
@Override
Expand Down Expand Up @@ -121,12 +123,14 @@ public Void call() throws Exception {
}
};

public ParseCommandCache(Context context) {
public ParseCommandCache(Context context, ParseHttpClient client) {
setConnected(false);

shouldStop = false;
running = false;

runningLock = new Object();
httpClient = client;

log = Logger.getLogger(TAG);

Expand Down Expand Up @@ -526,7 +530,7 @@ private void maybeRunAllCommandsNow(int retriesRemaining) {
}
notifyTestHelper(TestHelper.COMMAND_OLD_FORMAT_DISCARDED);
} else {
commandTask = command.executeAsync().continueWithTask(new Continuation<JSONObject, Task<JSONObject>>() {
commandTask = command.executeAsync(httpClient).continueWithTask(new Continuation<JSONObject, Task<JSONObject>>() {
@Override
public Task<JSONObject> then(Task<JSONObject> task) throws Exception {
String localId = command.getLocalId();
Expand Down
8 changes: 5 additions & 3 deletions Parse/src/main/java/com/parse/ParseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1660,11 +1660,13 @@ public Task<Void> then(Task<Void> task) throws Exception {

// Currently only used by ParsePinningEventuallyQueue for saveEventually due to the limitation in
// ParseCommandCache that it can only return JSONObject result.
/* package */ Task<JSONObject> saveAsync(final ParseOperationSet operationSet, String sessionToken)
throws ParseException {
/* package */ Task<JSONObject> saveAsync(
ParseHttpClient client,
final ParseOperationSet operationSet,
String sessionToken) throws ParseException {
final ParseRESTCommand command =
currentSaveEventuallyCommand(operationSet, PointerEncoder.get(), sessionToken);
return command.executeAsync();
return command.executeAsync(client);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
*/
private Task<Void>.TaskCompletionSource connectionTaskCompletionSource = Task.create();
private final Object connectionLock = new Object();
private final ParseHttpClient httpClient;

private ConnectivityNotifier notifier;
private ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() {
Expand All @@ -84,9 +85,11 @@ public void networkConnectivityStatusChanged(Context context, Intent intent) {
}
};

public ParsePinningEventuallyQueue(Context context) {
public ParsePinningEventuallyQueue(Context context, ParseHttpClient client) {
setConnected(ConnectivityNotifier.isConnected(context));

httpClient = client;

notifier = ConnectivityNotifier.getNotifier(context);
notifier.addListener(listener);

Expand Down Expand Up @@ -492,7 +495,7 @@ public Task<JSONObject> then(Task<Void> task) throws Exception {

Task<JSONObject> executeTask;
if (type == EventuallyPin.TYPE_SAVE) {
executeTask = object.saveAsync(operationSet, sessionToken);
executeTask = object.saveAsync(httpClient, operationSet, sessionToken);
} else if (type == EventuallyPin.TYPE_DELETE) {
executeTask = object.deleteAsync(sessionToken).cast();
} else { // else if (type == EventuallyPin.TYPE_COMMAND) {
Expand All @@ -501,7 +504,7 @@ public Task<JSONObject> then(Task<Void> task) throws Exception {
executeTask = Task.forResult(null);
notifyTestHelper(TestHelper.COMMAND_OLD_FORMAT_DISCARDED);
} else {
executeTask = command.executeAsync();
executeTask = command.executeAsync(httpClient);
}
}

Expand Down
32 changes: 0 additions & 32 deletions Parse/src/main/java/com/parse/ParseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,6 @@ private static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int ma

private static long defaultInitialRetryDelay = DEFAULT_INITIAL_RETRY_DELAY;

// TODO(grantland): Remove once we're able to inject a http client into all of our controllers
// and we don't need this for mocking anymore.
private static ParseHttpClient defaultClient = null;
@Deprecated
public static void setDefaultClient(ParseHttpClient client) {
defaultClient = client;
}
@Deprecated
public static ParseHttpClient getDefaultClient() {
if (defaultClient == null) {
throw new IllegalStateException("Can't send Parse HTTPS request before Parse.initialize()");
}
return defaultClient;
}

public static void setDefaultInitialRetryDelay(long delay) {
defaultInitialRetryDelay = delay;
}
Expand Down Expand Up @@ -167,23 +152,6 @@ public Task<Response> then(Task<Response> task) throws Exception {
protected abstract Task<Response> onResponseAsync(ParseHttpResponse response,
ProgressCallback downloadProgressCallback);

@Deprecated
public Task<Response> executeAsync() {
return executeAsync(getDefaultClient());
}

@Deprecated
public Task<Response> executeAsync(
ProgressCallback uploadProgressCallback,
ProgressCallback downloadProgressCallback,
Task<Void> cancellationToken) {
return executeAsync(
getDefaultClient(),
uploadProgressCallback,
downloadProgressCallback,
cancellationToken);
}

/*
* Starts retrying the block.
*/
Expand Down