欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

AsyncHttpClient exception異常源碼流程解析

 更新時(shí)間:2023年12月11日 08:36:16   作者:codecraft  
這篇文章主要為大家介紹了AsyncHttpClient的exception源碼流程解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下AsyncHttpClient的exception

ChannelClosedException

org/asynchttpclient/exception/ChannelClosedException.java

public final class ChannelClosedException extends IOException {
  public static final ChannelClosedException INSTANCE = unknownStackTrace(new ChannelClosedException(), ChannelClosedException.class, "INSTANCE");
  private ChannelClosedException() {
    super("Channel closed");
  }
}
ChannelClosedException用于表示Channel closed的異常

handleUnexpectedClosedChannel

org/asynchttpclient/netty/request/NettyRequestSender.java

public void handleUnexpectedClosedChannel(Channel channel, NettyResponseFuture<?> future) {
    if (Channels.isActiveTokenSet(channel)) {
      if (future.isDone()) {
        channelManager.closeChannel(channel);
      } else if (future.incrementRetryAndCheck() && retry(future)) {
        future.pendingException = null;
      } else {
        abort(channel, future,
                future.pendingException != null ? future.pendingException : RemotelyClosedException.INSTANCE);
      }
    }
  }
NettyRequestSender定義了handleUnexpectedClosedChannel方法,它會(huì)關(guān)閉或abort當(dāng)前的channel

PoolAlreadyClosedException

org/asynchttpclient/exception/PoolAlreadyClosedException.java

public class PoolAlreadyClosedException extends IOException {
  public static final PoolAlreadyClosedException INSTANCE = unknownStackTrace(new PoolAlreadyClosedException(), PoolAlreadyClosedException.class, "INSTANCE");
  private PoolAlreadyClosedException() {
    super("Pool is already closed");
  }
}
PoolAlreadyClosedException用于表示連接池已經(jīng)關(guān)閉的異常

sendRequestWithNewChannel

org/asynchttpclient/netty/request/NettyRequestSender.java

private <T> ListenableFuture<T> sendRequestWithNewChannel(Request request,
                                                            ProxyServer proxy,
                                                            NettyResponseFuture<T> future,
                                                            AsyncHandler<T> asyncHandler) {
    // some headers are only set when performing the first request
    HttpHeaders headers = future.getNettyRequest().getHttpRequest().headers();
    Realm realm = future.getRealm();
    Realm proxyRealm = future.getProxyRealm();
    requestFactory.addAuthorizationHeader(headers, perConnectionAuthorizationHeader(request, proxy, realm));
    requestFactory.setProxyAuthorizationHeader(headers, perConnectionProxyAuthorizationHeader(request, proxyRealm));
    future.setInAuth(realm != null && realm.isUsePreemptiveAuth() && realm.getScheme() != AuthScheme.NTLM);
    future.setInProxyAuth(
            proxyRealm != null && proxyRealm.isUsePreemptiveAuth() && proxyRealm.getScheme() != AuthScheme.NTLM);
    try {
      if (!channelManager.isOpen()) {
        throw PoolAlreadyClosedException.INSTANCE;
      }
      // Do not throw an exception when we need an extra connection for a
      // redirect.
      future.acquirePartitionLockLazily();
    } catch (Throwable t) {
      abort(null, future, getCause(t));
      // exit and don't try to resolve address
      return future;
    }
    //......
}
sendRequestWithNewChannel在channelManager非open的時(shí)候會(huì)拋出PoolAlreadyClosedException

RemotelyClosedException

org/asynchttpclient/exception/RemotelyClosedException.java

public final class RemotelyClosedException extends IOException {
  public static final RemotelyClosedException INSTANCE = unknownStackTrace(new RemotelyClosedException(), RemotelyClosedException.class, "INSTANCE");
  RemotelyClosedException() {
    super("Remotely closed");
  }
}
RemotelyClosedException用于表示Remotely closed的異常

handleUnexpectedClosedChannel

org/asynchttpclient/netty/request/NettyRequestSender.java

public void handleUnexpectedClosedChannel(Channel channel, NettyResponseFuture&lt;?&gt; future) {
    if (Channels.isActiveTokenSet(channel)) {
      if (future.isDone()) {
        channelManager.closeChannel(channel);
      } else if (future.incrementRetryAndCheck() &amp;&amp; retry(future)) {
        future.pendingException = null;
      } else {
        abort(channel, future,
                future.pendingException != null ? future.pendingException : RemotelyClosedException.INSTANCE);
      }
    }
  }
NettyRequestSender的handleUnexpectedClosedChannel的時(shí)候,對(duì)于future未完成也沒有重試的時(shí)候會(huì)執(zhí)行abort,并拋出RemotelyClosedException

TooManyConnectionsException

org/asynchttpclient/exception/TooManyConnectionsException.java

public class TooManyConnectionsException extends IOException {
  public TooManyConnectionsException(int max) {
    super("Too many connections: " + max);
  }
}
TooManyConnectionsException用于表示全局連接超過限制的異常

TooManyConnectionsPerHostException

