1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.volley; 18 19 /** 20 * Retry policy for a request. 21 * 22 * <p>A retry policy can control two parameters: 23 * 24 * <ul> 25 * <li>The number of tries. This can be a simple counter or more complex logic based on the type 26 * of error passed to {@link #retry(VolleyError)}, although {@link #getCurrentRetryCount()} 27 * should always return the current retry count for logging purposes. 28 * <li>The request timeout for each try, via {@link #getCurrentTimeout()}. In the common case that 29 * a request times out before the response has been received from the server, retrying again 30 * with a longer timeout can increase the likelihood of success (at the expense of causing the 31 * user to wait longer, especially if the request still fails). 32 * </ul> 33 * 34 * <p>Note that currently, retries triggered by a retry policy are attempted immediately in sequence 35 * with no delay between them (although the time between tries may increase if the requests are 36 * timing out and {@link #getCurrentTimeout()} is returning increasing values). 37 * 38 * <p>By default, Volley uses {@link DefaultRetryPolicy}. 39 */ 40 public interface RetryPolicy { 41 42 /** Returns the current timeout (used for logging). */ 43 int getCurrentTimeout(); 44 45 /** Returns the current retry count (used for logging). */ 46 int getCurrentRetryCount(); 47 48 /** 49 * Prepares for the next retry by applying a backoff to the timeout. 50 * 51 * @param error The error code of the last attempt. 52 * @throws VolleyError In the event that the retry could not be performed (for example if we ran 53 * out of attempts), the passed in error is thrown. 54 */ 55 void retry(VolleyError error) throws VolleyError; 56 } 57