|
| 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 | +import com.google.api.client.util.Beta; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | + |
| 21 | +/** |
| 22 | + * {@link Beta} <br/> |
| 23 | + * Strategy interface to control back off between retry attempts. |
| 24 | + * |
| 25 | + * @since 1.7 |
| 26 | + * @author Ravi Mistry |
| 27 | + * @deprecated (scheduled to be removed in 1.18) Use {@link HttpBackOffUnsuccessfulResponseHandler} |
| 28 | + * instead. |
| 29 | + */ |
| 30 | +@Deprecated |
| 31 | +@Beta |
| 32 | +public interface BackOffPolicy { |
| 33 | + |
| 34 | + /** |
| 35 | + * Value indicating that no more retries should be made, see {@link #getNextBackOffMillis()}. |
| 36 | + */ |
| 37 | + public static final long STOP = -1L; |
| 38 | + |
| 39 | + /** |
| 40 | + * Determines if back off is required based on the specified status code. |
| 41 | + * |
| 42 | + * <p> |
| 43 | + * Implementations may want to back off on server or product-specific errors. |
| 44 | + * </p> |
| 45 | + * |
| 46 | + * @param statusCode HTTP status code |
| 47 | + */ |
| 48 | + public boolean isBackOffRequired(int statusCode); |
| 49 | + |
| 50 | + /** |
| 51 | + * Reset Back off counters (if any) in an implementation-specific fashion. |
| 52 | + */ |
| 53 | + public void reset(); |
| 54 | + |
| 55 | + /** |
| 56 | + * Gets the number of milliseconds to wait before retrying an HTTP request. If {@link #STOP} is |
| 57 | + * returned, no retries should be made. |
| 58 | + * |
| 59 | + * This method should be used as follows: |
| 60 | + * |
| 61 | + * <pre> |
| 62 | + * long backoffTime = backoffPolicy.getNextBackoffMs(); |
| 63 | + * if (backoffTime == BackoffPolicy.STOP) { |
| 64 | + * // Stop retrying. |
| 65 | + * } else { |
| 66 | + * // Retry after backoffTime. |
| 67 | + * } |
| 68 | + *</pre> |
| 69 | + * |
| 70 | + * @return the number of milliseconds to wait when backing off requests, or {@link #STOP} if no |
| 71 | + * more retries should be made |
| 72 | + */ |
| 73 | + public long getNextBackOffMillis() throws IOException; |
| 74 | +} |
0 commit comments