org/asynchttpclient/exception/TooManyConnectionsPerHostException.java

public class TooManyConnectionsPerHostException extends IOException {
  public TooManyConnectionsPerHostException(int max) {
    super("Too many connections: " + max);
  }
}
TooManyConnectionsPerHostException用于表示連接超出單host限制的異常

acquireChannelLock

org/asynchttpclient/netty/channel/ConnectionSemaphore.java

public void acquireChannelLock(Object partitionKey) throws IOException {
    if (!tryAcquireGlobal())
      throw tooManyConnections;
    if (!tryAcquirePerHost(partitionKey)) {
      freeChannels.release();
      throw tooManyConnectionsPerHost;
    }
  }
acquireChannelLock方法在全局連接超出限制時(shí)拋出tooManyConnections,在單host連接超出限制時(shí)拋出tooManyConnectionsPerHost

小結(jié)

AsyncHttpClient一共定義了五個(gè)異常,它們都繼承了IOException,分別是ChannelClosedException、PoolAlreadyClosedException、RemotelyClosedException、TooManyConnectionsException、TooManyConnectionsPerHostException。

以上就是AsyncHttpClient的exception的詳細(xì)內(nèi)容,更多關(guān)于AsyncHttpClient的exception的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 一文教會(huì)Java新手使用Spring?MVC中的查詢字符串和查詢參數(shù)

    一文教會(huì)Java新手使用Spring?MVC中的查詢字符串和查詢參數(shù)

    在使用springMVC框架構(gòu)建web應(yīng)用,客戶端常會(huì)請(qǐng)求字符串、整型、json等格式的數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于通過一文教會(huì)Java新手使用Spring?MVC中的查詢字符串和查詢參數(shù)的相關(guān)資料,需要的朋友可以參考下
    2024-01-01
  • Spring中的Sentinel規(guī)則持久化解析

    Spring中的Sentinel規(guī)則持久化解析

    這篇文章主要介紹了Spring中的Sentinel規(guī)則持久化解析,具體內(nèi)容包括,Sentinel規(guī)則推送三種模式介紹,原始模式,拉模式,推模式,并對(duì)基于Nacos配置中心控制臺(tái)實(shí)現(xiàn)推送進(jìn)行詳盡介紹,需要的朋友可以參考下
    2023-09-09
  • Spring Bean生命周期源碼原理圖解

    Spring Bean生命周期源碼原理圖解

    這篇文章主要介紹了Spring Bean生命周期源碼原理圖解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • MyBatis中的JdbcType映射使用介紹

    MyBatis中的JdbcType映射使用介紹

    這篇文章主要介紹了MyBatis中的JdbcType映射使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Java實(shí)現(xiàn)八個(gè)常用的排序算法:插入排序、冒泡排序、選擇排序、希爾排序等

    Java實(shí)現(xiàn)八個(gè)常用的排序算法:插入排序、冒泡排序、選擇排序、希爾排序等

    這篇文章主要介紹了Java如何實(shí)現(xiàn)八個(gè)常用的排序算法:插入排序、冒泡排序、選擇排序、希爾排序 、快速排序、歸并排序、堆排序和LST基數(shù)排序,需要的朋友可以參考下
    2015-07-07
  • java使用篩選法求n以內(nèi)的素?cái)?shù)示例(java求素?cái)?shù))

    java使用篩選法求n以內(nèi)的素?cái)?shù)示例(java求素?cái)?shù))

    這篇文章主要介紹了java使用篩選法求n以內(nèi)的素?cái)?shù)示例(java求素?cái)?shù)),需要的朋友可以參考下
    2014-04-04
  • Eclipse如何導(dǎo)入Maven項(xiàng)目詳解(新手初學(xué))

    Eclipse如何導(dǎo)入Maven項(xiàng)目詳解(新手初學(xué))

    這篇文章主要介紹了Eclipse如何導(dǎo)入Maven項(xiàng)目詳解(新手初學(xué)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-12-12
  • idea如何關(guān)閉右側(cè)類顯示方法

    idea如何關(guān)閉右側(cè)類顯示方法

    這篇文章主要介紹了idea如何關(guān)閉右側(cè)類顯示方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • idea?2024使用Maven創(chuàng)建Java?Web項(xiàng)目詳細(xì)圖文教程

    idea?2024使用Maven創(chuàng)建Java?Web項(xiàng)目詳細(xì)圖文教程

    這篇文章主要給大家介紹了關(guān)于idea?2024使用Maven創(chuàng)建Java?Web項(xiàng)目的相關(guān)資料,介紹了如何使用Maven創(chuàng)建一個(gè)Spring?MVC項(xiàng)目,并配置Tomcat服務(wù)器以運(yùn)行一個(gè)簡單的Helloworld?JSP頁面,需要的朋友可以參考下
    2024-12-12
  • Java編程簡單應(yīng)用

    Java編程簡單應(yīng)用

    本文主要介紹了三個(gè)簡單Java小程序———1、HelloWorld(HelloWorld的來源);2、輸出個(gè)人信息3、輸出特殊圖案。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02

最新評(píng)論