8000 Truncated Exponential Backoff implementation · sdecima/google-http-java-client@ab02df6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab02df6

Browse files
committed
Truncated Exponential Backoff implementation
1 parent 4fb8bf7 commit ab02df6

File tree

6 files changed

+989
-13
lines changed

6 files changed

+989
-13
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2011 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
package com.google.api.client.http;
16+
17+
/**
18+
* Strategy interface to control back off between retry attempts.
19+
*
20+
* @since 1.7
21+
* @author Ravi Mistry
22+
*/
23+
public interface BackOffPolicy {
24+
25+
/**
26+
* Value indicating that no more retries should be made, see {@link #getNextBackOffMillis()}.
27+
*/
28+
public static final long STOP = -1L;
29+
30+
/**
31+
* Determines if back off is required based on the specified status code.
32+
*
33+
* <p>
34+
* Implementations may want to back off on server or product-specific errors.
35+
* </p>
36+
*
37+
* @param statusCode HTTP status code
38+
*/
39+
public boolean isBackOffRequired(int statusCode);
40+
41+
/**
42+
* Reset Back off counters (if any) in an implementation-specific fashion.
43+
*/
44+
public void reset();
45+
46+
/**
47+
* Gets the number of milliseconds to wait before retrying an HTTP request. If {@link #STOP} is
48+
* returned, no retries should be made.
49+
*
50+
* This method should be used as follows:
51+
*
52+
* <pre>
53+
* long backoffTime = backoffPolicy.getNextBackoffMs();
54+
* if (backoffTime == BackoffPolicy.STOP) {
55+
* // Stop retrying.
56+
* } else {
57+
* // Retry after backoffTime.
58+
* }
59+
* </pre>
60+
*
61+
* @return the number of milliseconds to wait when backing off requests, or {@link #STOP} if no
62+
* more retries should be made
63+
*/
64+
public long getNextBackOffMillis();
65+
}

0 commit comments

Comments
 (0)
0