1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient;
33
34 /***
35 * The default MethodRetryHandler used by HttpMethodBase.
36 *
37 * @author Michael Becke
38 *
39 * @see HttpMethodBase#setMethodRetryHandler(MethodRetryHandler)
40 */
41 public class DefaultMethodRetryHandler implements MethodRetryHandler {
42
43 /*** the number of times a method will be retried */
44 private int retryCount;
45
46 /*** Whether or not methods that have successfully sent their request will be retried */
47 private boolean requestSentRetryEnabled;
48
49 /***
50 */
51 public DefaultMethodRetryHandler() {
52 this.retryCount = 3;
53 this.requestSentRetryEnabled = false;
54 }
55
56 /***
57 * Used <code>retryCount</code> and <code>requestSentRetryEnabled</code> to determine
58 * if the given method should be retried.
59 *
60 * @see MethodRetryHandler#retryMethod(HttpMethod, HttpConnection, HttpRecoverableException, int, boolean)
61 */
62 public boolean retryMethod(
63 HttpMethod method,
64 HttpConnection connection,
65 HttpRecoverableException recoverableException,
66 int executionCount,
67 boolean requestSent
68 ) {
69 return ((!requestSent || requestSentRetryEnabled) && (executionCount <= retryCount));
70 }
71 /***
72 * @return <code>true</code> if this handler will retry methods that have
73 * successfully sent their request, <code>false</code> otherwise
74 */
75 public boolean isRequestSentRetryEnabled() {
76 return requestSentRetryEnabled;
77 }
78
79 /***
80 * @return the maximum number of times a method will be retried
81 */
82 public int getRetryCount() {
83 return retryCount;
84 }
85
86 /***
87 * @param requestSentRetryEnabled a flag indicating if methods that have
88 * successfully sent their request should be retried
89 */
90 public void setRequestSentRetryEnabled(boolean requestSentRetryEnabled) {
91 this.requestSentRetryEnabled = requestSentRetryEnabled;
92 }
93
94 /***
95 * @param retryCount the maximum number of times a method can be retried
96 */
97 public void setRetryCount(int retryCount) {
98 this.retryCount = retryCount;
99 }
100
101 }