1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27 package org.apache.http.client;
28
29 import org.apache.http.HttpResponse;
30
31 /**
32 * When managing a dynamic number of connections for a given route, this
33 * strategy assesses whether a given request execution outcome should
34 * result in a backoff signal or not, based on either examining the
35 * {@code Throwable} that resulted or by examining the resulting
36 * response (e.g. for its status code).
37 *
38 * @since 4.2
39 *
40 */
41 public interface ConnectionBackoffStrategy {
42
43 /**
44 * Determines whether seeing the given {@code Throwable} as
45 * a result of request execution should result in a backoff
46 * signal.
47 * @param t the {@code Throwable} that happened
48 * @return {@code true} if a backoff signal should be
49 * given
50 */
51 boolean shouldBackoff(Throwable t);
52
53 /**
54 * Determines whether receiving the given {@link HttpResponse} as
55 * a result of request execution should result in a backoff
56 * signal. Implementations MUST restrict themselves to examining
57 * the response header and MUST NOT consume any of the response
58 * body, if any.
59 * @param resp the {@code HttpResponse} that was received
60 * @return {@code true} if a backoff signal should be
61 * given
62 */
63 boolean shouldBackoff(HttpResponse resp);
64 }