国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

apache的HttpClient的默認(rèn)重試機(jī)制

MartinDai / 3427人閱讀

摘要:異常重試默認(rèn)重試次,三次都失敗則拋出或其他異常

maven
        
            org.apache.httpcomponents
            httpclient
            4.5.2
        
異常重試log
2017-01-31 19:31:39.057  INFO 3873 --- [askScheduler-13] o.apache.http.impl.execchain.RetryExec   : I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://192.168.99.100:8080: The target server failed to respond
2017-01-31 19:31:39.058  INFO 3873 --- [askScheduler-13] o.apache.http.impl.execchain.RetryExec   : Retrying request to {}->http://192.168.99.100:8080
RetryExec

org/apache/http/impl/execchain/RetryExec.java

/**
 * Request executor in the request execution chain that is responsible
 * for making a decision whether a request failed due to an I/O error
 * should be re-executed.
 * 

* Further responsibilities such as communication with the opposite * endpoint is delegated to the next executor in the request execution * chain. *

* * @since 4.3 */ @Immutable public class RetryExec implements ClientExecChain { private final Log log = LogFactory.getLog(getClass()); private final ClientExecChain requestExecutor; private final HttpRequestRetryHandler retryHandler; public RetryExec( final ClientExecChain requestExecutor, final HttpRequestRetryHandler retryHandler) { Args.notNull(requestExecutor, "HTTP request executor"); Args.notNull(retryHandler, "HTTP request retry handler"); this.requestExecutor = requestExecutor; this.retryHandler = retryHandler; } @Override public CloseableHttpResponse execute( final HttpRoute route, final HttpRequestWrapper request, final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException { Args.notNull(route, "HTTP route"); Args.notNull(request, "HTTP request"); Args.notNull(context, "HTTP context"); final Header[] origheaders = request.getAllHeaders(); for (int execCount = 1;; execCount++) { try { return this.requestExecutor.execute(route, request, context, execAware); } catch (final IOException ex) { if (execAware != null && execAware.isAborted()) { this.log.debug("Request has been aborted"); throw ex; } if (retryHandler.retryRequest(ex, execCount, context)) { if (this.log.isInfoEnabled()) { this.log.info("I/O exception ("+ ex.getClass().getName() + ") caught when processing request to " + route + ": " + ex.getMessage()); } if (this.log.isDebugEnabled()) { this.log.debug(ex.getMessage(), ex); } if (!RequestEntityProxy.isRepeatable(request)) { this.log.debug("Cannot retry non-repeatable request"); throw new NonRepeatableRequestException("Cannot retry request " + "with a non-repeatable request entity", ex); } request.setHeaders(origheaders); if (this.log.isInfoEnabled()) { this.log.info("Retrying request to " + route); } } else { if (ex instanceof NoHttpResponseException) { final NoHttpResponseException updatedex = new NoHttpResponseException( route.getTargetHost().toHostString() + " failed to respond"); updatedex.setStackTrace(ex.getStackTrace()); throw updatedex; } else { throw ex; } } } } } }
DefaultHttpRequestRetryHandler

org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java

/**
 * The default {@link HttpRequestRetryHandler} used by request executors.
 *
 * @since 4.0
 */
@Immutable
public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {

    public static final DefaultHttpRequestRetryHandler INSTANCE = new DefaultHttpRequestRetryHandler();

    /** the number of times a method will be retried */
    private final int retryCount;

    /** Whether or not methods that have successfully sent their request will be retried */
    private final boolean requestSentRetryEnabled;

    private final Set> nonRetriableClasses;

    /**
     * Create the request retry handler using the specified IOException classes
     *
     * @param retryCount how many times to retry; 0 means no retries
     * @param requestSentRetryEnabled true if it"s OK to retry requests that have been sent
     * @param clazzes the IOException types that should not be retried
     * @since 4.3
     */
    protected DefaultHttpRequestRetryHandler(
            final int retryCount,
            final boolean requestSentRetryEnabled,
            final Collection> clazzes) {
        super();
        this.retryCount = retryCount;
        this.requestSentRetryEnabled = requestSentRetryEnabled;
        this.nonRetriableClasses = new HashSet>();
        for (final Class clazz: clazzes) {
            this.nonRetriableClasses.add(clazz);
        }
    }

    /**
     * Create the request retry handler using the following list of
     * non-retriable IOException classes: 
*
    *
  • InterruptedIOException
  • *
  • UnknownHostException
  • *
  • ConnectException
  • *
  • SSLException
  • *
* @param retryCount how many times to retry; 0 means no retries * @param requestSentRetryEnabled true if it"s OK to retry non-idempotent requests that have been sent */ @SuppressWarnings("unchecked") public DefaultHttpRequestRetryHandler(final int retryCount, final boolean requestSentRetryEnabled) { this(retryCount, requestSentRetryEnabled, Arrays.asList( InterruptedIOException.class, UnknownHostException.class, ConnectException.class, SSLException.class)); } /** * Create the request retry handler with a retry count of 3, requestSentRetryEnabled false * and using the following list of non-retriable IOException classes:
*
    *
  • InterruptedIOException
  • *
  • UnknownHostException
  • *
  • ConnectException
  • *
  • SSLException
  • *
*/ public DefaultHttpRequestRetryHandler() { this(3, false); } /** * Used {@code retryCount} and {@code requestSentRetryEnabled} to determine * if the given method should be retried. */ @Override public boolean retryRequest( final IOException exception, final int executionCount, final HttpContext context) { Args.notNull(exception, "Exception parameter"); Args.notNull(context, "HTTP context"); if (executionCount > this.retryCount) { // Do not retry if over max retry count return false; } if (this.nonRetriableClasses.contains(exception.getClass())) { return false; } else { for (final Class rejectException : this.nonRetriableClasses) { if (rejectException.isInstance(exception)) { return false; } } } final HttpClientContext clientContext = HttpClientContext.adapt(context); final HttpRequest request = clientContext.getRequest(); if(requestIsAborted(request)){ return false; } if (handleAsIdempotent(request)) { // Retry if the request is considered idempotent return true; } if (!clientContext.isRequestSent() || this.requestSentRetryEnabled) { // Retry if the request has not been sent fully or // if it"s OK to retry methods that have been sent return true; } // otherwise do not retry return false; } /** * @return {@code true} if this handler will retry methods that have * successfully sent their request, {@code false} otherwise */ public boolean isRequestSentRetryEnabled() { return requestSentRetryEnabled; } /** * @return the maximum number of times a method will be retried */ public int getRetryCount() { return retryCount; } /** * @since 4.2 */ protected boolean handleAsIdempotent(final HttpRequest request) { return !(request instanceof HttpEntityEnclosingRequest); } /** * @since 4.2 * * @deprecated (4.3) */ @Deprecated protected boolean requestIsAborted(final HttpRequest request) { HttpRequest req = request; if (request instanceof RequestWrapper) { // does not forward request to original req = ((RequestWrapper) request).getOriginal(); } return (req instanceof HttpUriRequest && ((HttpUriRequest)req).isAborted()); } }

默認(rèn)重試3次,三次都失敗則拋出NoHttpResponseException或其他異常

doc

Apache HttpComponents

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/66577.html

相關(guān)文章

  • 記一次線程掛死排查過程(附 HttpClient 配置建議)

    摘要:此時我想到了福爾摩斯說過的一句話當(dāng)你排除掉各種不可能出現(xiàn)的情況之后,剩下的情況無論多么難以置信,都是真相。福爾摩斯冷靜下來想一想,這個線程,有可能靜悄悄地退出了嗎,沒留下半點異常日志從理論上來說,不可能。配置建議最后,附上一份配置建議。 1、事發(fā) 我們有個視頻處理程序,基于 SpringBoot,會啟動幾個線程來跑。要退出程序時,會發(fā)送一個信號給程序,每個線程收到信號后會平滑退出,等全...

    jollywing 評論0 收藏0
  • Apache httpclientexecute方法調(diào)試

    摘要:因為工作需要,想研究一下執(zhí)行的邏輯。在這一行調(diào)用的實現(xiàn)我在代碼里聲明的只是一個接口,實現(xiàn)類是。首先根據(jù)傳入的請求決定出目標(biāo)投遞到執(zhí)行。 因為工作需要,想研究一下execute執(zhí)行的邏輯。 在這一行調(diào)用execute: response = getHttpClient().execute(get); getHttpClient的實現(xiàn): private HttpClient getHttp...

    wudengzan 評論0 收藏0
  • 爬蟲框架WebMagic源碼分析之Downloader

    摘要:方法,首先判斷是否有這是在中配置的,如果有,直接調(diào)用的將相應(yīng)內(nèi)容轉(zhuǎn)化成對應(yīng)編碼字符串,否則智能檢測響應(yīng)內(nèi)容的字符編碼。 Downloader是負(fù)責(zé)請求url獲取返回值(html、json、jsonp等)的一個組件。當(dāng)然會同時處理POST重定向、Https驗證、ip代理、判斷失敗重試等。 接口:Downloader 定義了download方法返回Page,定義了setThread方法來...

    104828720 評論0 收藏0
  • spring-cloud-feign源碼深度解析

    摘要:內(nèi)部使用了的動態(tài)代理為目標(biāo)接口生成了一個動態(tài)代理類,這里會生成一個動態(tài)代理原理統(tǒng)一的方法攔截器,同時為接口的每個方法生成一個攔截器,并解析方法上的元數(shù)據(jù),生成一個請求模板。的核心源碼解析到此結(jié)束了,不知道是否對您有無幫助,可留言跟我交流。 Feign是一個聲明式的Web服務(wù)客戶端。這使得Web服務(wù)客戶端的寫入更加方便 要使用Feign創(chuàng)建一個界面并對其進(jìn)行注釋。它具有可插拔注釋支持,包...

    vibiu 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<