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

AsyncHttpClient?ClientStats源碼流程解讀

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

本文主要研究一下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通過(guò)Map<String, HostStats>維護(hù)了每個(gè)host對(duì)應(yīng)的統(tǒng)計(jì);它提供了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

小結(jié)

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

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

相關(guān)文章

  • 手把手帶你實(shí)現(xiàn)第一個(gè)Mybatis程序

    手把手帶你實(shí)現(xiàn)第一個(gè)Mybatis程序

    這篇文章主要介紹了mybatis實(shí)現(xiàn)過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-07-07
  • Java中的Vector和ArrayList區(qū)別及比較

    Java中的Vector和ArrayList區(qū)別及比較

    這篇文章主要介紹了Java中的Vector和ArrayList區(qū)別及比較,本文從API、同步、數(shù)據(jù)增長(zhǎng)、使用模式4個(gè)方面總結(jié)了它們之間的不同之處,需要的朋友可以參考下
    2015-03-03
  • Java高性能序列化工具Kryo詳情

    Java高性能序列化工具Kryo詳情

    這篇文章主要介紹了Java高性能序列化工具Kryo詳情,Kryo?是一個(gè)快速序列化/反序列化工具,依賴于字節(jié)碼生成機(jī)制,更多相關(guān)內(nèi)容感興趣的朋友可以參考一下下面文章內(nèi)容
    2022-06-06
  • java int轉(zhuǎn)byte和long轉(zhuǎn)byte的方法

    java int轉(zhuǎn)byte和long轉(zhuǎn)byte的方法

    下面小編就為大家?guī)?lái)一篇java int轉(zhuǎn)byte和long轉(zhuǎn)byte的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-10-10
  • Springboot使用jsp具體案例解析

    Springboot使用jsp具體案例解析

    這篇文章主要介紹了Springboot使用jsp具體案例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • SpringBoot?jwt的token如何刷新

    SpringBoot?jwt的token如何刷新

    這篇文章主要給大家介紹了關(guān)于SpringBoot?jwt的token如何刷新的相關(guān)資料,Json web token(JWT)是為了在網(wǎng)絡(luò)應(yīng)用環(huán)境間傳遞聲明而執(zhí)行的一種基于JSON的開(kāi)放標(biāo)準(zhǔn),需要的朋友可以參考下
    2023-07-07
  • Springboot3整合Mybatis3的完整步驟記錄

    Springboot3整合Mybatis3的完整步驟記錄

    這篇文章主要給大家介紹了關(guān)于Springboot3整合Mybatis3的完整步驟,Spring Boot和MyBatis分別是兩個(gè)功能強(qiáng)大的框架,它們的協(xié)同使用可以極大地簡(jiǎn)化數(shù)據(jù)訪問(wèn)層的開(kāi)發(fā),提高整體的開(kāi)發(fā)效率,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • java控制臺(tái)實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)

    java控制臺(tái)實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了java控制臺(tái)實(shí)現(xiàn)學(xué)生信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • SpringBoot參數(shù)校驗(yàn)之@Validated的使用詳解

    SpringBoot參數(shù)校驗(yàn)之@Validated的使用詳解

    這篇文章主要通過(guò)示例為大家詳細(xì)介紹一下介紹了SpringBoot參數(shù)校驗(yàn)中@Validated的使用方法,文中的示例代碼講解詳細(xì),需要的可以參考一下
    2022-06-06
  • 如何發(fā)布jar包到maven中央倉(cāng)庫(kù)

    如何發(fā)布jar包到maven中央倉(cāng)庫(kù)

    這篇文章主要介紹了發(fā)布jar包到maven中央倉(cāng)庫(kù)的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-12-12

最新評(píng)論