From 6ba77ec7b78fd60a789ef89a78ff47c1da1230fc Mon Sep 17 00:00:00 2001 From: tursom <tursom@foxmail.com> Date: Sun, 11 Apr 2021 23:27:15 +0800 Subject: [PATCH] update --- settings.gradle.kts | 3 + ts-core/build.gradle.kts | 1 + .../tursom/core}/ws/WebSocketFrameWrapper.kt | 2 +- ts-core/ts-json/build.gradle.kts | 34 ++++++ .../main/kotlin/cn/tursom/core}/json/Json.kt | 3 +- .../kotlin/cn/tursom/core/json/JsonWorker.kt | 6 + .../cn/tursom/core/json/JsonWorkerImpl.kt | 29 +++++ .../tursom/{ => core}/ws/WebSocketClient.kt | 2 +- .../ws/WebSocketClientChannelHandler.kt | 2 +- .../ws/WebSocketClientHandshakerAdapter.kt | 2 +- .../tursom/{ => core}/ws/WebSocketHandler.kt | 2 +- ts-web/build.gradle.kts | 35 ++++++ .../kotlin/cn/tursom/web/ExceptionContent.kt | 0 .../main/kotlin/cn/tursom/web/HttpContent.kt | 0 .../main/kotlin/cn/tursom/web/HttpHandler.kt | 0 .../main/kotlin/cn/tursom/web/HttpServer.kt | 0 .../cn/tursom/web/MutableHttpContent.kt | 0 .../cn/tursom/web/RequestHeaderAdapter.kt | 0 .../cn/tursom/web/ResponseHeaderAdapter.kt | 0 .../kotlin/cn/tursom/web/WebSocketContent.kt | 0 .../kotlin/cn/tursom/web/WebSocketHandler.kt | 0 .../cn/tursom/web/mapping/ConnectMapping.kt | 0 .../cn/tursom/web/mapping/DeleteMapping.kt | 0 .../cn/tursom/web/mapping/GetMapping.kt | 0 .../cn/tursom/web/mapping/HeadMapping.kt | 0 .../kotlin/cn/tursom/web/mapping/Mapping.kt | 0 .../cn/tursom/web/mapping/OptionsMapping.kt | 0 .../cn/tursom/web/mapping/PatchMapping.kt | 0 .../cn/tursom/web/mapping/PostMapping.kt | 0 .../cn/tursom/web/mapping/PutMapping.kt | 0 .../cn/tursom/web/mapping/TraceMapping.kt | 0 .../cn/tursom/web/result/ContextType.kt | 0 .../main/kotlin/cn/tursom/web/result/Html.kt | 0 .../main/kotlin/cn/tursom/web/result/Json.kt | 0 .../cn/tursom/web/result/NoReturnLog.kt | 0 .../main/kotlin/cn/tursom/web/result/Text.kt | 0 .../cn/tursom/web/router/BlockHandler.kt | 0 .../cn/tursom/web/router/RoutedHttpHandler.kt | 7 +- .../kotlin/cn/tursom/web/router/Router.kt | 0 .../cn/tursom/web/router/impl/ColonRouter.kt | 0 .../web/router/impl/CurlyBracesRouter.kt | 0 .../cn/tursom/web/router/impl/FilterRouter.kt | 4 +- .../cn/tursom/web/router/impl/SimpleRouter.kt | 0 .../web/router/impl/colonnode/AnyColonNode.kt | 0 .../web/router/impl/colonnode/ColonNode.kt | 0 .../web/router/impl/colonnode/IColonNode.kt | 0 .../impl/colonnode/PlaceholderColonNode.kt | 0 .../cn/tursom/web/utils/CacheControl.kt | 0 .../kotlin/cn/tursom/web/utils/Chunked.kt | 0 .../cn/tursom/web/utils/ContextTypeEnum.kt | 0 .../cn/tursom/web/utils/ContextTypeMap.kt | 0 .../main/kotlin/cn/tursom/web/utils/Cookie.kt | 0 .../cn/tursom/web/utils/EmptyHttpContent.kt | 1 - .../kotlin/cn/tursom/web/utils/HttpUtil.kt | 0 .../kotlin/cn/tursom/web/utils/MethodEnum.kt | 0 .../kotlin/cn/tursom/web/utils/SameSite.kt | 0 .../web/router/impl/FilterRouterTest.kt | 0 .../ts-web-coroutine}/build.gradle | 0 .../src/main/kotlin/cn/tursom/web/Utils.kt | 0 .../web/router/AsyncRoutedHttpHandler.kt | 0 ts-web/ts-web-netty/build.gradle.kts | 34 ++++++ .../tursom/web/netty/HttpContextExchange.kt | 1 - .../web/netty/NettyChunkedByteBuffer.kt | 2 +- .../cn/tursom/web/netty/NettyChunkedInput.kt | 2 +- .../tursom/web/netty/NettyExceptionContent.kt | 2 +- .../cn/tursom/web/netty/NettyHttpContent.kt | 2 +- .../tursom/web/netty/NettyHttpDecodeType.kt | 0 .../cn/tursom/web/netty/NettyHttpHandler.kt | 0 .../web/netty/NettyHttpObjectHandler.kt | 0 .../cn/tursom/web/netty/NettyHttpServer.kt | 2 +- .../web/netty/NettyResponseHeaderAdapter.kt | 0 .../tursom/web/netty/NettyWebSocketContent.kt | 2 +- .../tursom/web/netty/NettyWebSocketHandler.kt | 2 +- .../kotlin/cn/tursom/web/netty/ParamParser.kt | 7 +- utils/json/build.gradle | 0 .../src/main/kotlin/cn/tursom/math/FFT.kt | 33 ------ utils/performance-test/build.gradle | 3 - .../kotlin/cn/tursom/test/PerformanceTest.kt | 55 --------- .../cn/tursom/test/PerformanceTestHandler.kt | 6 - .../main/kotlin/cn/tursom/test/TestResult.kt | 20 ---- .../cn/tursom/utils/asynclock/AsyncLock.kt | 59 ---------- .../tursom/utils/asynclock/AsyncLoopLock.kt | 22 ---- .../tursom/utils/asynclock/AsyncMutexLock.kt | 47 -------- .../cn/tursom/utils/asynclock/AsyncRWLock.kt | 6 - .../utils/asynclock/AsyncReadFirstRWLock.kt | 41 ------- .../tursom/utils/asynclock/AsyncWaitList.kt | 58 ---------- .../utils/asynclock/AsyncWriteFirstRWLock.kt | 56 ---------- utils/yaml/build.gradle | 5 - .../src/main/kotlin/cn/tursom/yaml/Yaml.kt | 104 ------------------ web/build.gradle | 5 - web/netty-web/build.gradle | 7 -- 91 files changed, 166 insertions(+), 550 deletions(-) rename ts-core/{ts-ws-client/src/main/kotlin/cn/tursom => src/main/kotlin/cn/tursom/core}/ws/WebSocketFrameWrapper.kt (96%) create mode 100644 ts-core/ts-json/build.gradle.kts rename {utils/json/src/main/kotlin/cn/tursom/utils => ts-core/ts-json/src/main/kotlin/cn/tursom/core}/json/Json.kt (99%) create mode 100644 ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorker.kt create mode 100644 ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorkerImpl.kt rename ts-core/ts-ws-client/src/main/kotlin/cn/tursom/{ => core}/ws/WebSocketClient.kt (99%) rename ts-core/ts-ws-client/src/main/kotlin/cn/tursom/{ => core}/ws/WebSocketClientChannelHandler.kt (97%) rename ts-core/ts-ws-client/src/main/kotlin/cn/tursom/{ => core}/ws/WebSocketClientHandshakerAdapter.kt (98%) rename ts-core/ts-ws-client/src/main/kotlin/cn/tursom/{ => core}/ws/WebSocketHandler.kt (98%) create mode 100644 ts-web/build.gradle.kts rename {web => ts-web}/src/main/kotlin/cn/tursom/web/ExceptionContent.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/HttpContent.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/HttpHandler.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/HttpServer.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/MutableHttpContent.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/RequestHeaderAdapter.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/ResponseHeaderAdapter.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/WebSocketContent.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/WebSocketHandler.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/ConnectMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/DeleteMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/GetMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/HeadMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/Mapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/OptionsMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/PatchMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/PostMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/PutMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/mapping/TraceMapping.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/result/ContextType.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/result/Html.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/result/Json.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/result/NoReturnLog.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/result/Text.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/BlockHandler.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt (98%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/Router.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/ColonRouter.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/CurlyBracesRouter.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/FilterRouter.kt (96%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/SimpleRouter.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/colonnode/AnyColonNode.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/colonnode/ColonNode.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/colonnode/IColonNode.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/router/impl/colonnode/PlaceholderColonNode.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/CacheControl.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/Chunked.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/ContextTypeEnum.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/ContextTypeMap.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/Cookie.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/EmptyHttpContent.kt (98%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/HttpUtil.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/MethodEnum.kt (100%) rename {web => ts-web}/src/main/kotlin/cn/tursom/web/utils/SameSite.kt (100%) rename {web => ts-web}/src/test/kotlin/cn/tursom/web/router/impl/FilterRouterTest.kt (100%) rename {web/web-coroutine => ts-web/ts-web-coroutine}/build.gradle (100%) rename {web/web-coroutine => ts-web/ts-web-coroutine}/src/main/kotlin/cn/tursom/web/Utils.kt (100%) rename {web/web-coroutine => ts-web/ts-web-coroutine}/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt (100%) create mode 100644 ts-web/ts-web-netty/build.gradle.kts rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/HttpContextExchange.kt (95%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyChunkedByteBuffer.kt (97%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyChunkedInput.kt (96%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyExceptionContent.kt (98%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt (99%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyHttpDecodeType.kt (100%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyHttpHandler.kt (100%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyHttpObjectHandler.kt (100%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyHttpServer.kt (99%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyResponseHeaderAdapter.kt (100%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketContent.kt (96%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketHandler.kt (95%) rename {web/netty-web => ts-web/ts-web-netty}/src/main/kotlin/cn/tursom/web/netty/ParamParser.kt (87%) delete mode 100644 utils/json/build.gradle delete mode 100644 utils/performance-test/build.gradle delete mode 100644 utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTest.kt delete mode 100644 utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTestHandler.kt delete mode 100644 utils/performance-test/src/main/kotlin/cn/tursom/test/TestResult.kt delete mode 100644 utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLock.kt delete mode 100644 utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLoopLock.kt delete mode 100644 utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncMutexLock.kt delete mode 100644 utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncRWLock.kt delete mode 100644 utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncReadFirstRWLock.kt delete mode 100644 utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWaitList.kt delete mode 100644 utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWriteFirstRWLock.kt delete mode 100644 utils/yaml/build.gradle delete mode 100644 utils/yaml/src/main/kotlin/cn/tursom/yaml/Yaml.kt delete mode 100644 web/build.gradle delete mode 100644 web/netty-web/build.gradle diff --git a/settings.gradle.kts b/settings.gradle.kts index d4e76c5..1bf9817 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,7 +13,10 @@ include("ts-core:ts-coroutine") include("ts-core:ts-coroutine:ts-coroutine-lock") include("ts-core:ts-ws-client") include("ts-core:ts-yaml") +include("ts-core:ts-json") include("ts-socket") +include("ts-web") +include("ts-web:ts-web-netty") //include("web", "aop", "database", "utils", "utils:xml", "utils:async-http", "web:netty-web") //include("socket", "socket:socket-async") //include("AsyncSocket") diff --git a/ts-core/build.gradle.kts b/ts-core/build.gradle.kts index 97c7a17..4a36a85 100644 --- a/ts-core/build.gradle.kts +++ b/ts-core/build.gradle.kts @@ -6,6 +6,7 @@ plugins { dependencies { api(project(":")) compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.6") + compileOnly(group = "io.netty", name = "netty-all", version = "4.1.43.Final") } @kotlin.Suppress("UNCHECKED_CAST") diff --git a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketFrameWrapper.kt b/ts-core/src/main/kotlin/cn/tursom/core/ws/WebSocketFrameWrapper.kt similarity index 96% rename from ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketFrameWrapper.kt rename to ts-core/src/main/kotlin/cn/tursom/core/ws/WebSocketFrameWrapper.kt index ad4038c..3f11162 100644 --- a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketFrameWrapper.kt +++ b/ts-core/src/main/kotlin/cn/tursom/core/ws/WebSocketFrameWrapper.kt @@ -1,4 +1,4 @@ -package cn.tursom.ws +package cn.tursom.core.ws import io.netty.buffer.ByteBuf import io.netty.buffer.Unpooled diff --git a/ts-core/ts-json/build.gradle.kts b/ts-core/ts-json/build.gradle.kts new file mode 100644 index 0000000..a73cb6b --- /dev/null +++ b/ts-core/ts-json/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + kotlin("jvm") + `maven-publish` +} + +dependencies { + api(project(":")) + compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.6") + compileOnly(group = "com.fasterxml.jackson.core", name = "jackson-core", version = "2.10.1") + compileOnly(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = "2.10.1") +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + +tasks.register("install") { + finalizedBy(tasks["publishToMavenLocal"]) +} + +publishing { + publications { + create<MavenPublication>("maven") { + groupId = project.group.toString() + artifactId = project.name + version = project.version.toString() + + from(components["java"]) + try { + artifact(tasks["sourcesJar"]) + } catch (e: Exception) { + } + } + } +} diff --git a/utils/json/src/main/kotlin/cn/tursom/utils/json/Json.kt b/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/Json.kt similarity index 99% rename from utils/json/src/main/kotlin/cn/tursom/utils/json/Json.kt rename to ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/Json.kt index bde038c..6cf4be8 100644 --- a/utils/json/src/main/kotlin/cn/tursom/utils/json/Json.kt +++ b/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/Json.kt @@ -1,7 +1,6 @@ -package cn.tursom.utils.json +package cn.tursom.core.json import com.sun.org.apache.xalan.internal.lib.ExsltMath.power -import java.lang.RuntimeException object Json { class JsonFormatException(message: String? = null) : RuntimeException(message) { diff --git a/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorker.kt b/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorker.kt new file mode 100644 index 0000000..822a91e --- /dev/null +++ b/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorker.kt @@ -0,0 +1,6 @@ +package cn.tursom.core.json + +interface JsonWorker { + fun toJson(obj: Any): String? + fun <T> fromJson(json: String, clazz: Class<T>): T? +} \ No newline at end of file diff --git a/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorkerImpl.kt b/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorkerImpl.kt new file mode 100644 index 0000000..6943d7a --- /dev/null +++ b/ts-core/ts-json/src/main/kotlin/cn/tursom/core/json/JsonWorkerImpl.kt @@ -0,0 +1,29 @@ +package cn.tursom.core.json + +import com.fasterxml.jackson.databind.ObjectMapper +import com.google.gson.Gson + +class JsonWorkerImpl : JsonWorker { + companion object { + private val gson = try { + Gson() + } catch (e: Throwable) { + null + } + + private val jackson = try { + ObjectMapper() + } catch (e: Throwable) { + null + } + } + + override fun toJson(obj: Any): String? = gson?.toJson(obj) ?: jackson?.writeValueAsString(obj) + + override fun <T> fromJson(json: String, clazz: Class<T>): T? = + gson?.fromJson(json, clazz) ?: jackson?.readValue(json, clazz) + + override fun toString(): String { + return "JsonWorkerImpl(gson=$gson, jackson=$jackson)" + } +} \ No newline at end of file diff --git a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClient.kt b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt similarity index 99% rename from ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClient.kt rename to ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt index bd79e5c..c196145 100644 --- a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClient.kt +++ b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClient.kt @@ -1,4 +1,4 @@ -package cn.tursom.ws +package cn.tursom.core.ws import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.buffer.impl.NettyByteBuffer diff --git a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClientChannelHandler.kt b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClientChannelHandler.kt similarity index 97% rename from ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClientChannelHandler.kt rename to ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClientChannelHandler.kt index 243471f..1bea2e3 100644 --- a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClientChannelHandler.kt +++ b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClientChannelHandler.kt @@ -1,4 +1,4 @@ -package cn.tursom.ws +package cn.tursom.core.ws import io.netty.channel.ChannelHandlerContext import io.netty.channel.SimpleChannelInboundHandler diff --git a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClientHandshakerAdapter.kt b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClientHandshakerAdapter.kt similarity index 98% rename from ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClientHandshakerAdapter.kt rename to ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClientHandshakerAdapter.kt index acc560a..c7d28f9 100644 --- a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketClientHandshakerAdapter.kt +++ b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketClientHandshakerAdapter.kt @@ -1,4 +1,4 @@ -package cn.tursom.ws +package cn.tursom.core.ws import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelPromise diff --git a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketHandler.kt b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketHandler.kt similarity index 98% rename from ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketHandler.kt rename to ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketHandler.kt index b4c13cb..4d6067d 100644 --- a/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/ws/WebSocketHandler.kt +++ b/ts-core/ts-ws-client/src/main/kotlin/cn/tursom/core/ws/WebSocketHandler.kt @@ -1,4 +1,4 @@ -package cn.tursom.ws +package cn.tursom.core.ws import cn.tursom.core.buffer.ByteBuffer import cn.tursom.core.buffer.impl.NettyByteBuffer diff --git a/ts-web/build.gradle.kts b/ts-web/build.gradle.kts new file mode 100644 index 0000000..b490268 --- /dev/null +++ b/ts-web/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + kotlin("jvm") + `maven-publish` +} + +dependencies { + api(project(":ts-core")) + api(project(":ts-core:ts-buffer")) + api(project(":ts-core:ts-datastruct")) + compileOnly(project(":ts-core:ts-json")) + api(group = "org.slf4j", name = "slf4j-api", version = "1.7.29") +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + +tasks.register("install") { + finalizedBy(tasks["publishToMavenLocal"]) +} + +publishing { + publications { + create<MavenPublication>("maven") { + groupId = project.group.toString() + artifactId = project.name + version = project.version.toString() + + from(components["java"]) + try { + artifact(tasks["sourcesJar"]) + } catch (e: Exception) { + } + } + } +} diff --git a/web/src/main/kotlin/cn/tursom/web/ExceptionContent.kt b/ts-web/src/main/kotlin/cn/tursom/web/ExceptionContent.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/ExceptionContent.kt rename to ts-web/src/main/kotlin/cn/tursom/web/ExceptionContent.kt diff --git a/web/src/main/kotlin/cn/tursom/web/HttpContent.kt b/ts-web/src/main/kotlin/cn/tursom/web/HttpContent.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/HttpContent.kt rename to ts-web/src/main/kotlin/cn/tursom/web/HttpContent.kt diff --git a/web/src/main/kotlin/cn/tursom/web/HttpHandler.kt b/ts-web/src/main/kotlin/cn/tursom/web/HttpHandler.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/HttpHandler.kt rename to ts-web/src/main/kotlin/cn/tursom/web/HttpHandler.kt diff --git a/web/src/main/kotlin/cn/tursom/web/HttpServer.kt b/ts-web/src/main/kotlin/cn/tursom/web/HttpServer.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/HttpServer.kt rename to ts-web/src/main/kotlin/cn/tursom/web/HttpServer.kt diff --git a/web/src/main/kotlin/cn/tursom/web/MutableHttpContent.kt b/ts-web/src/main/kotlin/cn/tursom/web/MutableHttpContent.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/MutableHttpContent.kt rename to ts-web/src/main/kotlin/cn/tursom/web/MutableHttpContent.kt diff --git a/web/src/main/kotlin/cn/tursom/web/RequestHeaderAdapter.kt b/ts-web/src/main/kotlin/cn/tursom/web/RequestHeaderAdapter.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/RequestHeaderAdapter.kt rename to ts-web/src/main/kotlin/cn/tursom/web/RequestHeaderAdapter.kt diff --git a/web/src/main/kotlin/cn/tursom/web/ResponseHeaderAdapter.kt b/ts-web/src/main/kotlin/cn/tursom/web/ResponseHeaderAdapter.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/ResponseHeaderAdapter.kt rename to ts-web/src/main/kotlin/cn/tursom/web/ResponseHeaderAdapter.kt diff --git a/web/src/main/kotlin/cn/tursom/web/WebSocketContent.kt b/ts-web/src/main/kotlin/cn/tursom/web/WebSocketContent.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/WebSocketContent.kt rename to ts-web/src/main/kotlin/cn/tursom/web/WebSocketContent.kt diff --git a/web/src/main/kotlin/cn/tursom/web/WebSocketHandler.kt b/ts-web/src/main/kotlin/cn/tursom/web/WebSocketHandler.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/WebSocketHandler.kt rename to ts-web/src/main/kotlin/cn/tursom/web/WebSocketHandler.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/ConnectMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/ConnectMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/ConnectMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/ConnectMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/DeleteMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/DeleteMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/DeleteMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/DeleteMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/GetMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/GetMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/GetMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/GetMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/HeadMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/HeadMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/HeadMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/HeadMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/Mapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/Mapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/Mapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/Mapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/OptionsMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/OptionsMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/OptionsMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/OptionsMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/PatchMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/PatchMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/PatchMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/PatchMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/PostMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/PostMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/PostMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/PostMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/PutMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/PutMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/PutMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/PutMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/mapping/TraceMapping.kt b/ts-web/src/main/kotlin/cn/tursom/web/mapping/TraceMapping.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/mapping/TraceMapping.kt rename to ts-web/src/main/kotlin/cn/tursom/web/mapping/TraceMapping.kt diff --git a/web/src/main/kotlin/cn/tursom/web/result/ContextType.kt b/ts-web/src/main/kotlin/cn/tursom/web/result/ContextType.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/result/ContextType.kt rename to ts-web/src/main/kotlin/cn/tursom/web/result/ContextType.kt diff --git a/web/src/main/kotlin/cn/tursom/web/result/Html.kt b/ts-web/src/main/kotlin/cn/tursom/web/result/Html.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/result/Html.kt rename to ts-web/src/main/kotlin/cn/tursom/web/result/Html.kt diff --git a/web/src/main/kotlin/cn/tursom/web/result/Json.kt b/ts-web/src/main/kotlin/cn/tursom/web/result/Json.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/result/Json.kt rename to ts-web/src/main/kotlin/cn/tursom/web/result/Json.kt diff --git a/web/src/main/kotlin/cn/tursom/web/result/NoReturnLog.kt b/ts-web/src/main/kotlin/cn/tursom/web/result/NoReturnLog.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/result/NoReturnLog.kt rename to ts-web/src/main/kotlin/cn/tursom/web/result/NoReturnLog.kt diff --git a/web/src/main/kotlin/cn/tursom/web/result/Text.kt b/ts-web/src/main/kotlin/cn/tursom/web/result/Text.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/result/Text.kt rename to ts-web/src/main/kotlin/cn/tursom/web/result/Text.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/BlockHandler.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/BlockHandler.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/BlockHandler.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/BlockHandler.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt similarity index 98% rename from web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt index 3760df1..8423aba 100644 --- a/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt +++ b/ts-web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt @@ -1,9 +1,9 @@ package cn.tursom.web.router import cn.tursom.core.buffer.ByteBuffer +import cn.tursom.core.json.JsonWorkerImpl import cn.tursom.core.lambda import cn.tursom.core.regex.regex -import cn.tursom.json.JsonWorkerImpl import cn.tursom.web.ExceptionContent import cn.tursom.web.HttpContent import cn.tursom.web.HttpHandler @@ -14,7 +14,10 @@ import cn.tursom.web.router.impl.SimpleRouter import cn.tursom.web.utils.Chunked import cn.tursom.web.utils.ContextTypeEnum import org.slf4j.LoggerFactory -import java.io.* +import java.io.ByteArrayOutputStream +import java.io.File +import java.io.PrintStream +import java.io.RandomAccessFile import java.lang.reflect.Method import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.ThreadFactory diff --git a/web/src/main/kotlin/cn/tursom/web/router/Router.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/Router.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/Router.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/Router.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/ColonRouter.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/ColonRouter.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/impl/ColonRouter.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/ColonRouter.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/CurlyBracesRouter.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/CurlyBracesRouter.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/impl/CurlyBracesRouter.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/CurlyBracesRouter.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/FilterRouter.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/FilterRouter.kt similarity index 96% rename from web/src/main/kotlin/cn/tursom/web/router/impl/FilterRouter.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/FilterRouter.kt index 3efb48b..81a4654 100644 --- a/web/src/main/kotlin/cn/tursom/web/router/impl/FilterRouter.kt +++ b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/FilterRouter.kt @@ -3,7 +3,6 @@ package cn.tursom.web.router.impl import cn.tursom.web.router.Router import java.util.* import java.util.concurrent.locks.ReentrantReadWriteLock -import kotlin.collections.ArrayList import kotlin.concurrent.read import kotlin.concurrent.write @@ -14,7 +13,8 @@ class FilterRouter<T>( val slashOnceMore = Regex("/+") } - private val flower = Regex("\\${matchPair.first}[^\\${matchPair.first}\\${matchPair.second}]*\\${matchPair.second}") + private val flower = + Regex("\\\\${matchPair.first}[^\\\\${matchPair.first}\\\\${matchPair.second}]*\\\\${matchPair.second}") private val lock = ReentrantReadWriteLock() private val routeList = ArrayList<RouteContext<T>>() diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/SimpleRouter.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/SimpleRouter.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/impl/SimpleRouter.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/SimpleRouter.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/AnyColonNode.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/AnyColonNode.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/AnyColonNode.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/AnyColonNode.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/ColonNode.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/ColonNode.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/ColonNode.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/ColonNode.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/IColonNode.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/IColonNode.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/IColonNode.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/IColonNode.kt diff --git a/web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/PlaceholderColonNode.kt b/ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/PlaceholderColonNode.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/PlaceholderColonNode.kt rename to ts-web/src/main/kotlin/cn/tursom/web/router/impl/colonnode/PlaceholderColonNode.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/CacheControl.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/CacheControl.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/CacheControl.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/CacheControl.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/Chunked.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/Chunked.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/Chunked.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/Chunked.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/ContextTypeEnum.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/ContextTypeEnum.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/ContextTypeEnum.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/ContextTypeEnum.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/ContextTypeMap.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/ContextTypeMap.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/ContextTypeMap.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/ContextTypeMap.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/Cookie.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/Cookie.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/Cookie.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/Cookie.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/EmptyHttpContent.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/EmptyHttpContent.kt similarity index 98% rename from web/src/main/kotlin/cn/tursom/web/utils/EmptyHttpContent.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/EmptyHttpContent.kt index 326f5ef..fce08e0 100644 --- a/web/src/main/kotlin/cn/tursom/web/utils/EmptyHttpContent.kt +++ b/ts-web/src/main/kotlin/cn/tursom/web/utils/EmptyHttpContent.kt @@ -2,7 +2,6 @@ package cn.tursom.web.utils import cn.tursom.core.buffer.ByteBuffer import cn.tursom.web.HttpContent -import java.io.ByteArrayOutputStream import java.io.File import java.io.RandomAccessFile import java.net.InetSocketAddress diff --git a/web/src/main/kotlin/cn/tursom/web/utils/HttpUtil.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/HttpUtil.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/HttpUtil.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/HttpUtil.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/MethodEnum.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/MethodEnum.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/MethodEnum.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/MethodEnum.kt diff --git a/web/src/main/kotlin/cn/tursom/web/utils/SameSite.kt b/ts-web/src/main/kotlin/cn/tursom/web/utils/SameSite.kt similarity index 100% rename from web/src/main/kotlin/cn/tursom/web/utils/SameSite.kt rename to ts-web/src/main/kotlin/cn/tursom/web/utils/SameSite.kt diff --git a/web/src/test/kotlin/cn/tursom/web/router/impl/FilterRouterTest.kt b/ts-web/src/test/kotlin/cn/tursom/web/router/impl/FilterRouterTest.kt similarity index 100% rename from web/src/test/kotlin/cn/tursom/web/router/impl/FilterRouterTest.kt rename to ts-web/src/test/kotlin/cn/tursom/web/router/impl/FilterRouterTest.kt diff --git a/web/web-coroutine/build.gradle b/ts-web/ts-web-coroutine/build.gradle similarity index 100% rename from web/web-coroutine/build.gradle rename to ts-web/ts-web-coroutine/build.gradle diff --git a/web/web-coroutine/src/main/kotlin/cn/tursom/web/Utils.kt b/ts-web/ts-web-coroutine/src/main/kotlin/cn/tursom/web/Utils.kt similarity index 100% rename from web/web-coroutine/src/main/kotlin/cn/tursom/web/Utils.kt rename to ts-web/ts-web-coroutine/src/main/kotlin/cn/tursom/web/Utils.kt diff --git a/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt b/ts-web/ts-web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt similarity index 100% rename from web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt rename to ts-web/ts-web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt diff --git a/ts-web/ts-web-netty/build.gradle.kts b/ts-web/ts-web-netty/build.gradle.kts new file mode 100644 index 0000000..9e3809c --- /dev/null +++ b/ts-web/ts-web-netty/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + kotlin("jvm") + `maven-publish` +} + +dependencies { + api(project(":ts-core")) + api(project(":ts-core:ts-log")) + api(project(":ts-web")) + api(group = "io.netty", name = "netty-all", version = "4.1.43.Final") +} + +@kotlin.Suppress("UNCHECKED_CAST") +(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks) + +tasks.register("install") { + finalizedBy(tasks["publishToMavenLocal"]) +} + +publishing { + publications { + create<MavenPublication>("maven") { + groupId = project.group.toString() + artifactId = project.name + version = project.version.toString() + + from(components["java"]) + try { + artifact(tasks["sourcesJar"]) + } catch (e: Exception) { + } + } + } +} diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/HttpContextExchange.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/HttpContextExchange.kt similarity index 95% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/HttpContextExchange.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/HttpContextExchange.kt index efc5479..4e67171 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/HttpContextExchange.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/HttpContextExchange.kt @@ -5,7 +5,6 @@ package cn.tursom.web.netty import io.netty.handler.codec.DateFormatter import io.netty.handler.codec.http.cookie.ServerCookieDecoder import java.util.* -import kotlin.collections.HashMap fun parseHttpDate(date: CharSequence, start: Int = 0, end: Int = date.length): Date = DateFormatter.parseHttpDate(date, start, end) diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyChunkedByteBuffer.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyChunkedByteBuffer.kt similarity index 97% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyChunkedByteBuffer.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyChunkedByteBuffer.kt index 28f6302..a9e457c 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyChunkedByteBuffer.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyChunkedByteBuffer.kt @@ -1,8 +1,8 @@ package cn.tursom.web.netty import cn.tursom.core.buffer.ByteBuffer +import cn.tursom.core.buffer.impl.NettyByteBuffer import cn.tursom.log.traceEnabled -import cn.tursom.utils.bytebuffer.NettyByteBuffer import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBufAllocator import io.netty.buffer.Unpooled diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyChunkedInput.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyChunkedInput.kt similarity index 96% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyChunkedInput.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyChunkedInput.kt index 5bc5e44..8eca93f 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyChunkedInput.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyChunkedInput.kt @@ -1,7 +1,7 @@ package cn.tursom.web.netty +import cn.tursom.core.buffer.impl.NettyByteBuffer import cn.tursom.log.traceEnabled -import cn.tursom.utils.bytebuffer.NettyByteBuffer import cn.tursom.web.utils.Chunked import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBufAllocator diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyExceptionContent.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyExceptionContent.kt similarity index 98% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyExceptionContent.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyExceptionContent.kt index 53a42ab..7745b8b 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyExceptionContent.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyExceptionContent.kt @@ -1,8 +1,8 @@ package cn.tursom.web.netty import cn.tursom.core.buffer.ByteBuffer +import cn.tursom.core.buffer.impl.NettyByteBuffer import cn.tursom.log.traceEnabled -import cn.tursom.utils.bytebuffer.NettyByteBuffer import cn.tursom.web.ExceptionContent import io.netty.buffer.ByteBuf import io.netty.buffer.CompositeByteBuf diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt similarity index 99% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt index d7819bc..56ee1d3 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt @@ -1,8 +1,8 @@ package cn.tursom.web.netty import cn.tursom.core.buffer.ByteBuffer +import cn.tursom.core.buffer.impl.NettyByteBuffer import cn.tursom.log.traceEnabled -import cn.tursom.utils.bytebuffer.NettyByteBuffer import cn.tursom.web.MutableHttpContent import cn.tursom.web.utils.Chunked import io.netty.buffer.ByteBuf diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpDecodeType.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpDecodeType.kt similarity index 100% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpDecodeType.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpDecodeType.kt diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpHandler.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpHandler.kt similarity index 100% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpHandler.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpHandler.kt diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpObjectHandler.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpObjectHandler.kt similarity index 100% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpObjectHandler.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpObjectHandler.kt diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpServer.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpServer.kt similarity index 99% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpServer.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpServer.kt index c6535f3..46a7aa6 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpServer.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyHttpServer.kt @@ -1,6 +1,6 @@ package cn.tursom.web.netty -import cn.tursom.utils.WebSocketFrameWrapper +import cn.tursom.core.ws.WebSocketFrameWrapper import cn.tursom.web.HttpHandler import cn.tursom.web.HttpServer import cn.tursom.web.WebSocketHandler diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyResponseHeaderAdapter.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyResponseHeaderAdapter.kt similarity index 100% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyResponseHeaderAdapter.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyResponseHeaderAdapter.kt diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketContent.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketContent.kt similarity index 96% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketContent.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketContent.kt index f31de16..d39ad0d 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketContent.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketContent.kt @@ -1,9 +1,9 @@ package cn.tursom.web.netty import cn.tursom.core.buffer.ByteBuffer +import cn.tursom.core.buffer.impl.NettyByteBuffer import cn.tursom.core.buffer.read import cn.tursom.log.traceEnabled -import cn.tursom.utils.bytebuffer.NettyByteBuffer import cn.tursom.web.WebSocketContent import io.netty.buffer.Unpooled import io.netty.channel.Channel diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketHandler.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketHandler.kt similarity index 95% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketHandler.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketHandler.kt index 11579a4..176a44f 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketHandler.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/NettyWebSocketHandler.kt @@ -1,6 +1,6 @@ package cn.tursom.web.netty -import cn.tursom.utils.bytebuffer.NettyByteBuffer +import cn.tursom.core.buffer.impl.NettyByteBuffer import cn.tursom.web.WebSocketHandler import io.netty.channel.Channel import io.netty.channel.ChannelHandlerContext diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/ParamParser.kt b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/ParamParser.kt similarity index 87% rename from web/netty-web/src/main/kotlin/cn/tursom/web/netty/ParamParser.kt rename to ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/ParamParser.kt index 6deafaa..db61631 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/ParamParser.kt +++ b/ts-web/ts-web-netty/src/main/kotlin/cn/tursom/web/netty/ParamParser.kt @@ -1,10 +1,11 @@ package cn.tursom.web.netty -import io.netty.handler.codec.http.* +import io.netty.handler.codec.http.HttpContent +import io.netty.handler.codec.http.HttpMethod +import io.netty.handler.codec.http.HttpRequest +import io.netty.handler.codec.http.QueryStringDecoder import io.netty.handler.codec.http.multipart.Attribute import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder -import java.util.* -import kotlin.collections.ArrayList import kotlin.collections.set /** diff --git a/utils/json/build.gradle b/utils/json/build.gradle deleted file mode 100644 index e69de29..0000000 diff --git a/utils/math/src/main/kotlin/cn/tursom/math/FFT.kt b/utils/math/src/main/kotlin/cn/tursom/math/FFT.kt index 005660d..e69de29 100644 --- a/utils/math/src/main/kotlin/cn/tursom/math/FFT.kt +++ b/utils/math/src/main/kotlin/cn/tursom/math/FFT.kt @@ -1,33 +0,0 @@ -package cn.tursom.math - -import kotlin.math.PI -import kotlin.math.cos -import kotlin.math.sin - -fun fft1(a: Array<Complex>): Array<Complex> { - if (a.size == 1) return a - val a0 = Array(a.size shr 1) { - a[it shl 1] - } - val a1 = Array(a.size shr 1) { - a[(it shl 1) + 1] - } - fft1(a0) - fft1(a1) - val wn = Complex(cos(2 * PI / a.size), sin(2 * PI / a.size)) - val w = Complex(1.0, 0.0) - repeat(a.size shr 1) { k -> - a[k] = a0[k] + w * a1[k] - a[k + (a.size shr 1)] = a0[k] - w * a1[k] - w.plusAssign(wn) - } - return a -} - -fun main() { - val source = Array(8) { - Complex(sin(it.toDouble())) - } - println(source.asList()) - println(fft1(source).asList()) -} \ No newline at end of file diff --git a/utils/performance-test/build.gradle b/utils/performance-test/build.gradle deleted file mode 100644 index 891d697..0000000 --- a/utils/performance-test/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - compile project(":") -} diff --git a/utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTest.kt b/utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTest.kt deleted file mode 100644 index 62fda7f..0000000 --- a/utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package cn.tursom.test - -import java.util.concurrent.CountDownLatch -import java.util.concurrent.atomic.AtomicInteger -import kotlin.concurrent.thread - -class PerformanceTest( - val countPerThread: Int, - val threadCount: Int = 1, - val handler: PerformanceTestHandler -) { - val totalCount = countPerThread * threadCount - - constructor( - countPerThread: Int, - threadCount: Int = 1, - handler: () -> Unit - ) : this(countPerThread, threadCount, object : PerformanceTestHandler, () -> Unit by handler {}) - - fun run(): TestResult { - val schedule = AtomicInteger(0) - val wait = CountDownLatch(threadCount) - val runLock = CountDownLatch(1) - var line95 = 0L - var line98 = 0L - var line99 = 0L - repeat(threadCount) { - thread { - runLock.await() - try { - repeat(countPerThread) { - val loop = schedule.getAndIncrement() - if (loop * 100 % totalCount == 0) { - val line = loop * 100 / totalCount - when (line) { - 95 -> line95 = System.currentTimeMillis() - 98 -> line98 = System.currentTimeMillis() - 99 -> line99 = System.currentTimeMillis() - } - handler.logSchedule(line) - } - handler() - } - } finally { - wait.countDown() - } - } - } - val start = System.currentTimeMillis() - runLock.countDown() - wait.await() - val end = System.currentTimeMillis() - return TestResult(start, end, line95, line98, line99) - } -} diff --git a/utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTestHandler.kt b/utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTestHandler.kt deleted file mode 100644 index 60c6a15..0000000 --- a/utils/performance-test/src/main/kotlin/cn/tursom/test/PerformanceTestHandler.kt +++ /dev/null @@ -1,6 +0,0 @@ -package cn.tursom.test - -interface PerformanceTestHandler : () -> Unit { - fun logSchedule(percentage: Int) { - } -} \ No newline at end of file diff --git a/utils/performance-test/src/main/kotlin/cn/tursom/test/TestResult.kt b/utils/performance-test/src/main/kotlin/cn/tursom/test/TestResult.kt deleted file mode 100644 index 436a927..0000000 --- a/utils/performance-test/src/main/kotlin/cn/tursom/test/TestResult.kt +++ /dev/null @@ -1,20 +0,0 @@ -package cn.tursom.test - -import java.util.concurrent.TimeUnit - -data class TestResult( - val startTime: Long, - val endTime: Long, - val line95: Long, - val line98: Long, - val line99: Long, - val usingTime: Long = endTime - startTime, - val usingTimeS: Long = TimeUnit.SECONDS.convert(usingTime, TimeUnit.MILLISECONDS), - val t95: Long = line95 - startTime, - val t98: Long = line98 - startTime, - val t99: Long = line99 - startTime, - val t95s: Long = TimeUnit.SECONDS.convert(t95, TimeUnit.MILLISECONDS), - val t98s: Long = TimeUnit.SECONDS.convert(t98, TimeUnit.MILLISECONDS), - val t99s: Long = TimeUnit.SECONDS.convert(t99, TimeUnit.MILLISECONDS) -) { -} \ No newline at end of file diff --git a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLock.kt b/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLock.kt deleted file mode 100644 index 4651b39..0000000 --- a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLock.kt +++ /dev/null @@ -1,59 +0,0 @@ -package cn.tursom.utils.asynclock - -import kotlinx.coroutines.delay -import java.util.concurrent.atomic.AtomicBoolean -import java.util.concurrent.atomic.AtomicInteger - -interface AsyncLock { - suspend fun sync(block: suspend () -> Unit) - suspend fun isLock(): Boolean - suspend operator fun <T> invoke(block: suspend () -> T): T - - suspend fun AtomicBoolean.lock(delayTime: Long) { - // 如果得不到锁,先自旋20次 - var maxLoopTime = 20 - while (maxLoopTime-- > 0) { - if (compareAndSet(false, true)) return - } - while (!compareAndSet(false, true)) { - delay(delayTime) - } - } - - suspend fun AtomicBoolean.release() { - set(false) - } - - suspend fun AtomicBoolean.wait(delayTime: Long) { - // 如果得不到锁,先自旋20次 - var maxLoopTime = 20 - while (maxLoopTime-- > 0) { - if (!get()) return - } - while (get()) { - delay(delayTime) - } - } - - suspend fun AsyncLock.wait(delayTime: Long) { - // 如果得不到锁,先自旋20次 - var maxLoopTime = 20 - while (maxLoopTime-- > 0) { - if (!isLock()) return - } - while (isLock()) { - delay(delayTime) - } - } - - suspend fun AtomicInteger.wait(delayTime: Long) { - // 如果得不到锁,先自旋20次 - var maxLoopTime = 20 - while (maxLoopTime-- > 0) { - if (get() <= 0) return - } - while (get() > 0) { - delay(delayTime) - } - } -} \ No newline at end of file diff --git a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLoopLock.kt b/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLoopLock.kt deleted file mode 100644 index 97d164b..0000000 --- a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncLoopLock.kt +++ /dev/null @@ -1,22 +0,0 @@ -package cn.tursom.utils.asynclock - -import java.util.concurrent.atomic.AtomicBoolean - -class AsyncLoopLock : AsyncLock { - private val lock = AtomicBoolean(false) - - override suspend fun sync(block: suspend () -> Unit) { - invoke(block) - } - - override suspend fun isLock(): Boolean = lock.get() - - override suspend fun <T> invoke(block: suspend () -> T): T { - while (!lock.compareAndSet(false, true)); - try { - return block() - } finally { - lock.set(false) - } - } -} \ No newline at end of file diff --git a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncMutexLock.kt b/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncMutexLock.kt deleted file mode 100644 index 117cffe..0000000 --- a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncMutexLock.kt +++ /dev/null @@ -1,47 +0,0 @@ -package cn.tursom.utils.asynclock - -import java.util.concurrent.atomic.AtomicBoolean - -class AsyncMutexLock : AsyncLock { - private val lock = AtomicBoolean(false) - private val waitList = AsyncWaitList() - - suspend fun wait() { - var loopTime = 20 - while (loopTime-- > 0) if (!lock.get()) return - waitList.wait() - waitList.resume() - } - - override suspend fun sync(block: suspend () -> Unit) { - invoke(block) - } - - override suspend fun isLock(): Boolean { - return lock.get() - } - - override suspend operator fun <T> invoke(block: suspend () -> T): T { - lock.lock() - try { - return block() - } finally { - lock.release() - } - } - - private suspend fun AtomicBoolean.lock() { - var loopTime = 20 - while (loopTime-- > 0) if (compareAndSet(false, true)) return - waitList.wait() - } - - override suspend fun AtomicBoolean.release() { - if (waitList.notEmpty) { - waitList.resume() - } else { - set(false) - } - } -} - diff --git a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncRWLock.kt b/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncRWLock.kt deleted file mode 100644 index 0ee4541..0000000 --- a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncRWLock.kt +++ /dev/null @@ -1,6 +0,0 @@ -package cn.tursom.utils.asynclock - -interface AsyncRWLock : AsyncLock { - suspend fun <T> doRead(block: suspend () -> T): T - suspend fun <T> doWrite(block: suspend () -> T): T -} \ No newline at end of file diff --git a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncReadFirstRWLock.kt b/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncReadFirstRWLock.kt deleted file mode 100644 index e437b2f..0000000 --- a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncReadFirstRWLock.kt +++ /dev/null @@ -1,41 +0,0 @@ -package cn.tursom.utils.asynclock - -import java.util.concurrent.atomic.AtomicInteger - -/** - * 读优化锁 - */ -@Suppress("MemberVisibilityCanBePrivate") -class AsyncReadFirstRWLock() : AsyncRWLock { - private val lock = AsyncMutexLock() - private val readNumber = AtomicInteger(0) - private val writeList = AsyncWaitList() - - override suspend fun <T> doRead(block: suspend () -> T): T { - readNumber.incrementAndGet() - lock.wait() - try { - return block() - } finally { - readNumber.decrementAndGet() - if (readNumber.get() == 0) writeList.resume() - } - } - - override suspend fun <T> doWrite(block: suspend () -> T): T { - return invoke(block) - } - - override suspend fun sync(block: suspend () -> Unit) { - invoke(block) - } - - override suspend fun <T> invoke(block: suspend () -> T): T { - while (readNumber.get() != 0) writeList.wait() - return lock { block() } - } - - override suspend fun isLock(): Boolean { - return lock.isLock() - } -} diff --git a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWaitList.kt b/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWaitList.kt deleted file mode 100644 index 6d8b976..0000000 --- a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWaitList.kt +++ /dev/null @@ -1,58 +0,0 @@ -package cn.tursom.utils.asynclock - -import cn.tursom.core.Unsafe.unsafe -import java.io.Closeable -import kotlin.coroutines.Continuation -import kotlin.coroutines.resume -import kotlin.coroutines.suspendCoroutine - -@Suppress("MemberVisibilityCanBePrivate") -class AsyncWaitList : Closeable { - val empty: Boolean get() = lockList == null - val notEmpty: Boolean get() = lockList != null - - suspend fun wait() = suspendCoroutine<Int> { cont -> - var list = lockList - while (!unsafe.compareAndSwapObject(this, listOffset, list, LockNode(cont, list))) { - list = lockList - } - } - - - fun resume(): Boolean { - var list = lockList ?: return false - while (!unsafe.compareAndSwapObject(this, listOffset, list, list.next)) { - list = lockList ?: return false - } - list.cont.resume(0) - return true - } - - fun resumeAll(): Boolean { - var list: LockNode? = lockList ?: return false - while (!unsafe.compareAndSwapObject(this, listOffset, list, null)) { - list = lockList ?: return false - } - while (list != null) { - list.cont.resume(0) - list = list.next - } - return true - } - - override fun close() { - resumeAll() - } - - @Volatile - private var lockList: LockNode? = null - //private val listLock = AsyncLoopLock() - - private data class LockNode(val cont: Continuation<Int>, val next: LockNode? = null) - - companion object { - val listOffset = run { - unsafe.objectFieldOffset(AsyncWaitList::class.java.getDeclaredField("lockList")) - } - } -} \ No newline at end of file diff --git a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWriteFirstRWLock.kt b/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWriteFirstRWLock.kt deleted file mode 100644 index b486b76..0000000 --- a/utils/src/main/kotlin/cn/tursom/utils/asynclock/AsyncWriteFirstRWLock.kt +++ /dev/null @@ -1,56 +0,0 @@ -package cn.tursom.utils.asynclock - -import java.util.concurrent.atomic.AtomicBoolean -import java.util.concurrent.atomic.AtomicInteger - -@Suppress("MemberVisibilityCanBePrivate") -class AsyncWriteFirstRWLock(val delayTime: Long = 10) : AsyncRWLock { - - private val lock = AtomicBoolean(false) - private val readNumber = AtomicInteger(0) - private val writeNumber = AtomicInteger(0) - - override suspend fun <T> doWrite(block: suspend () -> T): T { - return invoke(block) - } - - override suspend fun <T> doRead(block: suspend () -> T): T { - // 先等待通知锁关闭 - writeNumber.wait(delayTime) - - // 添加读计数 - readNumber.incrementAndGet() - - try { - return block() - } finally { - // 减少读计数 - readNumber.decrementAndGet() - } - } - - override suspend fun sync(block: suspend () -> Unit) { - invoke(block) - } - - override suspend fun <T> invoke(block: suspend () -> T): T { - writeNumber.incrementAndGet() - - repeat(20) {} - - readNumber.wait(delayTime) - - lock.lock(delayTime) - - try { - return block() - } finally { - lock.release() - writeNumber.decrementAndGet() - } - } - - override suspend fun isLock(): Boolean { - return lock.get() - } -} \ No newline at end of file diff --git a/utils/yaml/build.gradle b/utils/yaml/build.gradle deleted file mode 100644 index 58a0ebd..0000000 --- a/utils/yaml/build.gradle +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - compile project(":") - // 解析YAML - implementation group: 'org.yaml', name: 'snakeyaml', version: '1.25' -} diff --git a/utils/yaml/src/main/kotlin/cn/tursom/yaml/Yaml.kt b/utils/yaml/src/main/kotlin/cn/tursom/yaml/Yaml.kt deleted file mode 100644 index e6dc5fc..0000000 --- a/utils/yaml/src/main/kotlin/cn/tursom/yaml/Yaml.kt +++ /dev/null @@ -1,104 +0,0 @@ -package cn.tursom.yaml - -import cn.tursom.core.Parser -import cn.tursom.core.ThreadLocalSimpleDateFormat -import cn.tursom.core.getClazz -import org.yaml.snakeyaml.Yaml -import java.lang.reflect.Modifier -import java.util.* - - -@Suppress("MemberVisibilityCanBePrivate", "unused") -object Yaml { - private val simpleDateFormat = ThreadLocalSimpleDateFormat() - private val yaml = Yaml() - - fun toYaml(obj: Any): String { - val stringBuilder = StringBuilder() - toYaml(obj, stringBuilder, "") - return stringBuilder.toString() - } - - private fun toYaml(obj: Any, stringBuilder: StringBuilder, indentation: String, inCollection: Boolean = false) { - when (obj) { - is Byte -> stringBuilder.append(obj) - is Char -> stringBuilder.append(obj) - is Short -> stringBuilder.append(obj) - is Int -> stringBuilder.append(obj) - is Long -> stringBuilder.append(obj) - is Float -> stringBuilder.append(obj) - is Double -> stringBuilder.append(obj) - is Date -> stringBuilder.append(simpleDateFormat.get().format(obj)) - is String -> when { - obj.contains('\n') -> { - stringBuilder.append("|${if (obj.endsWith('\n')) '+' else '-'}") - obj.split('\n').forEach { - stringBuilder.append("$indentation$it") - } - } - obj.startsWith('|') -> stringBuilder.append("\"$obj\"") - else -> { - stringBuilder.append(obj) - } - } - is Map<*, *> -> { - var first = true - obj.forEach { (any, u) -> - if (inCollection && first) { - stringBuilder.append("${any ?: return@forEach}: ") - first = false - } else { - stringBuilder.append("$indentation${any ?: return@forEach}: ") - } - toYaml(u ?: return@forEach, stringBuilder, "$indentation ") - if (!stringBuilder.endsWith('\n')) { - stringBuilder.append("\n") - } - } - } - is Collection<*> -> if (obj.isEmpty()) { - stringBuilder.append("[]") - } else { - var appended = 0 - obj.forEach { - it ?: return@forEach - stringBuilder.append("${if (appended == 0) "\n" else ""}$indentation- ") - appended++ - toYaml(it, stringBuilder, "$indentation ", true) - if (!stringBuilder.endsWith('\n')) { - stringBuilder.append("\n") - } - } - } - else -> { - var first = true - fun getIndentation() = if (inCollection && first) { - first = false - "" - } else { - indentation - } - obj.javaClass.declaredFields.forEach { - if ((it.modifiers and (Modifier.STATIC or Modifier.TRANSIENT)) != 0) return@forEach - it.isAccessible = true - val value = it.get(obj) - stringBuilder.append("${getIndentation()}${it.name}: ") - toYaml(value, stringBuilder, "${getIndentation()} ") - if (!stringBuilder.endsWith('\n')) { - stringBuilder.append("\n") - } - } - } - } - - } - - inline fun <reified T> parse(yaml: Any) = Parser.parse(yaml, T::class.java) - inline fun <reified T> parse(yaml: String) = parse(yaml, T::class.java) - inline fun <reified T> parseResource(path: String) = parseResource(path, T::class.java) - inline fun <reified T> parseResource(classLoader: ClassLoader, path: String) = parseResource(classLoader, path, T::class.java) - - fun <T> parseResource(path: String, clazz: Class<T>) = parseResource(this.javaClass.classLoader, path, clazz) - fun <T> parseResource(classLoader: ClassLoader, path: String, clazz: Class<T>) = Parser.parse(yaml.load(classLoader.getResourceAsStream(path)), clazz) - fun <T> parse(yaml: String, clazz: Class<T>) = Parser.parse(this.yaml.load(yaml), clazz) -} \ No newline at end of file diff --git a/web/build.gradle b/web/build.gradle deleted file mode 100644 index d823087..0000000 --- a/web/build.gradle +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - compile project(":") - api project(":json") - api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.29' -} \ No newline at end of file diff --git a/web/netty-web/build.gradle b/web/netty-web/build.gradle deleted file mode 100644 index d86afda..0000000 --- a/web/netty-web/build.gradle +++ /dev/null @@ -1,7 +0,0 @@ -dependencies { - //compile project(":") - compile project(":web") - implementation project(":utils") - api project(":log") - compile group: "io.netty", name: "netty-all", version: "4.1.43.Final" -}