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