/ org.apache.commons.httpclient / src / org / apache / commons / httpclient / DefaultMethodRetryHandler.java
DefaultMethodRetryHandler.java
1 /* 2 * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/DefaultMethodRetryHandler.java,v 1.4 2004/07/05 22:46:58 olegk Exp $ 3 * $Revision: 480424 $ 4 * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $ 5 * 6 * ==================================================================== 7 * 8 * Licensed to the Apache Software Foundation (ASF) under one or more 9 * contributor license agreements. See the NOTICE file distributed with 10 * this work for additional information regarding copyright ownership. 11 * The ASF licenses this file to You under the Apache License, Version 2.0 12 * (the "License"); you may not use this file except in compliance with 13 * the License. You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * ==================================================================== 23 * 24 * This software consists of voluntary contributions made by many 25 * individuals on behalf of the Apache Software Foundation. For more 26 * information on the Apache Software Foundation, please see 27 * <http://www.apache.org/>. 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 }