You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/06/30 15:11:31 UTC
svn commit: r1355729 - in
/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client:
AutoRetryHttpClient.java HttpClientBuilder.java
exec/ServiceUnavailableRetryExec.java
Author: olegk
Date: Sat Jun 30 13:11:30 2012
New Revision: 1355729
URL: http://svn.apache.org/viewvc?rev=1355729&view=rev
Log:
Deprecated AutoRetryHttpClient
Added:
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java (with props)
Modified:
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java?rev=1355729&r1=1355728&r2=1355729&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java Sat Jun 30 13:11:30 2012
@@ -50,6 +50,8 @@ import org.apache.http.protocol.HttpCont
* a non-2xx response using the {@link ServiceUnavailableRetryStrategy} interface.
*
* @since 4.2
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}.
*/
@ThreadSafe
public class AutoRetryHttpClient implements HttpClient {
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1355729&r1=1355728&r2=1355729&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java Sat Jun 30 13:11:30 2012
@@ -50,6 +50,7 @@ import org.apache.http.client.Credential
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.RedirectStrategy;
+import org.apache.http.client.ServiceUnavailableRetryStrategy;
import org.apache.http.client.UserTokenHandler;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.params.CookiePolicy;
@@ -81,6 +82,7 @@ import org.apache.http.impl.client.exec.
import org.apache.http.impl.client.exec.ProtocolExec;
import org.apache.http.impl.client.exec.RedirectExec;
import org.apache.http.impl.client.exec.RetryExec;
+import org.apache.http.impl.client.exec.ServiceUnavailableRetryExec;
import org.apache.http.impl.conn.DefaultHttpRoutePlanner;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
@@ -204,6 +206,8 @@ public class HttpClientBuilder {
private ConnectionBackoffStrategy connectionBackoffStrategy;
private BackoffManager backoffManager;
+ private ServiceUnavailableRetryStrategy serviceUnavailStrategy;
+
private HttpParams params;
private Map<String, AuthSchemeFactory> authShemes;
@@ -354,6 +358,12 @@ public class HttpClientBuilder {
this.backoffManager = backoffManager;
return this;
}
+
+ public final HttpClientBuilder setServiceUnavailableRetryStrategy(
+ final ServiceUnavailableRetryStrategy serviceUnavailStrategy) {
+ this.serviceUnavailStrategy = serviceUnavailStrategy;
+ return this;
+ }
public final HttpClientBuilder setParams(final HttpParams params) {
this.params = params;
@@ -569,6 +579,11 @@ public class HttpClientBuilder {
execChain = new RedirectExec(execChain, routePlanner, redirectStrategy);
}
+ // Optionally, add service unavailable retry executor
+ ServiceUnavailableRetryStrategy serviceUnavailStrategy = this.serviceUnavailStrategy;
+ if (serviceUnavailStrategy != null) {
+ execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategy);
+ }
// Optionally, add connection back-off executor
BackoffManager backoffManager = this.backoffManager;
ConnectionBackoffStrategy connectionBackoffStrategy = this.connectionBackoffStrategy;
Added: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java?rev=1355729&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java (added)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java Sat Jun 30 13:11:30 2012
@@ -0,0 +1,102 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client.exec;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpException;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.client.ServiceUnavailableRetryStrategy;
+import org.apache.http.client.methods.HttpExecutionAware;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * {@link ClientExecChain} implementation that can automatically retry the request in case of
+ * a non-2xx response using the {@link ServiceUnavailableRetryStrategy} interface.
+ *
+ * @since 4.3
+ */
+@ThreadSafe
+public class ServiceUnavailableRetryExec implements ClientExecChain {
+
+ private final Log log = LogFactory.getLog(getClass());
+
+ private final ClientExecChain requestExecutor;
+ private final ServiceUnavailableRetryStrategy retryStrategy;
+
+ public ServiceUnavailableRetryExec(
+ final ClientExecChain requestExecutor,
+ final ServiceUnavailableRetryStrategy retryStrategy) {
+ super();
+ if (requestExecutor == null) {
+ throw new IllegalArgumentException("HTTP request executor may not be null");
+ }
+ if (retryStrategy == null) {
+ throw new IllegalArgumentException(
+ "ServiceUnavailableRetryStrategy may not be null");
+ }
+ this.requestExecutor = requestExecutor;
+ this.retryStrategy = retryStrategy;
+ }
+
+ public HttpResponseWrapper execute(
+ final HttpRoute route,
+ final HttpRequestWrapper request,
+ final HttpContext context,
+ final HttpExecutionAware execAware) throws IOException, HttpException {
+ for (int c = 1;; c++) {
+ HttpResponseWrapper response = this.requestExecutor.execute(
+ route, request, context, execAware);
+ try {
+ if (this.retryStrategy.retryRequest(response, c, context)) {
+ response.releaseConnection();
+ long nextInterval = this.retryStrategy.getRetryInterval();
+ try {
+ this.log.trace("Wait for " + nextInterval);
+ Thread.sleep(nextInterval);
+ } catch (InterruptedException e) {
+ throw new InterruptedIOException(e.getMessage());
+ }
+ } else {
+ return response;
+ }
+ } catch (RuntimeException ex) {
+ response.close();
+ throw ex;
+ } catch (IOException ex) {
+ response.close();
+ throw ex;
+ }
+ }
+ }
+
+}
Propchange: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java
------------------------------------------------------------------------------
svn:mime-type = text/plain