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
2 changes: 1 addition & 1 deletion src/main/java/com/box/sdk/BoxAPIConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public BoxAPIConnection(String clientID, String clientSecret, String accessToken
this.baseURL = DEFAULT_BASE_URL;
this.baseUploadURL = DEFAULT_BASE_UPLOAD_URL;
this.autoRefresh = true;
this.maxRequestAttempts = DEFAULT_MAX_ATTEMPTS;
this.maxRequestAttempts = BoxGlobalSettings.getMaxRequestAttempts();
this.refreshLock = new ReentrantReadWriteLock();
this.userAgent = "Box Java SDK v" + SDK_VERSION + " (Java " + JAVA_VERSION + ")";
this.listeners = new ArrayList<BoxAPIConnectionListener>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/box/sdk/BoxAPIRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public BoxAPIResponse send() {
*/
public BoxAPIResponse send(ProgressListener listener) {
if (this.api == null) {
this.backoffCounter.reset(BoxAPIConnection.DEFAULT_MAX_ATTEMPTS);
this.backoffCounter.reset(BoxGlobalSettings.getMaxRequestAttempts());
} else {
this.backoffCounter.reset(this.api.getMaxRequestAttempts());
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/box/sdk/BoxGlobalSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public final class BoxGlobalSettings {
private static int connectTimeout = 0;
private static int readTimeout = 0;
private static int maxRequestAttempts = BoxAPIConnection.DEFAULT_MAX_ATTEMPTS;

private BoxGlobalSettings() {
}
Expand Down Expand Up @@ -41,4 +42,20 @@ public static int getReadTimeout() {
public static void setReadTimeout(int readTimeout) {
BoxGlobalSettings.readTimeout = readTimeout;
}

/**
* Returns the global maximum number of request attempts.
* @return max number of request attempts
*/
public static int getMaxRequestAttempts() {
return maxRequestAttempts;
}

/**
* Sets the global default maximum number of request attempts.
* @param maxRequestAttempts maximum number of request attempts
*/
public static void setMaxRequestAttempts(int maxRequestAttempts) {
BoxGlobalSettings.maxRequestAttempts = maxRequestAttempts;
}
}
15 changes: 15 additions & 0 deletions src/test/java/com/box/sdk/BoxAPIConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,19 @@ public String getJSON() {

BoxFile.Info info = new BoxFile(api, "98765").getInfo();
}

@Test
@Category(UnitTest.class)
public void shouldUseGlobalMaxRequests() {

int defaultMaxRequests = BoxGlobalSettings.getMaxRequestAttempts();
int newMaxRequests = defaultMaxRequests + 5;
BoxGlobalSettings.setMaxRequestAttempts(newMaxRequests);

BoxAPIConnection api = new BoxAPIConnection("");
assertEquals(newMaxRequests, api.getMaxRequestAttempts());

// Set back the original number to not interfere with other test cases
BoxGlobalSettings.setMaxRequestAttempts(defaultMaxRequests);
}
}