001: /*
002: * $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 $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: *
006: * ====================================================================
007: *
008: * Licensed to the Apache Software Foundation (ASF) under one or more
009: * contributor license agreements. See the NOTICE file distributed with
010: * this work for additional information regarding copyright ownership.
011: * The ASF licenses this file to You under the Apache License, Version 2.0
012: * (the "License"); you may not use this file except in compliance with
013: * the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing, software
018: * distributed under the License is distributed on an "AS IS" BASIS,
019: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020: * See the License for the specific language governing permissions and
021: * limitations under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: */
030:
031: package org.apache.commons.httpclient;
032:
033: /**
034: * The default MethodRetryHandler used by HttpMethodBase.
035: *
036: * @author Michael Becke
037: *
038: * @see HttpMethodBase#setMethodRetryHandler(MethodRetryHandler)
039: *
040: * @deprecated use {@link org.apache.commons.httpclient.DefaultHttpMethodRetryHandler}
041: */
042: public class DefaultMethodRetryHandler implements MethodRetryHandler {
043:
044: /** the number of times a method will be retried */
045: private int retryCount;
046:
047: /** Whether or not methods that have successfully sent their request will be retried */
048: private boolean requestSentRetryEnabled;
049:
050: /**
051: */
052: public DefaultMethodRetryHandler() {
053: this .retryCount = 3;
054: this .requestSentRetryEnabled = false;
055: }
056:
057: /**
058: * Used <code>retryCount</code> and <code>requestSentRetryEnabled</code> to determine
059: * if the given method should be retried.
060: *
061: * @see MethodRetryHandler#retryMethod(HttpMethod, HttpConnection, HttpRecoverableException, int, boolean)
062: */
063: public boolean retryMethod(HttpMethod method,
064: HttpConnection connection,
065: HttpRecoverableException recoverableException,
066: int executionCount, boolean requestSent) {
067: return ((!requestSent || requestSentRetryEnabled) && (executionCount <= retryCount));
068: }
069:
070: /**
071: * @return <code>true</code> if this handler will retry methods that have
072: * successfully sent their request, <code>false</code> otherwise
073: */
074: public boolean isRequestSentRetryEnabled() {
075: return requestSentRetryEnabled;
076: }
077:
078: /**
079: * @return the maximum number of times a method will be retried
080: */
081: public int getRetryCount() {
082: return retryCount;
083: }
084:
085: /**
086: * @param requestSentRetryEnabled a flag indicating if methods that have
087: * successfully sent their request should be retried
088: */
089: public void setRequestSentRetryEnabled(
090: boolean requestSentRetryEnabled) {
091: this .requestSentRetryEnabled = requestSentRetryEnabled;
092: }
093:
094: /**
095: * @param retryCount the maximum number of times a method can be retried
096: */
097: public void setRetryCount(int retryCount) {
098: this.retryCount = retryCount;
099: }
100:
101: }
|