style: 全项目统一 Tab 缩进并补全尾随逗号

This commit is contained in:
2026-11-07 13:54:46 +08:00
parent 7a3bc01b11
commit 5714aef444
195 changed files with 37684 additions and 37406 deletions
@@ -61,63 +61,63 @@ import org.springframework.context.event.EventListener
@ConditionalOnClass(name = ["okhttp3.OkHttpClient"])
open class Okhttp3AutoConfiguration {
companion object {
val log: Logger = MingLiLoggerFactory.getLogger<Okhttp3AutoConfiguration>()
}
companion object {
val log: Logger = MingLiLoggerFactory.getLogger<Okhttp3AutoConfiguration>()
}
/**
* 由本配置创建并注册的 [okhttp3.OkHttpClient] 实例,供上下文关闭时清理使用。
*
* 当调用方自行声明了 `OkHttpClient` Bean 时,本配置的 Bean 方法不会执行,
* 该字段保持 `null`,关闭时的清理逻辑也会相应跳过。
*/
var okhttp: okhttp3.OkHttpClient? = null
/**
* 由本配置创建并注册的 [okhttp3.OkHttpClient] 实例,供上下文关闭时清理使用。
*
* 当调用方自行声明了 `OkHttpClient` Bean 时,本配置的 Bean 方法不会执行,
* 该字段保持 `null`,关闭时的清理逻辑也会相应跳过。
*/
var okhttp: okhttp3.OkHttpClient? = null
/**
* 创建默认的 [okhttp3.OkHttpClient] Bean。
*
* 依次应用容器中所有 [OkhttpBuilder] 定制器后构建客户端。没有任何定制器时
* 也能正常构建([ObjectProvider] 允许零个元素)。
*
* 该 Bean 仅在容器中不存在其他 `OkHttpClient` 时创建;若调用方已自行声明,
* 本方法不会被调用。
*
* @param builders 容器中的 OkHttp 构建定制器,按 `@Order` 排序后依次应用
* @return 构建完成的 OkHttp 客户端
*/
@Bean
@ConditionalOnMissingBean
open fun okHttpClient(builders: ObjectProvider<OkhttpBuilder>): okhttp3.OkHttpClient {
var connt = 0
return okhttp3.OkHttpClient.Builder().let { builder ->
var b = builder
builders.orderedStream().forEach {
b = it.customize(b)
connt++
}
b.build()
}.also {
okhttp = it
log.info("load $connt OkhttpBuilder initialized OkHttpClient successfully")
}
}
/**
* 创建默认的 [okhttp3.OkHttpClient] Bean。
*
* 依次应用容器中所有 [OkhttpBuilder] 定制器后构建客户端。没有任何定制器时
* 也能正常构建([ObjectProvider] 允许零个元素)。
*
* 该 Bean 仅在容器中不存在其他 `OkHttpClient` 时创建;若调用方已自行声明,
* 本方法不会被调用。
*
* @param builders 容器中的 OkHttp 构建定制器,按 `@Order` 排序后依次应用
* @return 构建完成的 OkHttp 客户端
*/
@Bean
@ConditionalOnMissingBean
open fun okHttpClient(builders: ObjectProvider<OkhttpBuilder>): okhttp3.OkHttpClient {
var connt = 0
return okhttp3.OkHttpClient.Builder().let { builder ->
var b = builder
builders.orderedStream().forEach {
b = it.customize(b)
connt++
}
b.build()
}.also {
okhttp = it
log.info("load $connt OkhttpBuilder initialized OkHttpClient successfully")
}
}
/**
* 在 Spring 上下文关闭时清理本配置创建的 OkHttp 客户端。
*
* 执行两步清理:
* 1. [okhttp3.ConnectionPool.evictAll] 立即关闭连接池中的空闲连接;
* 2. 关闭 [okhttp3.Dispatcher] 的线程池,中断未完成的任务。
*
* 仅当 [okhttp] 字段非空(即客户端由本配置创建)时执行;
* 调用方自行声明的客户端不会被清理。
*/
@EventListener(ContextClosedEvent::class)
open fun handleContextClosed() {
okhttp?.let {
log.info("Context closed, cleaning up OkHttpClient...")
it.connectionPool.evictAll()
it.dispatcher.executorService.shutdownNow()
}
}
/**
* 在 Spring 上下文关闭时清理本配置创建的 OkHttp 客户端。
*
* 执行两步清理:
* 1. [okhttp3.ConnectionPool.evictAll] 立即关闭连接池中的空闲连接;
* 2. 关闭 [okhttp3.Dispatcher] 的线程池,中断未完成的任务。
*
* 仅当 [okhttp] 字段非空(即客户端由本配置创建)时执行;
* 调用方自行声明的客户端不会被清理。
*/
@EventListener(ContextClosedEvent::class)
open fun handleContextClosed() {
okhttp?.let {
log.info("Context closed, cleaning up OkHttpClient...")
it.connectionPool.evictAll()
it.dispatcher.executorService.shutdownNow()
}
}
}