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

AsyncHttpClient?ClientStats源碼流程解讀

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

本文主要研究一下AsyncHttpClient的ClientStats

ClientStats

org/asynchttpclient/ClientStats.java

/**
 * A record class representing the state of an (@link org.asynchttpclient.AsyncHttpClient).
 */
public class ClientStats {
  private final Map<String, HostStats> statsPerHost;
  public ClientStats(Map<String, HostStats> statsPerHost) {
    this.statsPerHost = Collections.unmodifiableMap(statsPerHost);
  }
  /**
   * @return A map from hostname to statistics on that host's connections.
   * The returned map is unmodifiable.
   */
  public Map<String, HostStats> getStatsPerHost() {
    return statsPerHost;
  }
  /**
   * @return The sum of {@link #getTotalActiveConnectionCount()} and {@link #getTotalIdleConnectionCount()},
   * a long representing the total number of connections in the connection pool.
   */
  public long getTotalConnectionCount() {
    return statsPerHost
            .values()
            .stream()
            .mapToLong(HostStats::getHostConnectionCount)
            .sum();
  }
  /**
   * @return A long representing the number of active connections in the connection pool.
   */
  public long getTotalActiveConnectionCount() {
    return statsPerHost
            .values()
            .stream()
            .mapToLong(HostStats::getHostActiveConnectionCount)
            .sum();
  }
  /**
   * @return A long representing the number of idle connections in the connection pool.
   */
  public long getTotalIdleConnectionCount() {
    return statsPerHost
            .values()
            .stream()
            .mapToLong(HostStats::getHostIdleConnectionCount)
            .sum();
  }
  @Override
  public String toString() {
    return "There are " + getTotalConnectionCount() +
            " total connections, " + getTotalActiveConnectionCount() +
            " are active and " + getTotalIdleConnectionCount() + " are idle.";
  }
  @Override
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    final ClientStats that = (ClientStats) o;
    return Objects.equals(statsPerHost, that.statsPerHost);
  }
  @Override
  public int hashCode() {
    return Objects.hashCode(statsPerHost);
  }
}
ClientStats通過Map<String, HostStats>維護了每個host對應的統(tǒng)計;它提供了getStatsPerHost、getTotalConnectionCount、getTotalActiveConnectionCount、getTotalIdleConnectionCount方法

HostStats

org/asynchttpclient/HostStats.java

/**
 * A record class representing the status of connections to some host.
 */
public class HostStats {
  private final long activeConnectionCount;
  private final long idleConnectionCount;
  public HostStats(long activeConnectionCount,
                   long idleConnectionCount) {
    this.activeConnectionCount = activeConnectionCount;
    this.idleConnectionCount = idleConnectionCount;
  }
  /**
   * @return The sum of {@link #getHostActiveConnectionCount()} and {@link #getHostIdleConnectionCount()},
   * a long representing the total number of connections to this host.
   */
  public long getHostConnectionCount() {
    return activeConnectionCount + idleConnectionCount;
  }
  /**
   * @return A long representing the number of active connections to the host.
   */
  public long getHostActiveConnectionCount() {
    return activeConnectionCount;
  }
  /**
   * @return A long representing the number of idle connections in the connection pool.
   */
  public long getHostIdleConnectionCount() {
    return idleConnectionCount;
  }
  @Override
  public String toString() {
    return "There are " + getHostConnectionCount() +
            " total connections, " + getHostActiveConnectionCount() +
            " are active and " + getHostIdleConnectionCount() + " are idle.";
  }
  @Override
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    final HostStats hostStats = (HostStats) o;
    return activeConnectionCount == hostStats.activeConnectionCount &&
            idleConnectionCount == hostStats.idleConnectionCount;
  }
  @Override
  public int hashCode() {
    return Objects.hash(activeConnectionCount, idleConnectionCount);
  }
}
HostStats定義了activeConnectionCount、idleConnectionCount屬性

getClientStats

org/asynchttpclient/netty/channel/ChannelManager.java

public ClientStats getClientStats() {
    Map<String, Long> totalConnectionsPerHost = openChannels.stream().map(Channel::remoteAddress).filter(a -> a.getClass() == InetSocketAddress.class)
            .map(a -> (InetSocketAddress) a).map(InetSocketAddress::getHostName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    Map<String, Long> idleConnectionsPerHost = channelPool.getIdleChannelCountPerHost();
    Map<String, HostStats> statsPerHost = totalConnectionsPerHost.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> {
      final long totalConnectionCount = entry.getValue();
      final long idleConnectionCount = idleConnectionsPerHost.getOrDefault(entry.getKey(), 0L);
      final long activeConnectionCount = totalConnectionCount - idleConnectionCount;
      return new HostStats(activeConnectionCount, idleConnectionCount);
    }));
    return new ClientStats(statsPerHost);
  }
