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