当前位置: 首页 > news >正文

聊聊HttpClientBuilder

本文主要研究一下HttpClientBuilder

HttpClientBuilder

httpclient-4.5.10-sources.jar!/org/apache/http/impl/client/HttpClientBuilder.java

public class HttpClientBuilder {public static HttpClientBuilder create() {return new HttpClientBuilder();}protected HttpClientBuilder() {super();}public CloseableHttpClient build() {// Create main request executor// We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong versionPublicSuffixMatcher publicSuffixMatcherCopy = this.publicSuffixMatcher;if (publicSuffixMatcherCopy == null) {publicSuffixMatcherCopy = PublicSuffixMatcherLoader.getDefault();}HttpRequestExecutor requestExecCopy = this.requestExec;if (requestExecCopy == null) {requestExecCopy = new HttpRequestExecutor();}HttpClientConnectionManager connManagerCopy = this.connManager;if (connManagerCopy == null) {LayeredConnectionSocketFactory sslSocketFactoryCopy = this.sslSocketFactory;if (sslSocketFactoryCopy == null) {final String[] supportedProtocols = systemProperties ? split(System.getProperty("https.protocols")) : null;final String[] supportedCipherSuites = systemProperties ? split(System.getProperty("https.cipherSuites")) : null;HostnameVerifier hostnameVerifierCopy = this.hostnameVerifier;if (hostnameVerifierCopy == null) {hostnameVerifierCopy = new DefaultHostnameVerifier(publicSuffixMatcherCopy);}if (sslContext != null) {sslSocketFactoryCopy = new SSLConnectionSocketFactory(sslContext, supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);} else {if (systemProperties) {sslSocketFactoryCopy = new SSLConnectionSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault(),supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);} else {sslSocketFactoryCopy = new SSLConnectionSocketFactory(SSLContexts.createDefault(),hostnameVerifierCopy);}}}@SuppressWarnings("resource")final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactoryCopy).build(),null,null,dnsResolver,connTimeToLive,connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS);if (defaultSocketConfig != null) {poolingmgr.setDefaultSocketConfig(defaultSocketConfig);}if (defaultConnectionConfig != null) {poolingmgr.setDefaultConnectionConfig(defaultConnectionConfig);}if (systemProperties) {String s = System.getProperty("http.keepAlive", "true");if ("true".equalsIgnoreCase(s)) {s = System.getProperty("http.maxConnections", "5");final int max = Integer.parseInt(s);poolingmgr.setDefaultMaxPerRoute(max);poolingmgr.setMaxTotal(2 * max);}}if (maxConnTotal > 0) {poolingmgr.setMaxTotal(maxConnTotal);}if (maxConnPerRoute > 0) {poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);}connManagerCopy = poolingmgr;}ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;if (reuseStrategyCopy == null) {if (systemProperties) {final String s = System.getProperty("http.keepAlive", "true");if ("true".equalsIgnoreCase(s)) {reuseStrategyCopy = DefaultClientConnectionReuseStrategy.INSTANCE;} else {reuseStrategyCopy = NoConnectionReuseStrategy.INSTANCE;}} else {reuseStrategyCopy = DefaultClientConnectionReuseStrategy.INSTANCE;}}ConnectionKeepAliveStrategy keepAliveStrategyCopy = this.keepAliveStrategy;if (keepAliveStrategyCopy == null) {keepAliveStrategyCopy = DefaultConnectionKeepAliveStrategy.INSTANCE;}AuthenticationStrategy targetAuthStrategyCopy = this.targetAuthStrategy;if (targetAuthStrategyCopy == null) {targetAuthStrategyCopy = TargetAuthenticationStrategy.INSTANCE;}AuthenticationStrategy proxyAuthStrategyCopy = this.proxyAuthStrategy;if (proxyAuthStrategyCopy == null) {proxyAuthStrategyCopy = ProxyAuthenticationStrategy.INSTANCE;}UserTokenHandler userTokenHandlerCopy = this.userTokenHandler;if (userTokenHandlerCopy == null) {if (!connectionStateDisabled) {userTokenHandlerCopy = DefaultUserTokenHandler.INSTANCE;} else {userTokenHandlerCopy = NoopUserTokenHandler.INSTANCE;}}String userAgentCopy = this.userAgent;if (userAgentCopy == null) {if (systemProperties) {userAgentCopy = System.getProperty("http.agent");}if (userAgentCopy == null && !defaultUserAgentDisabled) {userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient","org.apache.http.client", getClass());}}ClientExecChain execChain = createMainExec(requestExecCopy,connManagerCopy,reuseStrategyCopy,keepAliveStrategyCopy,new ImmutableHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)),targetAuthStrategyCopy,proxyAuthStrategyCopy,userTokenHandlerCopy);execChain = decorateMainExec(execChain);HttpProcessor httpprocessorCopy = this.httpprocessor;if (httpprocessorCopy == null) {final HttpProcessorBuilder b = HttpProcessorBuilder.create();if (requestFirst != null) {for (final HttpRequestInterceptor i: requestFirst) {b.addFirst(i);}}if (responseFirst != null) {for (final HttpResponseInterceptor i: responseFirst) {b.addFirst(i);}}b.addAll(new RequestDefaultHeaders(defaultHeaders),new RequestContent(),new RequestTargetHost(),new RequestClientConnControl(),new RequestUserAgent(userAgentCopy),new RequestExpectContinue());if (!cookieManagementDisabled) {b.add(new RequestAddCookies());}if (!contentCompressionDisabled) {if (contentDecoderMap != null) {final List<String> encodings = new ArrayList<String>(contentDecoderMap.keySet());Collections.sort(encodings);b.add(new RequestAcceptEncoding(encodings));} else {b.add(new RequestAcceptEncoding());}}if (!authCachingDisabled) {b.add(new RequestAuthCache());}if (!cookieManagementDisabled) {b.add(new ResponseProcessCookies());}if (!contentCompressionDisabled) {if (contentDecoderMap != null) {final RegistryBuilder<InputStreamFactory> b2 = RegistryBuilder.create();for (final Map.Entry<String, InputStreamFactory> entry: contentDecoderMap.entrySet()) {b2.register(entry.getKey(), entry.getValue());}b.add(new ResponseContentEncoding(b2.build()));} else {b.add(new ResponseContentEncoding());}}if (requestLast != null) {for (final HttpRequestInterceptor i: requestLast) {b.addLast(i);}}if (responseLast != null) {for (final HttpResponseInterceptor i: responseLast) {b.addLast(i);}}httpprocessorCopy = b.build();}execChain = new ProtocolExec(execChain, httpprocessorCopy);execChain = decorateProtocolExec(execChain);// Add request retry executor, if not disabledif (!automaticRetriesDisabled) {HttpRequestRetryHandler retryHandlerCopy = this.retryHandler;if (retryHandlerCopy == null) {retryHandlerCopy = DefaultHttpRequestRetryHandler.INSTANCE;}execChain = new RetryExec(execChain, retryHandlerCopy);}HttpRoutePlanner routePlannerCopy = this.routePlanner;if (routePlannerCopy == null) {SchemePortResolver schemePortResolverCopy = this.schemePortResolver;if (schemePortResolverCopy == null) {schemePortResolverCopy = DefaultSchemePortResolver.INSTANCE;}if (proxy != null) {routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy);} else if (systemProperties) {routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, ProxySelector.getDefault());} else {routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);}}// Optionally, add service unavailable retry executorfinal ServiceUnavailableRetryStrategy serviceUnavailStrategyCopy = this.serviceUnavailStrategy;if (serviceUnavailStrategyCopy != null) {execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategyCopy);}// Add redirect executor, if not disabledif (!redirectHandlingDisabled) {RedirectStrategy redirectStrategyCopy = this.redirectStrategy;if (redirectStrategyCopy == null) {redirectStrategyCopy = DefaultRedirectStrategy.INSTANCE;}execChain = new RedirectExec(execChain, routePlannerCopy, redirectStrategyCopy);}// Optionally, add connection back-off executorif (this.backoffManager != null && this.connectionBackoffStrategy != null) {execChain = new BackoffStrategyExec(execChain, this.connectionBackoffStrategy, this.backoffManager);}Lookup<AuthSchemeProvider> authSchemeRegistryCopy = this.authSchemeRegistry;if (authSchemeRegistryCopy == null) {authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.BASIC, new BasicSchemeFactory()).register(AuthSchemes.DIGEST, new DigestSchemeFactory()).register(AuthSchemes.NTLM, new NTLMSchemeFactory()).register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()).register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build();}Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;if (cookieSpecRegistryCopy == null) {cookieSpecRegistryCopy = CookieSpecRegistries.createDefault(publicSuffixMatcherCopy);}CookieStore defaultCookieStore = this.cookieStore;if (defaultCookieStore == null) {defaultCookieStore = new BasicCookieStore();}CredentialsProvider defaultCredentialsProvider = this.credentialsProvider;if (defaultCredentialsProvider == null) {if (systemProperties) {defaultCredentialsProvider = new SystemDefaultCredentialsProvider();} else {defaultCredentialsProvider = new BasicCredentialsProvider();}}List<Closeable> closeablesCopy = closeables != null ? new ArrayList<Closeable>(closeables) : null;if (!this.connManagerShared) {if (closeablesCopy == null) {closeablesCopy = new ArrayList<Closeable>(1);}final HttpClientConnectionManager cm = connManagerCopy;if (evictExpiredConnections || evictIdleConnections) {final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(cm,maxIdleTime > 0 ? maxIdleTime : 10, maxIdleTimeUnit != null ? maxIdleTimeUnit : TimeUnit.SECONDS,maxIdleTime, maxIdleTimeUnit);closeablesCopy.add(new Closeable() {@Overridepublic void close() throws IOException {connectionEvictor.shutdown();try {connectionEvictor.awaitTermination(1L, TimeUnit.SECONDS);} catch (final InterruptedException interrupted) {Thread.currentThread().interrupt();}}});connectionEvictor.start();}closeablesCopy.add(new Closeable() {@Overridepublic void close() throws IOException {cm.shutdown();}});}return new InternalHttpClient(execChain,connManagerCopy,routePlannerCopy,cookieSpecRegistryCopy,authSchemeRegistryCopy,defaultCookieStore,defaultCredentialsProvider,defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.DEFAULT,closeablesCopy);}
}

HttpClientBuilder提供了静态方法create用于创建builder,其build方法用于创建CloseableHttpClient,它主要是构建ClientExecChain(HttpRequestExecutor、HttpClientConnectionManager、ConnectionReuseStrategy、ConnectionKeepAliveStrategy、AuthenticationStrategy、UserTokenHandler)、ProtocolExec(ClientExecChain、HttpProcessor)、RetryExec(ClientExecChain、HttpRequestRetryHandler)、RedirectExec(HttpRoutePlanner、ServiceUnavailableRetryStrategy、RedirectStrategy)、BackoffStrategyExec;最后构建的是InternalHttpClient

SSLContext

org/apache/http/ssl/SSLContexts.java
对于sslContext不为null的则创建SSLConnectionSocketFactory(sslContext, supportedProtocols, supportedCipherSuites, hostnameVerifierCopy),为null的话,则通过SSLContexts.createDefault()来创建默认的SSLContext

public static SSLContext createDefault() throws SSLInitializationException {try {final SSLContext sslContext = SSLContext.getInstance(SSLContextBuilder.TLS);sslContext.init(null, null, null);return sslContext;} catch (final NoSuchAlgorithmException ex) {throw new SSLInitializationException(ex.getMessage(), ex);} catch (final KeyManagementException ex) {throw new SSLInitializationException(ex.getMessage(), ex);}}

HostnameVerifier

若hostnameVerifier为null,则创建默认的DefaultHostnameVerifier

public DefaultHostnameVerifier(final PublicSuffixMatcher publicSuffixMatcher) {this.publicSuffixMatcher = publicSuffixMatcher;}public DefaultHostnameVerifier() {this(null);}@Overridepublic boolean verify(final String host, final SSLSession session) {try {final Certificate[] certs = session.getPeerCertificates();final X509Certificate x509 = (X509Certificate) certs[0];verify(host, x509);return true;} catch (final SSLException ex) {if (log.isDebugEnabled()) {log.debug(ex.getMessage(), ex);}return false;}}

PoolingHttpClientConnectionManager

org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java

@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
public class PoolingHttpClientConnectionManagerimplements HttpClientConnectionManager, ConnPoolControl<HttpRoute>, Closeable {private final ConfigData configData;private final CPool pool;private final HttpClientConnectionOperator connectionOperator;private final AtomicBoolean isShutDown;public PoolingHttpClientConnectionManager(final HttpClientConnectionOperator httpClientConnectionOperator,final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,final long timeToLive, final TimeUnit timeUnit) {super();this.configData = new ConfigData();this.pool = new CPool(new InternalConnectionFactory(this.configData, connFactory), 2, 20, timeToLive, timeUnit);this.pool.setValidateAfterInactivity(2000);this.connectionOperator = Args.notNull(httpClientConnectionOperator, "HttpClientConnectionOperator");this.isShutDown = new AtomicBoolean(false);}@Overrideprotected void finalize() throws Throwable {try {shutdown();} finally {super.finalize();}}@Overridepublic void close() {shutdown();}//......
}    

PoolingHttpClientConnectionManager实现了HttpClientConnectionManager、ConnPoolControl、Closeable接口,它使用了CPool作为连接池来管理连接,默认的maxPerRoute为2,maxTotal为20

小结

apache的httpclient的HttpClientBuilder提供了构建CloseableHttpClient的方法,它提供了设置sslContext的方法,如果没有设置则通过SSLContexts.createDefault()来创建默认的SSLContext,若hostnameVerifier为null,则创建默认的DefaultHostnameVerifier,其默认会创建HttpClientConnectionManager,使用的是maxPerRoute为2,maxTotal为20的连接池。

相关文章:

聊聊HttpClientBuilder

序 本文主要研究一下HttpClientBuilder HttpClientBuilder httpclient-4.5.10-sources.jar!/org/apache/http/impl/client/HttpClientBuilder.java public class HttpClientBuilder {public static HttpClientBuilder create() {return new HttpClientBuilder();}protected…...

MacOS - Sonoma更新了啥

1 系统介绍 苹果公司于2023年9月26日发布了macOS Sonoma 14.0正式版。名称由来不知道&#xff0c;可能是地名&#xff1a;Sonoma是一个地名,指加利福尼亚州北部索诺玛县(Sonoma County)。 2 系统重要更新 2.1 将小组件添加到桌面 速览提醒事项和临近日程等。按住Control键点…...

C++17中头文件filesystem的使用

C17引入了std::filesystem库(文件系统库, filesystem library)&#xff0c;相关类及函数的声明在头文件filesystem中&#xff0c;命名空间为std::filesystem。 1.path类&#xff1a;文件路径相关操作&#xff0c;如指定的路径是否存在等&#xff0c;其介绍参见&#xff1a;http…...

「专题速递」数字人直播带货、传统行业数字化升级、远程协作中的低延时视频、地产物业中的通讯终端...

音视频技术作为企业数字化转型的核心要素之一&#xff0c;已在各行各业展现出广泛的应用和卓越的价值。实时通信、社交互动、高清视频等技术不仅令传统行业焕发新生&#xff0c;还为其在生产、管理、服务提供与维护等各个领域带来了巨大的助力&#xff0c;实现了生产效率和服务…...

PE格式之PE头部

1. PE头部总体组成 2. DOS MZ头 3. PE头 PE头由3部分组成: 下面分别: OptionalHeader比较大: 然后是节表, 节表有多个: PE文件头部就结束了, 最后就是节区了, 来看几段代码: ; main.asm .586 .model flat, stdcall option casemap:noneinclude windows.inc include ke…...

SLAM从入门到精通(用python实现机器人运动控制)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 在ROS下面&#xff0c;开发的方法很多&#xff0c;可以是c&#xff0c;可以是python。大部分接口操作类的应用&#xff0c;其实都可以用python来开…...

接口和抽象类有什么区别?

接口和抽象类都是用于实现抽象类型的机制: 抽象类:抽象类可以包含抽象方法(未实现的方法)和具体方法(已实现的方法)。抽象类可以有字段(成员变量),这些字段可以是具体的,也可以是抽象的。一个类只能继承一个抽象类,Java不支持多继承。抽象类可以拥有构造方法,用于初…...

基于springboot+vue的人事系统

目录 前言 一、技术栈 二、系统功能介绍 员工信息管理 考勤信息管理 考勤信息管理 下班记录管理 三、核心代码 1、登录模块 2、文件上传模块 3、代码封装 前言 随着信息技术在管理上越来越深入而广泛的应用&#xff0c;作为学校以及一些培训机构&#xff0c;都在用信息…...

记住这份软件测试八股文还怕不能拿offer?你值得拥有

前言 2023秋招即将来临&#xff0c;很多同学会问软件测试面试八股文有必要背吗&#xff1f; 我的回答是&#xff1a;很有必要。你可以讨厌这种模式&#xff0c;但你一定要去背&#xff0c;因为不背你就进不了大厂。 国内的互联网面试&#xff0c;恐怕是现存的、最接近科举考试…...

2023年,在CSDN拥有10000粉丝有多难?

该数据来源于粉丝数人数排行前5000名用户的关注用户列表中产生的&#xff0c;由于采集样本数有限&#xff0c;数据可能具有一定的误差&#xff0c;仅供参考&#xff0c;本次采样用户数大概在100万以上。 筛选条件人数粉丝人数大于50007519粉丝人数大于100003763粉丝人数大于500…...

C++ -- 学习系列 关联式容器 set 与 map

一 关联式容器是什么&#xff1f; c 中有两种容器类型&#xff1a;关联式容器与序列式容器&#xff08;顺序容器&#xff09; 关联式中的容器是按照关键字来存储与访问的&#xff0c;序列式容器&#xff08;顺序容器&#xff09;则是元素在容器中的相对位置来存储与访问的。…...

Day 04 python学习笔记

Python数据容器 元组 元组的声明 变量名称&#xff08;元素1&#xff0c;元素2&#xff0c;元素3&#xff0c;元素4…….&#xff09; &#xff08;元素类型可以不同&#xff09; eg: tuple_01 ("hello", 1, 2,-20,[11,22,33]) print(type(tuple_01))结果&#x…...

Moonbeam Ignite强势回归

参与Moonbeam上最新的流动性计划 还记得新一轮的流动性激励计划吗&#xff1f;Moonbeam Ignite社区活动带着超过300万枚GLMR奖励来啦&#xff01;体验新项目&#xff0c;顺便薅一把GLMR羊毛。 本次Moonbeam Ignite活动的参与项目均为第二批Moonbeam生态系统Grant资助提案中获…...

【改造后序遍历算法】95. 不同的二叉搜索树 II

95. 不同的二叉搜索树 II 解题思路 遍历每一个节点查看以k为根节点的二叉搜索树储存所有左子树的根节点储存所有右子树的根节点将左子树和右子树组装起来 将根节点储存在向量中 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeN…...

栈的基本操作(数据结构)

顺序栈的基本操作 #include <stdlib.h> #include <iostream> #include <stdio.h> #define MaxSize 10typedef struct{int data[MaxSize];int top; }SqStack;//初始化栈 void InitStack(SqStack &S){S.top -1; } //判断栈空 bool StackEmpty(SqStack S)…...

D. Jellyfish and Mex Codeforces Round 901 (Div. 2)

Problem - D - Codeforces 题目大意&#xff1a;有一个n个数的数组a&#xff0c;数m初始为0&#xff0c;每次操作可以删除任意一个数&#xff0c;然后m加上那个数&#xff0c;求n次操作和m的最小值 1<n<5000&#xff1b;0<a[i]<1e9 思路&#xff1a;可以发现&am…...

操作系统内存管理相关

1. 虚拟内存 1.1 什么是虚拟内存 虚拟内存是计算机系统内存管理的一种技术&#xff0c;我们可以手动设置自己电脑的虚拟内存。不要单纯认为虚拟内存只是“使用硬盘空间来扩展内存“的技术。虚拟内存的重要意义是它定义了一个连续的虚拟地址空间&#xff0c;并且 把内存扩展到硬…...

Sui流动性质押黑客松获胜者公布,助力资产再流通

Sui流动质押黑客松于日前结束Demo Day演示&#xff0c;其中有五个团队获奖、六个团队荣誉提名&#xff0c;共有超过30个项目获得参赛资格。此外&#xff0c;有两个团队赢得了Sui上DeFi协议提供的赏金。 本次黑客松的目的是挖掘并奖励将流动质押功能集成到其apps和产品中的开发…...

为什么在使用PageHelper插件时,指定的每页记录数大小失效?显示所有的记录数

1.问题现象&#xff1a; 这里指定每页显示5条&#xff0c;却把所有的记录数都显示出来了 2.分析&#xff1a; 之前是可以的&#xff0c;然后发现&#xff1a;PageHelper.startPage(pageNum,pageSize) 和执行sql的语句 顺序颠倒了&#xff0c;然后就出错了。 3.验证&#xf…...

XML文档基础

什么是XML XML (eXtensible Markup Language&#xff0c;可扩展标记语言) 是一种用于存储和传输数据的文本文件格式。用户可以按照XML规则自定义标记&#xff0c;XML 的设计目标是传输数据&#xff0c;而不是显示数据&#xff0c;因此它是一种通用的标记语言&#xff0c;可用于…...

软考知识汇总-软件工程

软件工程 1 能力成熟度模型&#xff08;CMM&#xff09;2 能力成熟度模型集成&#xff08;CMMI&#xff09;2.1阶段式模型2.2 连续式模型 3 软件过程模型 1 能力成熟度模型&#xff08;CMM&#xff09; 将软件工程成熟度分为5个级别 初始级&#xff1a;杂乱无章&#xff0c;很…...

力扣:119. 杨辉三角 II(Python3)

题目&#xff1a; 给定一个非负索引 rowIndex&#xff0c;返回「杨辉三角」的第 rowIndex 行。 在「杨辉三角」中&#xff0c;每个数是它左上方和右上方的数的和。 来源&#xff1a;力扣&#xff08;LeetCode&#xff09; 链接&#xff1a;力扣&#xff08;LeetCode&#xff09…...

指针笔试题(带解析版)

题目2&#xff1a; struct MyStruct {int num;char* pcname;short sdate;char cha[2];short sba[4]; }*p; //结构体大小为32字节 //p0x100000 int main() {p 0x100000;printf("%p\n", p 0x1);//p&#xff1a;结构体指针&#xff0c;1下一个结构体指针&#xff0c;…...

服务器搭建(TCP套接字)-libevent版(服务端)

Libevent 是一个开源的事件驱动库&#xff0c;用于开发高性能、并发的网络应用程序。它提供了跨平台的事件处理和网络编程功能&#xff0c;具有高性能、可扩展性和可移植性。下面详细讲解 Libevent 的主要组成部分和使用方法。 一、事件基础结构&#xff08;event_base&#x…...

斐波那契模型系列【动态规划】

动态规划步骤 1、状态表示 是什么&#xff1a;dp表&#xff08;可能是一维或二维数组&#xff09;里的值所表示的含义。 怎么来&#xff1a; 1、题目要求 2、经验题目要求 3、发现重复子问题 2、状态转移方程 dp[i]... 3、初始化 保证填表不越界 4、填表顺序 5、返回值 写代码时…...

【Java】微服务——Nacos注册中心

目录 1.Nacos快速入门1.1.服务注册到nacos1&#xff09;引入依赖2&#xff09;配置nacos地址3&#xff09;重启 2.服务分级存储模型2.1.给user-service配置集群2.2.同集群优先的负载均衡 3.权重配置4.环境隔离4.1.创建namespace4.2.给微服务配置namespace 5.Nacos与Eureka的区别…...

Redis Cluster Gossip Protocol: PING, PONG, MEET

返回目录 PING / PONG / MEET 的发送 过程 计算freshNodes。freshNodes表示在消息中能携带的&#xff0c;在cluster节点字典中的节点总数&#xff0c;但需要减去myself和对端节点&#xff0c;因为myself的信息会存储在消息头中。实际上&#xff0c;并非所有在cluster节点字典…...

httpserver 下载服务器demo 以及libevent版本的 httpserver

实现效果如下&#xff1a; 图片可以直接显示 cpp h 这些可以直接显示 其他的 则是提示是否要下载 单线程 还有bug 代码如下 先放上来 #include "httpserver.h" #include "stdio.h" #include <stdlib.h> #include <arpa/inet.h> #include…...

构建强大的RESTful API:@RestController与@Controller的对比与应用

构建强大的RESTful API&#xff1a;RestController与Controller的对比与应用 前言什么是RESTful APIRestController&#xff0c;Controller&#xff0c;ResponseBody1. Controller注解&#xff1a;2. RestController注解&#xff1a;3. ResponseBody注解&#xff1a; 示例非thy…...

【Java-LangChain:使用 ChatGPT API 搭建系统-10】评估(下)-当不存在一个简单的正确答案时

第十章&#xff0c;评估&#xff08;下&#xff09;-当不存在一个简单的正确答案时 在上一章中&#xff0c;了解了如何评估 LLM 模型在 有明确正确答案 的情况下的输出&#xff0c;我们可以编写一个函数来判断 LLM 输出是否正确地分类并列出产品。 然而&#xff0c;如果 LLM …...