ChannelManager提供了getClientStats方法,它從openChannels獲取totalConnectionsPerHost,從channelPool.getIdleChannelCountPerHost()獲取idleConnectionCount,然后創(chuàng)建HostStats,最后返回ClientStats

小結

AsyncHttpClient提供了ClientStats用于獲取連接的統(tǒng)計信息,可按host維度,統(tǒng)計activeConnectionCount、idleConnectionCount,也可匯總查看totalConnectionCount、totalActiveConnectionCount、totalIdleConnectionCount。它可以從ChannelManager獲取。對于使用micrometer的可以使用這個作為數(shù)據(jù)源進行適配。

以上就是AsyncHttpClient ClientStats源碼流程解讀的詳細內(nèi)容,更多關于AsyncHttpClient ClientStats的資料請關注腳本之家其它相關文章!

相關文章

  • spring?retry方法調用失敗重試機制示例解析

    spring?retry方法調用失敗重試機制示例解析

    這篇文章主要為大家介紹了spring?retry方法調用失敗重試機制的示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步
    2022-03-03
  • springboot全局異常處理詳解

    springboot全局異常處理詳解

    本篇文章主要介紹了springboot全局異常處理詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • SpringBoot配置文件的優(yōu)先級順序、加載順序、bootstrap.yml與application.yml區(qū)別及說明

    SpringBoot配置文件的優(yōu)先級順序、加載順序、bootstrap.yml與application.yml區(qū)別及說明

    在SpringBoot中,配置文件的優(yōu)先級順序是:application-{profile}.yml或.properties > application.yml或.properties > bootstrap.yml或.properties,{profile}代表不同環(huán)境,如dev、test、prod,加載順序是先加載bootstrap文件
    2024-09-09
  • java中關于命令執(zhí)行匯總

    java中關于命令執(zhí)行匯總

    這篇文章主要介紹了java中關于命令執(zhí)行匯總,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Java中Calendar類用法實例詳解

    Java中Calendar類用法實例詳解

    這篇文章主要給大家介紹了關于Java中Calendar類用法的相關資料,Calendar類是Java.util包中提供的一個抽象類,該類從JDK1.1開始出現(xiàn),作為Date類的替代方案,Calendar類中包含了對不同國家地區(qū)日歷的處理,需要的朋友可以參考下
    2023-09-09
  • SpringBoot的application.yml不生效問題及解決

    SpringBoot的application.yml不生效問題及解決

    這篇文章主要介紹了SpringBoot的application.yml不生效問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • idea如何保存當前已修改的文件|恢復到未修改狀態(tài)

    idea如何保存當前已修改的文件|恢復到未修改狀態(tài)

    文章主要介紹了如何在Git中將修改暫存起來以及如何恢復這些暫存的修改,詳細步驟包括提交修改、保存修改、查看和恢復修改等過程
    2026-04-04
  • Java調用Redis集群代碼及問題解決

    Java調用Redis集群代碼及問題解決

    這篇文章主要介紹了Java調用Redis集群代碼及問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-08-08
  • SpringBoot 優(yōu)雅停機實現(xiàn)原理與最佳實踐指南

    SpringBoot 優(yōu)雅停機實現(xiàn)原理與最佳實踐指南

    文章介紹了Spring Boot在2.3版本中引入的優(yōu)雅停機機制,詳細解釋了優(yōu)雅停機的概念、核心組件與層級關系、Spring Boot 2.3前后的區(qū)別,以及在生產(chǎn)環(huán)境中的最佳實踐,強調了啟用優(yōu)雅停機的重要性,以提高系統(tǒng)的高可用性和穩(wěn)定性
    2026-04-04
  • Java SpringBoot在RequestBody中高效的使用枚舉參數(shù)原理案例詳解

    Java SpringBoot在RequestBody中高效的使用枚舉參數(shù)原理案例詳解

    這篇文章主要介紹了Java SpringBoot在RequestBody中高效的使用枚舉參數(shù)原理案例詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-09-09

最新評論

白山市| 青阳县| 巴彦淖尔市| 汕头市| 濮阳市| 潞城市| 萨迦县| 陆丰市| 望奎县| 安西县| 稻城县| 年辖:市辖区| 南康市| 轮台县| 阜南县| 麻江县| 辽中县| 贵港市| 东乌| 高要市| 沙田区| 泗阳县| 梅州市| 马尔康县| 泰和县| 乡宁县| 奉化市| 武夷山市| 文山县| 卓资县| 晋江市| 桃江县| 平凉市| 张家界市| 昌黎县| 泰顺县| 同江市| 宿松县| 安陆市| 即墨市| 蕉岭县|