最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AsyncHttpClient exception異常源碼流程解析

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

本文主要研究一下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方法,它會關(guān)閉或abort當前的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的時候會拋出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的時候,對于future未完成也沒有重試的時候會執(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方法在全局連接超出限制時拋出tooManyConnections,在單host連接超出限制時拋出tooManyConnectionsPerHost

小結(jié)

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

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

相關(guān)文章

  • 在controller中如何設(shè)置接收參數(shù)的默認值

    在controller中如何設(shè)置接收參數(shù)的默認值

    這篇文章主要介紹了在controller中如何設(shè)置接收參數(shù)的默認值,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • http basic authentication通過post方式訪問api示例分享 basic認證示例

    http basic authentication通過post方式訪問api示例分享 basic認證示例

    在HTTP中,基本認證是一種用來允許Web瀏覽器或其他客戶端程序在請求時提供以用戶名和口令形式的憑證,這篇文章主要介紹了http basic authentication通過post方式訪問api示例,大家參考使用吧
    2014-01-01
  • java運行windows的cmd命令簡單代碼

    java運行windows的cmd命令簡單代碼

    這篇文章主要介紹了java運行windows的cmd命令簡單代碼,有需要的朋友可以參考一下
    2013-12-12
  • Java 使用Socket正確讀取數(shù)據(jù)姿勢

    Java 使用Socket正確讀取數(shù)據(jù)姿勢

    這篇文章主要介紹了Java 使用Socket正確讀取數(shù)據(jù)姿勢,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java中的15種鎖

    Java中的15種鎖

    在讀很多并發(fā)文章中,會提及各種各樣鎖如公平鎖,樂觀鎖等等,這篇文章小編將向大家介紹是各種鎖的分類,感興趣的小伙伴可以參考下面文章的具體內(nèi)容
    2021-09-09
  • SpringBoot 集成 ShedLock 分布式鎖的示例詳解

    SpringBoot 集成 ShedLock 分布式鎖的示例詳解

    ShedLock是一個在分布式環(huán)境中使用的定時任務(wù)框架,用于解決在分布式環(huán)境中的多個實例的相同定時任務(wù)在同一時間點重復(fù)執(zhí)行的問題,本文重點給大家介紹SpringBoot 分布式鎖ShedLock的相關(guān)知識,感興趣的朋友一起看看吧
    2021-08-08
  • SpringBoot返回前端Long型丟失精度后兩位變成00的解決

    SpringBoot返回前端Long型丟失精度后兩位變成00的解決

    在后端開發(fā)中,當Long類型的ID超過19位時,前端JavaScript可能會出現(xiàn)精度問題,導(dǎo)致最后兩位變成00,本文提出了三種解決方案:將ID轉(zhuǎn)換為字符串、使用@JsonSerialize注解和使用@JsonFormat注解,通過這些方法,可以確保ID在前后端傳輸過程中不會發(fā)生精度丟失
    2026-01-01
  • Java實現(xiàn)一行一行讀取文本的多種方法詳解

    Java實現(xiàn)一行一行讀取文本的多種方法詳解

    這篇文章主要為大家詳細介紹了Java實現(xiàn)一行一行讀取文本的多種方法,文中的示例代碼講解詳細,具有一定的借鑒價值,有需要的小伙伴可以了解下
    2025-10-10
  • Java Apache POI實現(xiàn)導(dǎo)出Excel的實戰(zhàn)指南

    Java Apache POI實現(xiàn)導(dǎo)出Excel的實戰(zhàn)指南

    在企業(yè)級開發(fā)中,Excel 數(shù)據(jù)導(dǎo)出是高頻需求,本文基于 Apache POI 實現(xiàn)災(zāi)情速報員數(shù)據(jù) Excel 導(dǎo)出功能,文中的示例代碼講解詳細,感興趣的小伙伴可以了解下
    2026-04-04
  • mybatis連接MySQL8出現(xiàn)的問題解決方法

    mybatis連接MySQL8出現(xiàn)的問題解決方法

    這篇文章主要介紹了mybatis連接MySQL8出現(xiàn)的問題解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-10-10

最新評論

孝感市| 五华县| 神池县| 清镇市| 滦平县| 宜兰市| 山丹县| 田阳县| 林周县| 万宁市| 惠来县| 德阳市| 金门县| 西吉县| 凌源市| 富平县| 鄂州市| 彩票| 卓尼县| 镇平县| 襄城县| 唐山市| 阳朔县| 当阳市| 松原市| 汉寿县| 金塔县| 肇州县| 尉氏县| 乃东县| 顺昌县| 鄱阳县| 宣汉县| 乐东| 建宁县| 锦屏县| 房山区| 青冈县| 高唐县| 怀来县| 扎兰屯市|