36
36
public class Parse {
37
37
private static final String TAG = "com.parse.Parse" ;
38
38
39
+ private static final int DEFAULT_MAX_RETRIES = ParseRequest .DEFAULT_MAX_RETRIES ;
40
+
39
41
/**
40
42
* Represents an opaque configuration for the {@code Parse} SDK configuration.
41
43
*/
@@ -50,6 +52,7 @@ public static final class Builder {
50
52
private String server ;
51
53
private boolean localDataStoreEnabled ;
52
54
private OkHttpClient .Builder clientBuilder ;
55
+ private int maxRetries = DEFAULT_MAX_RETRIES ;
53
56
54
57
/**
55
58
* Initialize a bulider with a given context.
@@ -179,6 +182,18 @@ public Builder clientBuilder(OkHttpClient.Builder builder) {
179
182
return this ;
180
183
}
181
184
185
+ /**
186
+ * Set the max number of times to retry Parse operations before deeming them a failure
187
+ * <p>
188
+ *
189
+ * @param maxRetries The maximum number of times to retry. <=0 to never retry commands
190
+ * @return The same builder, for easy chaining.
191
+ */
192
+ public Builder maxRetries (int maxRetries ) {
193
+ this .maxRetries = maxRetries ;
194
+ return this ;
195
+ }
196
+
182
197
/**
183
198
* Construct this builder into a concrete {@code Configuration} instance.
184
199
*
@@ -195,6 +210,7 @@ public Configuration build() {
195
210
final String server ;
196
211
final boolean localDataStoreEnabled ;
197
212
final OkHttpClient .Builder clientBuilder ;
213
+ final int maxRetries ;
198
214
199
215
200
216
private Configuration (Builder builder ) {
@@ -204,6 +220,7 @@ private Configuration(Builder builder) {
204
220
this .server = builder .server ;
205
221
this .localDataStoreEnabled = builder .localDataStoreEnabled ;
206
222
this .clientBuilder = builder .clientBuilder ;
223
+ this .maxRetries = builder .maxRetries ;
207
224
}
208
225
}
209
226
@@ -369,19 +386,14 @@ public static void initialize(Configuration configuration) {
369
386
// isLocalDataStoreEnabled() to perform additional behavior.
370
387
isLocalDatastoreEnabled = configuration .localDataStoreEnabled ;
371
388
372
- ParsePlugins .Android . initialize (configuration .context , configuration );
389
+ ParsePlugins .initialize (configuration .context , configuration );
373
390
374
391
try {
375
392
ParseRESTCommand .server = new URL (configuration .server );
376
393
} catch (MalformedURLException ex ) {
377
394
throw new RuntimeException (ex );
378
395
}
379
396
380
- Context applicationContext = configuration .context .getApplicationContext ();
381
-
382
- ParseHttpClient .setKeepAlive (true );
383
- ParseHttpClient .setMaxConnections (20 );
384
-
385
397
ParseObject .registerParseSubclasses ();
386
398
387
399
if (configuration .localDataStoreEnabled ) {
@@ -459,7 +471,7 @@ static boolean isInitialized() {
459
471
460
472
static Context getApplicationContext () {
461
473
checkContext ();
462
- return ParsePlugins .Android . get ().applicationContext ();
474
+ return ParsePlugins .get ().applicationContext ();
463
475
}
464
476
465
477
/**
@@ -580,7 +592,7 @@ static void checkCacheApplicationId() {
580
592
* processing any commands already stored in the on-disk queue.
581
593
*/
582
594
static ParseEventuallyQueue getEventuallyQueue () {
583
- Context context = ParsePlugins .Android . get ().applicationContext ();
595
+ Context context = ParsePlugins .get ().applicationContext ();
584
596
return getEventuallyQueue (context );
585
597
}
586
598
@@ -621,7 +633,7 @@ static void checkInit() {
621
633
}
622
634
623
635
static void checkContext () {
624
- if (ParsePlugins .Android . get ().applicationContext () == null ) {
636
+ if (ParsePlugins .get ().applicationContext () == null ) {
625
637
throw new RuntimeException ("applicationContext is null. "
626
638
+ "You must call Parse.initialize(Context)"
627
639
+ " before using the Parse library." );
0 commit comments