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