3636public class Parse {
3737 private static final String TAG = "com.parse.Parse" ;
3838
39+ private static final int DEFAULT_MAX_RETRIES = ParseRequest .DEFAULT_MAX_RETRIES ;
40+
3941 /**
4042 * Represents an opaque configuration for the {@code Parse} SDK configuration.
4143 */
@@ -50,6 +52,7 @@ public static final class Builder {
5052 private String server ;
5153 private boolean localDataStoreEnabled ;
5254 private OkHttpClient .Builder clientBuilder ;
55+ private int maxRetries = DEFAULT_MAX_RETRIES ;
5356
5457 /**
5558 * Initialize a bulider with a given context.
@@ -179,6 +182,18 @@ public Builder clientBuilder(OkHttpClient.Builder builder) {
179182 return this ;
180183 }
181184
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+
182197 /**
183198 * Construct this builder into a concrete {@code Configuration} instance.
184199 *
@@ -195,6 +210,7 @@ public Configuration build() {
195210 final String server ;
196211 final boolean localDataStoreEnabled ;
197212 final OkHttpClient .Builder clientBuilder ;
213+ final int maxRetries ;
198214
199215
200216 private Configuration (Builder builder ) {
@@ -204,6 +220,7 @@ private Configuration(Builder builder) {
204220 this .server = builder .server ;
205221 this .localDataStoreEnabled = builder .localDataStoreEnabled ;
206222 this .clientBuilder = builder .clientBuilder ;
223+ this .maxRetries = builder .maxRetries ;
207224 }
208225 }
209226
@@ -369,19 +386,14 @@ public static void initialize(Configuration configuration) {
369386 // isLocalDataStoreEnabled() to perform additional behavior.
370387 isLocalDatastoreEnabled = configuration .localDataStoreEnabled ;
371388
372- ParsePlugins .Android . initialize (configuration .context , configuration );
389+ ParsePlugins .initialize (configuration .context , configuration );
373390
374391 try {
375392 ParseRESTCommand .server = new URL (configuration .server );
376393 } catch (MalformedURLException ex ) {
377394 throw new RuntimeException (ex );
378395 }
379396
380- Context applicationContext = configuration .context .getApplicationContext ();
381-
382- ParseHttpClient .setKeepAlive (true );
383- ParseHttpClient .setMaxConnections (20 );
384-
385397 ParseObject .registerParseSubclasses ();
386398
387399 if (configuration .localDataStoreEnabled ) {
@@ -459,7 +471,7 @@ static boolean isInitialized() {
459471
460472 static Context getApplicationContext () {
461473 checkContext ();
462- return ParsePlugins .Android . get ().applicationContext ();
474+ return ParsePlugins .get ().applicationContext ();
463475 }
464476
465477 /**
@@ -580,7 +592,7 @@ static void checkCacheApplicationId() {
580592 * processing any commands already stored in the on-disk queue.
581593 */
582594 static ParseEventuallyQueue getEventuallyQueue () {
583- Context context = ParsePlugins .Android . get ().applicationContext ();
595+ Context context = ParsePlugins .get ().applicationContext ();
584596 return getEventuallyQueue (context );
585597 }
586598
@@ -621,7 +633,7 @@ static void checkInit() {
621633 }
622634
623635 static void checkContext () {
624- if (ParsePlugins .Android . get ().applicationContext () == null ) {
636+ if (ParsePlugins .get ().applicationContext () == null ) {
625637 throw new RuntimeException ("applicationContext is null. "
626638 + "You must call Parse.initialize(Context)"
627639 + " before using the Parse library." );
0 commit comments