View Javadoc

1   /*
2    * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java,v 1.1.2.1 2004/02/22 18:21:13 olegk Exp $
3    * $Revision: 1.1.2.1 $
4    * $Date: 2004/02/22 18:21:13 $
5    *
6    * ====================================================================
7    *
8    *  Copyright 1999-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   * [Additional notices, if required by prior licensing conditions]
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 }