diff --git a/.gitignore b/.gitignore index a23b0ea7..86147440 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ target/ !**/dist/ ### Agent ### -agent-dist/ +hippo4j-agent/ **/dependency-reduced-pom.xml ### STS ### @@ -49,5 +49,5 @@ docs/.docusaurus ### Docker ### -docker/threadpool/conf -docker/threadpool/target \ No newline at end of file +docker/conf +docker/target \ No newline at end of file diff --git a/agents/threadpool/config/agent.config b/agent/config/agent.config similarity index 100% rename from agents/threadpool/config/agent.config rename to agent/config/agent.config diff --git a/agents/threadpool/dist-material/LICENSE b/agent/dist-material/LICENSE similarity index 100% rename from agents/threadpool/dist-material/LICENSE rename to agent/dist-material/LICENSE diff --git a/agents/threadpool/dist-material/NOTICE b/agent/dist-material/NOTICE similarity index 100% rename from agents/threadpool/dist-material/NOTICE rename to agent/dist-material/NOTICE diff --git a/agents/threadpool/hippo4j-agent-bootstrap/pom.xml b/agent/hippo4j-agent-bootstrap/pom.xml similarity index 94% rename from agents/threadpool/hippo4j-agent-bootstrap/pom.xml rename to agent/hippo4j-agent-bootstrap/pom.xml index 6dddcc4f..8504850d 100644 --- a/agents/threadpool/hippo4j-agent-bootstrap/pom.xml +++ b/agent/hippo4j-agent-bootstrap/pom.xml @@ -5,7 +5,7 @@ 4.0.0 cn.hippo4j - hippo4j-threadpool-agent + hippo4j-agent ${revision} @@ -96,7 +96,7 @@ - + @@ -108,12 +108,12 @@ - - - - - - + + + + + + diff --git a/agents/threadpool/hippo4j-agent-bootstrap/src/main/java/cn/hippo4j/agent/bootstrap/Hippo4jAgent.java b/agent/hippo4j-agent-bootstrap/src/main/java/cn/hippo4j/agent/bootstrap/Hippo4jAgent.java similarity index 100% rename from agents/threadpool/hippo4j-agent-bootstrap/src/main/java/cn/hippo4j/agent/bootstrap/Hippo4jAgent.java rename to agent/hippo4j-agent-bootstrap/src/main/java/cn/hippo4j/agent/bootstrap/Hippo4jAgent.java diff --git a/agents/threadpool/hippo4j-agent-core/pom.xml b/agent/hippo4j-agent-core/pom.xml similarity index 99% rename from agents/threadpool/hippo4j-agent-core/pom.xml rename to agent/hippo4j-agent-core/pom.xml index b299e9dc..e020e562 100644 --- a/agents/threadpool/hippo4j-agent-core/pom.xml +++ b/agent/hippo4j-agent-core/pom.xml @@ -5,7 +5,7 @@ 4.0.0 cn.hippo4j - hippo4j-threadpool-agent + hippo4j-agent ${revision} diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/base64/Base64.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/base64/Base64.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/base64/Base64.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/base64/Base64.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackageNotFoundException.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackageNotFoundException.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackageNotFoundException.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackageNotFoundException.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackagePath.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackagePath.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackagePath.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackagePath.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/BootService.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/BootService.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/BootService.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/BootService.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultImplementor.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultImplementor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultImplementor.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultImplementor.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultNamedThreadFactory.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultNamedThreadFactory.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultNamedThreadFactory.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultNamedThreadFactory.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/OverrideImplementor.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/OverrideImplementor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/OverrideImplementor.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/OverrideImplementor.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/PluginConfig.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/PluginConfig.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/PluginConfig.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/PluginConfig.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceConflictException.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceConflictException.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceConflictException.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceConflictException.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceManager.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceManager.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceManager.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/ServiceManager.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigNode.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigNode.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigNode.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigNode.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/ConfigNotFoundException.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/ConfigNotFoundException.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/ConfigNotFoundException.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/ConfigNotFoundException.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/RuntimeContextConfiguration.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/RuntimeContextConfiguration.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/RuntimeContextConfiguration.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/RuntimeContextConfiguration.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/dynamic/AgentConfigChangeWatcher.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/dynamic/AgentConfigChangeWatcher.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/dynamic/AgentConfigChangeWatcher.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/dynamic/AgentConfigChangeWatcher.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/jvm/LoadedLibraryCollector.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/jvm/LoadedLibraryCollector.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/jvm/LoadedLibraryCollector.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/jvm/LoadedLibraryCollector.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/ILog.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/ILog.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/ILog.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/ILog.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogManager.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogManager.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogManager.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogManager.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogResolver.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogResolver.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogResolver.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogResolver.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/NoopLogger.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/NoopLogger.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/NoopLogger.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/NoopLogger.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/AbstractLogger.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/AbstractLogger.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/AbstractLogger.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/AbstractLogger.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Converter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Converter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Converter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Converter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/FileWriter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/FileWriter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/FileWriter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/FileWriter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/IWriter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/IWriter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/IWriter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/IWriter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogResolver.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogResolver.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogResolver.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogResolver.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogger.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogger.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogger.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogger.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogEvent.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogEvent.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogEvent.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogEvent.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogLevel.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogLevel.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogLevel.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogLevel.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogMessageHolder.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogMessageHolder.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogMessageHolder.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogMessageHolder.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogOutput.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogOutput.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogOutput.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogOutput.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Parser.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Parser.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Parser.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Parser.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogResolver.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogResolver.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogResolver.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogResolver.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogger.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogger.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogger.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogger.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/ResolverType.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/ResolverType.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/ResolverType.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/ResolverType.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/SystemOutWriter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/SystemOutWriter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/SystemOutWriter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/SystemOutWriter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/WriterFactory.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/WriterFactory.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/WriterFactory.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/WriterFactory.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/AgentNameConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/AgentNameConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/AgentNameConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/AgentNameConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ClassConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ClassConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ClassConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ClassConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/DateConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/DateConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/DateConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/DateConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LevelConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LevelConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LevelConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LevelConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LiteralConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LiteralConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LiteralConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LiteralConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/MessageConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/MessageConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/MessageConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/MessageConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThreadConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThreadConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThreadConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThreadConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThrowableConverter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThrowableConverter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThrowableConverter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThrowableConverter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/OSUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/OSUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/OSUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/OSUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/ProcessorUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/ProcessorUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/ProcessorUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/os/ProcessorUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/AbstractClassEnhancePluginDefine.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/AbstractClassEnhancePluginDefine.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/AbstractClassEnhancePluginDefine.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/AbstractClassEnhancePluginDefine.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/ByteBuddyCoreClasses.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/ByteBuddyCoreClasses.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/ByteBuddyCoreClasses.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/ByteBuddyCoreClasses.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/DynamicPluginLoader.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/DynamicPluginLoader.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/DynamicPluginLoader.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/DynamicPluginLoader.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/EnhanceContext.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/EnhanceContext.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/EnhanceContext.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/EnhanceContext.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/InstrumentDebuggingClass.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/InstrumentDebuggingClass.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/InstrumentDebuggingClass.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/InstrumentDebuggingClass.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginBootstrap.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginBootstrap.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginBootstrap.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginBootstrap.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginCfg.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginCfg.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginCfg.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginCfg.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginDefine.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginDefine.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginDefine.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginDefine.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginException.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginException.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginException.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginException.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginFinder.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginFinder.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginFinder.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginFinder.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginResourcesResolver.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginResourcesResolver.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginResourcesResolver.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginResourcesResolver.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginSelector.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginSelector.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginSelector.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/PluginSelector.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessFinder.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessFinder.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessFinder.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessFinder.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessMethod.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessMethod.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessMethod.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/WitnessMethod.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapPluginLogBridge.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapPluginLogBridge.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapPluginLogBridge.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/BootstrapPluginLogBridge.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/IBootstrapLog.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/IBootstrapLog.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/IBootstrapLog.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/IBootstrapLog.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/ConstructorInterTemplate.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/ConstructorInterTemplate.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/ConstructorInterTemplate.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/ConstructorInterTemplate.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterTemplate.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterTemplate.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterTemplate.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterTemplate.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterWithOverrideArgsTemplate.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterWithOverrideArgsTemplate.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterWithOverrideArgsTemplate.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/InstanceMethodInterWithOverrideArgsTemplate.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterTemplate.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterTemplate.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterTemplate.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterTemplate.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterWithOverrideArgsTemplate.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterWithOverrideArgsTemplate.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterWithOverrideArgsTemplate.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/StaticMethodInterWithOverrideArgsTemplate.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2Template.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2Template.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2Template.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2Template.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2WithOverrideArgsTemplate.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2WithOverrideArgsTemplate.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2WithOverrideArgsTemplate.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/InstanceMethodInterV2WithOverrideArgsTemplate.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2Template.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2Template.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2Template.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2Template.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2WithOverrideArgsTemplate.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2WithOverrideArgsTemplate.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2WithOverrideArgsTemplate.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bootstrap/template/v2/StaticMethodInterV2WithOverrideArgsTemplate.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AbstractJunction.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AbstractJunction.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AbstractJunction.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AbstractJunction.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AnnotationTypeNameMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AnnotationTypeNameMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AnnotationTypeNameMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/AnnotationTypeNameMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArgumentTypeNameMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArrayTypeNameChecker.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArrayTypeNameChecker.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArrayTypeNameChecker.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ArrayTypeNameChecker.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/CacheableTransformerDecorator.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/CacheableTransformerDecorator.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/CacheableTransformerDecorator.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/CacheableTransformerDecorator.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ClassCacheMode.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ClassCacheMode.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ClassCacheMode.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ClassCacheMode.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ReturnTypeNameMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ReturnTypeNameMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ReturnTypeNameMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ReturnTypeNameMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/exception/IllegalPluginDefineException.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/exception/IllegalPluginDefineException.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/exception/IllegalPluginDefineException.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/exception/IllegalPluginDefineException.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/ConstructorInterceptPoint.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/ConstructorInterceptPoint.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/ConstructorInterceptPoint.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/ConstructorInterceptPoint.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/DeclaredInstanceMethodsInterceptPoint.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/DeclaredInstanceMethodsInterceptPoint.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/DeclaredInstanceMethodsInterceptPoint.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/DeclaredInstanceMethodsInterceptPoint.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/EnhanceException.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/EnhanceException.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/EnhanceException.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/EnhanceException.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/InstanceMethodsInterceptPoint.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/StaticMethodsInterceptPoint.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/BootstrapInterRuntimeAssist.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/BootstrapInterRuntimeAssist.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/BootstrapInterRuntimeAssist.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/BootstrapInterRuntimeAssist.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ClassStaticMethodsEnhancePluginDefine.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ConstructorInter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ConstructorInter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ConstructorInter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/ConstructorInter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/EnhancedInstance.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/EnhancedInstance.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/EnhancedInstance.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/EnhancedInstance.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstMethodsInterWithOverrideArgs.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceConstructorInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/InstanceMethodsAroundInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/MethodInterceptResult.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/OverrideCallable.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/OverrideCallable.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/OverrideCallable.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/OverrideCallable.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsAroundInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/StaticMethodsInterWithOverrideArgs.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassEnhancePluginDefineV2.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassEnhancePluginDefineV2.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassEnhancePluginDefineV2.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassEnhancePluginDefineV2.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassInstanceMethodsEnhancePluginDefineV2.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassInstanceMethodsEnhancePluginDefineV2.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassInstanceMethodsEnhancePluginDefineV2.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassInstanceMethodsEnhancePluginDefineV2.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassStaticMethodsEnhancePluginDefineV2.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassStaticMethodsEnhancePluginDefineV2.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassStaticMethodsEnhancePluginDefineV2.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/ClassStaticMethodsEnhancePluginDefineV2.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2WithOverrideArgs.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2WithOverrideArgs.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2WithOverrideArgs.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstMethodsInterV2WithOverrideArgs.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstanceMethodsAroundInterceptorV2.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstanceMethodsAroundInterceptorV2.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstanceMethodsAroundInterceptorV2.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/InstanceMethodsAroundInterceptorV2.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/MethodInvocationContext.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/MethodInvocationContext.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/MethodInvocationContext.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/MethodInvocationContext.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsAroundInterceptorV2.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsAroundInterceptorV2.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsAroundInterceptorV2.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsAroundInterceptorV2.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2WithOverrideArgs.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2WithOverrideArgs.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2WithOverrideArgs.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/enhance/v2/StaticMethodsInterV2WithOverrideArgs.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/ConstructorInterceptV2Point.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/ConstructorInterceptV2Point.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/ConstructorInterceptV2Point.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/ConstructorInterceptV2Point.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/DeclaredInstanceMethodsInterceptV2Point.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/DeclaredInstanceMethodsInterceptV2Point.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/DeclaredInstanceMethodsInterceptV2Point.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/DeclaredInstanceMethodsInterceptV2Point.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/InstanceMethodsInterceptV2Point.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/InstanceMethodsInterceptV2Point.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/InstanceMethodsInterceptV2Point.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/InstanceMethodsInterceptV2Point.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/StaticMethodsInterceptV2Point.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/StaticMethodsInterceptV2Point.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/StaticMethodsInterceptV2Point.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/interceptor/v2/StaticMethodsInterceptV2Point.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/jdk9module/JDK9ModuleExporter.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/jdk9module/JDK9ModuleExporter.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/jdk9module/JDK9ModuleExporter.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/jdk9module/JDK9ModuleExporter.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/AgentClassLoader.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/AgentClassLoader.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/AgentClassLoader.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/AgentClassLoader.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InstrumentationLoader.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InstrumentationLoader.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InstrumentationLoader.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InstrumentationLoader.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InterceptorInstanceLoader.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InterceptorInstanceLoader.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InterceptorInstanceLoader.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/loader/InterceptorInstanceLoader.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassAnnotationMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassAnnotationMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassAnnotationMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassAnnotationMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ClassMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/HierarchyMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/HierarchyMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/HierarchyMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/HierarchyMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/IndirectMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/IndirectMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/IndirectMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/IndirectMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodAnnotationMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodAnnotationMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodAnnotationMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodAnnotationMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodInheritanceAnnotationMatcher.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodInheritanceAnnotationMatcher.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodInheritanceAnnotationMatcher.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MethodInheritanceAnnotationMatcher.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MultiClassNameMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MultiClassNameMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MultiClassNameMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/MultiClassNameMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/NameMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/NameMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/NameMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/NameMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/PrefixMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/PrefixMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/PrefixMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/PrefixMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ProtectiveShieldMatcher.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ProtectiveShieldMatcher.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ProtectiveShieldMatcher.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/ProtectiveShieldMatcher.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/RegexMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/RegexMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/RegexMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/RegexMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalAndMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalAndMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalAndMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalAndMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalMatchOperation.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalMatchOperation.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalMatchOperation.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalMatchOperation.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalOrMatch.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalOrMatch.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalOrMatch.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/match/logical/LogicalOrMatch.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CustomizeExpression.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CustomizeExpression.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CustomizeExpression.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CustomizeExpression.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/FileUtils.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/FileUtils.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/FileUtils.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/FileUtils.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/IOUtils.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/IOUtils.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/IOUtils.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/IOUtils.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/Length.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/Length.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/Length.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/Length.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/MethodUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/MethodUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/MethodUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/MethodUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PlaceholderConfigurerSupport.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PlaceholderConfigurerSupport.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PlaceholderConfigurerSupport.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PlaceholderConfigurerSupport.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PrivateKeyUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PrivateKeyUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PrivateKeyUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PrivateKeyUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PropertyPlaceholderHelper.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PropertyPlaceholderHelper.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PropertyPlaceholderHelper.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/PropertyPlaceholderHelper.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RegexUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RegexUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RegexUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RegexUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RunnableWithExceptionProtection.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RunnableWithExceptionProtection.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RunnableWithExceptionProtection.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RunnableWithExceptionProtection.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/StringUtil.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/StringUtil.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/StringUtil.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/StringUtil.java diff --git a/agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ThreadPoolPropertyKey.java b/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ThreadPoolPropertyKey.java similarity index 100% rename from agents/threadpool/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ThreadPoolPropertyKey.java rename to agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ThreadPoolPropertyKey.java diff --git a/agents/threadpool/hippo4j-agent-plugin/apollo-plugin/pom.xml b/agent/hippo4j-agent-plugin/apollo-plugin/pom.xml similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/apollo-plugin/pom.xml rename to agent/hippo4j-agent-plugin/apollo-plugin/pom.xml diff --git a/agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/boot/ApolloPluginBootService.java b/agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/boot/ApolloPluginBootService.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/boot/ApolloPluginBootService.java rename to agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/boot/ApolloPluginBootService.java diff --git a/agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/define/ApolloInstrumentation.java b/agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/define/ApolloInstrumentation.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/define/ApolloInstrumentation.java rename to agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/define/ApolloInstrumentation.java diff --git a/agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/interceptor/DefaultConfigConstructorInterceptor.java b/agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/interceptor/DefaultConfigConstructorInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/interceptor/DefaultConfigConstructorInterceptor.java rename to agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/interceptor/DefaultConfigConstructorInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/resources/META-INF/services/cn.hippo4j.agent.core.boot.BootService b/agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/META-INF/services/cn.hippo4j.agent.core.boot.BootService similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/resources/META-INF/services/cn.hippo4j.agent.core.boot.BootService rename to agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/META-INF/services/cn.hippo4j.agent.core.boot.BootService diff --git a/agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/resources/hippo4j-plugin.def b/agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/hippo4j-plugin.def similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/apollo-plugin/src/main/resources/hippo4j-plugin.def rename to agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/hippo4j-plugin.def diff --git a/agents/threadpool/hippo4j-agent-plugin/pom.xml b/agent/hippo4j-agent-plugin/pom.xml similarity index 97% rename from agents/threadpool/hippo4j-agent-plugin/pom.xml rename to agent/hippo4j-agent-plugin/pom.xml index 0a4ed758..934aea83 100644 --- a/agents/threadpool/hippo4j-agent-plugin/pom.xml +++ b/agent/hippo4j-agent-plugin/pom.xml @@ -5,7 +5,7 @@ 4.0.0 cn.hippo4j - hippo4j-threadpool-agent + hippo4j-agent ${revision} @@ -23,7 +23,7 @@ net.bytebuddy ${shade.package}.${shade.net.bytebuddy.source} - ${project.build.directory}${sdk.plugin.related.dir}/../../../agent-dist + ${project.build.directory}${sdk.plugin.related.dir}/../../../hippo4j-agent ${agent.package.dest.dir}/plugins diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/pom.xml b/agent/hippo4j-agent-plugin/spring-plugins/pom.xml similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/pom.xml rename to agent/hippo4j-agent-plugin/spring-plugins/pom.xml diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/DynamicThreadPoolChangeHandlerSpring1x.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/DynamicThreadPoolChangeHandlerSpring1x.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/DynamicThreadPoolChangeHandlerSpring1x.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/DynamicThreadPoolChangeHandlerSpring1x.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentation.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentation.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentation.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentation.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/resources/hippo4j-plugin.def b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/resources/hippo4j-plugin.def similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/resources/hippo4j-plugin.def rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/resources/hippo4j-plugin.def diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/pom.xml b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/pom.xml similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/pom.xml rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/pom.xml diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentation.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentation.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentation.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentation.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/resources/hippo4j-plugin.def b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/resources/hippo4j-plugin.def similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/resources/hippo4j-plugin.def rename to agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2.x-plugin/src/main/resources/hippo4j-plugin.def diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/pom.xml b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/pom.xml similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/pom.xml rename to agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/pom.xml diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/interceptor/EventPublishingRunListenerEnvironmentPreparedInterceptor.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/interceptor/EventPublishingRunListenerEnvironmentPreparedInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/interceptor/EventPublishingRunListenerEnvironmentPreparedInterceptor.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/interceptor/EventPublishingRunListenerEnvironmentPreparedInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/AbstractDynamicThreadPoolChangeHandlerSpring.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/AbstractDynamicThreadPoolChangeHandlerSpring.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/AbstractDynamicThreadPoolChangeHandlerSpring.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/AbstractDynamicThreadPoolChangeHandlerSpring.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringEnvironmentSupport.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringEnvironmentSupport.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringEnvironmentSupport.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringEnvironmentSupport.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringPropertiesLoader.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringPropertiesLoader.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringPropertiesLoader.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringPropertiesLoader.java diff --git a/agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java rename to agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java diff --git a/agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/pom.xml b/agent/hippo4j-agent-plugin/thread-pool-plugin/pom.xml similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/pom.xml rename to agent/hippo4j-agent-plugin/thread-pool-plugin/pom.xml diff --git a/agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/define/ThreadPoolExecutorInstrumentation.java b/agent/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/define/ThreadPoolExecutorInstrumentation.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/define/ThreadPoolExecutorInstrumentation.java rename to agent/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/define/ThreadPoolExecutorInstrumentation.java diff --git a/agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java b/agent/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java rename to agent/hippo4j-agent-plugin/thread-pool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java diff --git a/agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/src/main/resources/hippo4j-plugin.def b/agent/hippo4j-agent-plugin/thread-pool-plugin/src/main/resources/hippo4j-plugin.def similarity index 100% rename from agents/threadpool/hippo4j-agent-plugin/thread-pool-plugin/src/main/resources/hippo4j-plugin.def rename to agent/hippo4j-agent-plugin/thread-pool-plugin/src/main/resources/hippo4j-plugin.def diff --git a/agents/threadpool/pom.xml b/agent/pom.xml similarity index 98% rename from agents/threadpool/pom.xml rename to agent/pom.xml index bd1437f8..d0a8b793 100644 --- a/agents/threadpool/pom.xml +++ b/agent/pom.xml @@ -5,12 +5,12 @@ 4.0.0 cn.hippo4j - hippo4j-agents + hippo4j-all ${revision} - - hippo4j-threadpool-agent + hippo4j-agent pom + hippo4j-agent-core hippo4j-agent-plugin @@ -20,7 +20,7 @@ cn.hippo4j.agent.dependencies 1.8 - 4.12 + 4.13.1 2.0.7 3.5.13 1.18.20 diff --git a/agents/pom.xml b/agents/pom.xml deleted file mode 100644 index d14ffda6..00000000 --- a/agents/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - 4.0.0 - - cn.hippo4j - hippo4j-all - ${revision} - - hippo4j-agents - pom - - - true - - - - threadpool - - \ No newline at end of file diff --git a/docker/threadpool/Dockerfile b/docker/Dockerfile similarity index 100% rename from docker/threadpool/Dockerfile rename to docker/Dockerfile diff --git a/docker/threadpool/docker-startup.sh b/docker/docker-startup.sh similarity index 100% rename from docker/threadpool/docker-startup.sh rename to docker/docker-startup.sh diff --git a/docs/docs/user_docs/ops/server-docker.md b/docs/docs/user_docs/ops/server-docker.md index 2f81a57e..7b106a2c 100644 --- a/docs/docs/user_docs/ops/server-docker.md +++ b/docs/docs/user_docs/ops/server-docker.md @@ -36,9 +36,9 @@ hippo4j/hippo4j-server ```shell # 进入到 threadpool/server/bootstrap 工程路径下 mvn clean package -Dskip.spotless.apply=true -# 进入到 docker/threadpool 工程路径下 +# 进入到 docker 工程路径下 # 默认打包是打包的 tag 是 latest -docker build -t hippo4j/hippo4j-server ../threadpool +docker build -t hippo4j/hippo4j-server ../docker ``` 方式二: diff --git a/docs/i18n/zh/docusaurus-plugin-content-docs/current/user_docs/ops/server-docker.md b/docs/i18n/zh/docusaurus-plugin-content-docs/current/user_docs/ops/server-docker.md index 2f81a57e..7b106a2c 100644 --- a/docs/i18n/zh/docusaurus-plugin-content-docs/current/user_docs/ops/server-docker.md +++ b/docs/i18n/zh/docusaurus-plugin-content-docs/current/user_docs/ops/server-docker.md @@ -36,9 +36,9 @@ hippo4j/hippo4j-server ```shell # 进入到 threadpool/server/bootstrap 工程路径下 mvn clean package -Dskip.spotless.apply=true -# 进入到 docker/threadpool 工程路径下 +# 进入到 docker 工程路径下 # 默认打包是打包的 tag 是 latest -docker build -t hippo4j/hippo4j-server ../threadpool +docker build -t hippo4j/hippo4j-server ../docker ``` 方式二: diff --git a/docs/i18n/zh/docusaurus-plugin-content-pages/users.md b/docs/i18n/zh/docusaurus-plugin-content-pages/users.md index f667e7e7..c780d5e1 100644 --- a/docs/i18n/zh/docusaurus-plugin-content-pages/users.md +++ b/docs/i18n/zh/docusaurus-plugin-content-pages/users.md @@ -5,7 +5,7 @@ title: 采用公司 ## 谁在使用 Hippo4j -共计 37+ 家公司生产接入 Hippo4j,按照公司登记时间排序。 +共计 38+ 家公司生产接入 Hippo4j,按照公司登记时间排序。 - [身边云](https://serviceshare.com) - [思派健康科技](https://www.medbanks.cn) @@ -44,6 +44,7 @@ title: 采用公司 - [网易有道信息技术(北京)有限公司](https://www.youdao.com) - [神州数码(西安)](https://www.digitalchina.com) - [广联达科技股份有限公司](https://www.glodon.com) +- [天健联创控股集团有限公司](https://www.tjlc.com.cn) ## 登记 diff --git a/docs/src/pages/users.md b/docs/src/pages/users.md index f667e7e7..c780d5e1 100644 --- a/docs/src/pages/users.md +++ b/docs/src/pages/users.md @@ -5,7 +5,7 @@ title: 采用公司 ## 谁在使用 Hippo4j -共计 37+ 家公司生产接入 Hippo4j,按照公司登记时间排序。 +共计 38+ 家公司生产接入 Hippo4j,按照公司登记时间排序。 - [身边云](https://serviceshare.com) - [思派健康科技](https://www.medbanks.cn) @@ -44,6 +44,7 @@ title: 采用公司 - [网易有道信息技术(北京)有限公司](https://www.youdao.com) - [神州数码(西安)](https://www.digitalchina.com) - [广联达科技股份有限公司](https://www.glodon.com) +- [天健联创控股集团有限公司](https://www.tjlc.com.cn) ## 登记 diff --git a/infra/common/src/test/java/cn/hippo4j/common/toolkit/ClassUtilTest.java b/infra/common/src/test/java/cn/hippo4j/common/toolkit/ClassUtilTest.java new file mode 100644 index 00000000..548ff0b3 --- /dev/null +++ b/infra/common/src/test/java/cn/hippo4j/common/toolkit/ClassUtilTest.java @@ -0,0 +1,27 @@ +package cn.hippo4j.common.toolkit; + + +import org.junit.Assert; +import org.junit.Test; + +/** + * test for {@link ClassUtil} + */ +public class ClassUtilTest { + + @Test + public void testGetClassLoader(){ + ClassLoader expectedClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader actualClassLoader = ClassUtil.getClassLoader(ClassUtilTest.class); + Assert.assertEquals(expectedClassLoader, actualClassLoader); + + expectedClassLoader = ClassUtilTest.class.getClassLoader(); + actualClassLoader = ClassUtil.getClassLoader(null); + Assert.assertEquals(expectedClassLoader, actualClassLoader); + + expectedClassLoader = ClassLoader.getSystemClassLoader(); + actualClassLoader = ClassUtil.getClassLoader(String.class); + Assert.assertEquals(expectedClassLoader, actualClassLoader); + } + +} diff --git a/infra/common/src/test/java/cn/hippo4j/common/toolkit/http/HttpUtilsTest.java b/infra/common/src/test/java/cn/hippo4j/common/toolkit/http/HttpUtilsTest.java index a4e500b7..73e5c282 100644 --- a/infra/common/src/test/java/cn/hippo4j/common/toolkit/http/HttpUtilsTest.java +++ b/infra/common/src/test/java/cn/hippo4j/common/toolkit/http/HttpUtilsTest.java @@ -50,28 +50,33 @@ public class HttpUtilsTest { static final String LOGIN_URL = "/login"; static final String LOGIN_NAME = "loginServlet"; static final String CONTEXT_PATH = "/"; - static final String PATH_NAME = "."; static final String USER_DIR = "user.dir"; - static final String PREFIX = File.separator + "tomcat."; + static final String BASE_DIR = System.getProperty(USER_DIR) + "/target/tomcat"; @BeforeClass public static void startWeb() throws IOException, LifecycleException { tomcat = new Tomcat(); + // clear historical files that may be left behind + deleteBaseDir(); + // set base dir + tomcat.setBaseDir(BASE_DIR); // get a random port ServerSocket socket = new ServerSocket(0); PORT = socket.getLocalPort(); socket.close(); tomcat.setPort(PORT); + // set a connector Connector connector = new Connector(PROTOCOL); connector.setThrowOnFailure(true); connector.setPort(PORT); tomcat.setConnector(connector); - String absolutePath = new File(PATH_NAME).getAbsolutePath(); - Context context = tomcat.addContext(CONTEXT_PATH, absolutePath); + // set a context + Context context = tomcat.addContext(CONTEXT_PATH, BASE_DIR); Tomcat.addServlet(context, HOME_PAGE_NAME, new HomeServlet()).setAsyncSupported(true); context.addServletMappingDecoded(HOME_PAGE_URL, HOME_PAGE_NAME); Tomcat.addServlet(context, LOGIN_NAME, new LoginServlet()).setAsyncSupported(true); context.addServletMappingDecoded(LOGIN_URL, LOGIN_NAME); + // start tomcat tomcat.start(); } @@ -80,8 +85,15 @@ public class HttpUtilsTest { // stop tomcat tomcat.stop(); // del dir - String userUrl = System.getProperty(USER_DIR); - File file = new File(userUrl + PREFIX + PORT); + deleteBaseDir(); + } + + /** + * forcibly delete the tomcat's base dir and its sub files + */ + private static void deleteBaseDir() throws IOException { + File file = new File(BASE_DIR); + // fail fast if (!file.exists()) { return; } @@ -98,7 +110,6 @@ public class HttpUtilsTest { Files.delete(dir); return FileVisitResult.CONTINUE; } - }); } diff --git a/pom.xml b/pom.xml index 4a2f7683..d63fbf73 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ - agents + agent dependencies examples infra diff --git a/threadpool/console/package.json b/threadpool/console/package.json index aa4202ab..505a900b 100755 --- a/threadpool/console/package.json +++ b/threadpool/console/package.json @@ -44,9 +44,11 @@ }, "dependencies": { "axios": ">=0.18.1", + "buffer": "^6.0.3", "clipboard": "2.0.4", "codemirror": "5.45.0", "core-js": "^3.26.0", + "crypto": "^1.0.1", "echarts": "^5.2.2", "element-ui": "^2.15.7", "fuse.js": "3.4.4", diff --git a/threadpool/console/src/store/modules/user.js b/threadpool/console/src/store/modules/user.js index bae7a0c1..4b73f6b7 100755 --- a/threadpool/console/src/store/modules/user.js +++ b/threadpool/console/src/store/modules/user.js @@ -1,126 +1,131 @@ -import { login } from '@/api/user'; -import { getToken, setToken, removeToken } from '@/utils/auth'; -import router, { resetRouter } from '@/router'; +import {login} from '@/api/user'; +import {getToken, removeToken, setToken} from '@/utils/auth'; +import router, {resetRouter} from '@/router'; +import {genKey, encrypt} from '@/utils/aes-util'; const state = { - token: getToken(), - name: '', - avatar: '', - introduction: '', - roles: [], + token: getToken(), + name: '', + avatar: '', + introduction: '', + roles: [], }; const mutations = { - SET_TOKEN: (state, token) => { - state.token = token; - }, - SET_INTRODUCTION: (state, introduction) => { - state.introduction = introduction; - }, - SET_NAME: (state, name) => { - state.name = name; - }, - SET_AVATAR: (state, avatar) => { - state.avatar = avatar; - }, - SET_ROLES: (state, roles) => { - state.roles = roles; - }, + SET_TOKEN: (state, token) => { + state.token = token; + }, + SET_INTRODUCTION: (state, introduction) => { + state.introduction = introduction; + }, + SET_NAME: (state, name) => { + state.name = name; + }, + SET_AVATAR: (state, avatar) => { + state.avatar = avatar; + }, + SET_ROLES: (state, roles) => { + state.roles = roles; + }, }; const actions = { - // user login - login({ commit }, userInfo) { - const { username, password } = userInfo; - return new Promise((resolve, reject) => { - login({ username: username.trim(), password: password, rememberMe: 1 }) - .then((response) => { - const { data } = response; - const { roles } = response; - commit('SET_TOKEN', data); - localStorage.setItem('roles', JSON.stringify(roles)); - localStorage.setItem('USER_ROLE', roles[0]); - setToken(data); - resolve(); - }) - .catch((error) => { - alert('登录失败'); - reject(error); + // user login + login({commit}, userInfo) { + const {username, password} = userInfo; + return new Promise((resolve, reject) => { + let key = genKey(); + let encodePassword = encrypt(password, key) + key = key.split("").reverse().join("") + login({username: username.trim(), password: encodePassword, tag: key, rememberMe: 1}) + .then((response) => { + const {data} = response; + const {roles} = response; + commit('SET_TOKEN', data); + localStorage.setItem('roles', JSON.stringify(roles)); + localStorage.setItem('USER_ROLE', roles[0]); + setToken(data); + resolve(); + }) + .catch((error) => { + // alert('登录失败'); + reject(error); + }); }); - }); - }, - - // get user info - getInfo({ commit, state }) { - return new Promise((resolve, reject) => { - const data = {}; - data.roles = JSON.parse(localStorage.getItem('roles')); - commit('SET_ROLES', data.roles); - resolve(data); - }); - }, - - // user logout - logout({ commit, state }) { - // return new Promise((resolve, reject) => { - // logout(state.token).then(() => { - // commit('SET_TOKEN', '') - // commit('SET_ROLES', []) - // removeToken() - // resetRouter() - // resolve() - // }).catch(error => { - // reject(error) - // }) - // }) - return new Promise((resolve) => { - commit('SET_TOKEN', ''); - commit('SET_ROLES', []); - removeToken(); - resetRouter(); - resolve(); - }); - }, - - // remove token - resetToken({ commit }) { - return new Promise((resolve) => { - commit('SET_TOKEN', ''); - commit('SET_ROLES', []); - removeToken(); - resolve(); - }); - }, - - // dynamically modify permissions - changeRoles({ commit, dispatch }, role) { - return new Promise(async (resolve) => { - const token = role + '-token'; - - commit('SET_TOKEN', token); - setToken(token); - - const { roles } = await dispatch('getInfo'); - - resetRouter(); - - // generate accessible routes map based on roles - const accessRoutes = await dispatch('permission/generateRoutes', roles, { root: true }); - - // dynamically add accessible routes - router.addRoutes(accessRoutes); - - // reset visited views and cached views - dispatch('tagsView/delAllViews', null, { root: true }); - - resolve(); - }); - }, + }, + + + // get user info + getInfo({commit, state}) { + return new Promise((resolve, reject) => { + const data = {}; + data.roles = JSON.parse(localStorage.getItem('roles')); + commit('SET_ROLES', data.roles); + resolve(data); + }); + }, + + // user logout + logout({commit, state}) { + // return new Promise((resolve, reject) => { + // logout(state.token).then(() => { + // commit('SET_TOKEN', '') + // commit('SET_ROLES', []) + // removeToken() + // resetRouter() + // resolve() + // }).catch(error => { + // reject(error) + // }) + // }) + return new Promise((resolve) => { + commit('SET_TOKEN', ''); + commit('SET_ROLES', []); + removeToken(); + resetRouter(); + resolve(); + }); + }, + + // remove token + resetToken({commit}) { + return new Promise((resolve) => { + commit('SET_TOKEN', ''); + commit('SET_ROLES', []); + removeToken(); + resolve(); + }); + }, + + // dynamically modify permissions + changeRoles({commit, dispatch}, role) { + return new Promise(async (resolve) => { + const token = role + '-token'; + + commit('SET_TOKEN', token); + setToken(token); + + const {roles} = await dispatch('getInfo'); + + resetRouter(); + + // generate accessible routes map based on roles + const accessRoutes = await dispatch('permission/generateRoutes', roles, {root: true}); + + // dynamically add accessible routes + router.addRoutes(accessRoutes); + + // reset visited views and cached views + dispatch('tagsView/delAllViews', null, {root: true}); + + resolve(); + }); + }, }; export default { - namespaced: true, - state, - mutations, - actions, + namespaced: true, + state, + mutations, + actions, }; diff --git a/threadpool/console/src/utils/aes-util.js b/threadpool/console/src/utils/aes-util.js new file mode 100644 index 00000000..d4d78736 --- /dev/null +++ b/threadpool/console/src/utils/aes-util.js @@ -0,0 +1,37 @@ +import {Buffer} from 'buffer' +import crypto from 'crypto' + +/** + * generate key + * @returns {string} key(length 16) + */ +export function genKey() { + let chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + let result = ''; + for (let i = 16; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)]; + return result; +} + +/** + * encode message + * @param msg message + * @param key key + * @returns {string} encoded message + */ +export function encrypt(msg, key) { + try { + let pwd = Buffer.from(key) + let iv = crypto.randomBytes(12) + let cipher = crypto.createCipheriv('aes-128-gcm', pwd, iv) + let enc = cipher.update(msg, 'utf8', 'base64') + enc += cipher.final('base64') + let tags = cipher.getAuthTag() + enc = Buffer.from(enc, 'base64') + let totalLength = iv.length + enc.length + tags.length + let bufferMsg = Buffer.concat([iv, enc, tags], totalLength) + return bufferMsg.toString('base64') + } catch (e) { + console.log("Encrypt is error", e) + return null + } +} \ No newline at end of file diff --git a/threadpool/console/src/views/login/index.vue b/threadpool/console/src/views/login/index.vue index 086359a3..66ce2387 100755 --- a/threadpool/console/src/views/login/index.vue +++ b/threadpool/console/src/views/login/index.vue @@ -170,8 +170,8 @@ export default { this.$router.push({ path: this.redirect || '/', query: this.otherQuery }); this.loading = false; }) - .catch(() => { - console.log('error catch.'); + .catch((e) => { + console.log('error catch.',e); this.loading = false; }); } else { diff --git a/threadpool/rpc/pom.xml b/threadpool/rpc/pom.xml index c6f0d91b..ca4a41a7 100644 --- a/threadpool/rpc/pom.xml +++ b/threadpool/rpc/pom.xml @@ -11,18 +11,14 @@ - cn.hippo4j - hippo4j-threadpool-infra-common - ${project.version} - - - org.springframework.boot - spring-boot-starter-test + junit + junit test - org.springframework - spring-web + cn.hippo4j + hippo4j-threadpool-infra-common + ${project.version} org.projectlombok diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/Client.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/Client.java index c3da92b0..aa5c90ce 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/Client.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/Client.java @@ -30,8 +30,7 @@ import java.io.Closeable; * able to communicate with the server. Wait for the server's Response ({@link Response}) *

METHOD

*
    - *
  • {@link #connection(Request)}
  • - *
  • {@link #isActive()}
  • + *
  • {@link #connect(Request)}
  • *
  • {@link #close()}
  • *
* You can usually use the client in this way: @@ -55,13 +54,6 @@ public interface Client extends Closeable { * @param request Request information, Requested methods and parameters * @return response Response from server side */ - Response connection(Request request); - - /** - * Check whether the client is active - * - * @return Whether active - */ - boolean isActive(); + R connect(Request request); } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyClientSupport.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/ClientSupport.java similarity index 56% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyClientSupport.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/ClientSupport.java index 602aecc6..18ea0205 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyClientSupport.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/ClientSupport.java @@ -15,15 +15,19 @@ * limitations under the License. */ -package cn.hippo4j.rpc.support; +package cn.hippo4j.rpc.client; -import cn.hippo4j.rpc.client.Client; -import cn.hippo4j.rpc.client.ClientConnection; -import cn.hippo4j.rpc.client.NettyClientConnection; -import cn.hippo4j.rpc.client.RPCClient; +import cn.hippo4j.rpc.connection.ClientConnection; +import cn.hippo4j.rpc.connection.SimpleClientConnection; +import cn.hippo4j.rpc.exception.OperationException; +import cn.hippo4j.rpc.handler.ErrorClientHandler; import cn.hippo4j.rpc.handler.HandlerManager; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.handler.NettyClientTakeHandler; +import cn.hippo4j.rpc.handler.ClientPoolHandler; +import cn.hippo4j.rpc.handler.ClientTakeHandler; +import cn.hippo4j.rpc.model.DefaultRequest; +import cn.hippo4j.rpc.model.Request; +import cn.hippo4j.rpc.support.AddressUtil; +import cn.hippo4j.rpc.server.ServerSupport; import io.netty.channel.ChannelHandler; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -33,6 +37,7 @@ import java.lang.ref.WeakReference; import java.net.InetSocketAddress; import java.util.Map; import java.util.Optional; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; /** @@ -48,12 +53,12 @@ import java.util.concurrent.ConcurrentHashMap; * by the container * * @see cn.hippo4j.rpc.client.RPCClient - * @see cn.hippo4j.rpc.client.NettyClientConnection - * @see NettyServerSupport + * @see SimpleClientConnection + * @see ServerSupport * @since 2.0.0 */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class NettyClientSupport { +public final class ClientSupport { /** * the cache for client @@ -69,13 +74,14 @@ public final class NettyClientSupport { */ public static Client getClient(InetSocketAddress address, HandlerManager handlerManager) { return CLIENT_MAP.computeIfAbsent(address, a -> { - NettyClientPoolHandler handler = (handlerManager instanceof NettyClientPoolHandler) - ? (NettyClientPoolHandler) handlerManager - : new NettyClientPoolHandler(); + ClientPoolHandler handler = (handlerManager instanceof ClientPoolHandler) + ? (ClientPoolHandler) handlerManager + : new ClientPoolHandler(); if (handler.isEmpty()) { - handler.addFirst(null, new NettyClientTakeHandler()); + handler.addFirst(null, new ClientTakeHandler()); } - NettyClientConnection connection = new NettyClientConnection(address, handler); + handler.addLast(null, new ErrorClientHandler()); + SimpleClientConnection connection = new SimpleClientConnection(address, handler); return new RPCClient(connection); }); } @@ -87,7 +93,44 @@ public final class NettyClientSupport { * @return Client */ public static Client getClient(InetSocketAddress address) { - return getClient(address, new NettyClientPoolHandler()); + return getClient(address, new ClientPoolHandler()); + } + + /** + * Find a suitable client and send a request to the server + * + * @param address address + * @param handlerName The handler that can handle this request + * @param param parameter + * @return result + */ + public static R clientSend(String address, String handlerName, Object[] param) { + InetSocketAddress socketAddress = AddressUtil.getInetAddress(address); + Client client = getClient(socketAddress); + Request request = new DefaultRequest(UUID.randomUUID().toString(), handlerName, param); + return client.connect(request); + } + + public static R clientSend(String address, String handlerName, Object param) { + Object[] params = {param}; + InetSocketAddress socketAddress = AddressUtil.getInetAddress(address); + Client client = getClient(socketAddress); + Request request = new DefaultRequest(UUID.randomUUID().toString(), handlerName, params); + return client.connect(request); + } + + /** + * Find a suitable client and send a request to the server + * + * @param address address + * @param handlerName The handler that can handle this request + * @return result + */ + public static R clientSend(String address, String handlerName) { + InetSocketAddress socketAddress = AddressUtil.getInetAddress(address); + Client client = getClient(socketAddress); + Request request = new DefaultRequest(UUID.randomUUID().toString(), handlerName); + return client.connect(request); } /** @@ -102,7 +145,7 @@ public final class NettyClientSupport { try { c.close(); } catch (IOException e) { - throw new RuntimeException(e); + throw new OperationException(e); } }); } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/NettyClientConnection.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/NettyClientConnection.java deleted file mode 100644 index 4a77c6c4..00000000 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/NettyClientConnection.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.client; - -import cn.hippo4j.common.toolkit.Assert; -import cn.hippo4j.rpc.exception.TimeOutException; -import cn.hippo4j.rpc.model.Request; -import cn.hippo4j.rpc.model.Response; -import cn.hippo4j.rpc.support.NettyConnectPool; -import cn.hippo4j.rpc.support.NettyConnectPoolHolder; -import cn.hippo4j.rpc.support.ResultHolder; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.pool.ChannelPoolHandler; -import lombok.extern.slf4j.Slf4j; - -import java.net.InetSocketAddress; -import java.util.Optional; -import java.util.concurrent.locks.LockSupport; - -/** - * Client implemented using netty - * - * @since 2.0.0 - */ -@Slf4j -public class NettyClientConnection implements ClientConnection { - - InetSocketAddress address; - /** - * Obtain the connection timeout period. The default value is 30s - */ - long timeout = 30000L; - final int nanosPerMilliSecond = 1000000; - - EventLoopGroup worker = new NioEventLoopGroup(); - NettyConnectPool connectionPool; - ChannelFuture future; - Channel channel; - - public NettyClientConnection(InetSocketAddress address, - ChannelPoolHandler handler) { - Assert.notNull(worker); - this.address = address; - this.connectionPool = NettyConnectPoolHolder.getPool(address, timeout, worker, handler); - } - - @Override - public Response connect(Request request) { - this.channel = connectionPool.acquire(timeout); - boolean debugEnabled = log.isDebugEnabled(); - Response response; - try { - String key = request.getKey(); - this.future = channel.writeAndFlush(request); - if (debugEnabled) { - log.debug("Call successful, target address is {}:{}, request key is {}", address.getHostName(), address.getPort(), key); - } - // Wait for execution to complete - ResultHolder.putThread(key, Thread.currentThread()); - LockSupport.parkNanos(timeout() * nanosPerMilliSecond); - response = ResultHolder.get(key); - if (response == null) { - throw new TimeOutException("Timeout waiting for server-side response"); - } - if (debugEnabled) { - log.debug("The response from {}:{} was received successfully with the response key {}.", address.getHostName(), address.getPort(), key); - } - return response; - } catch (Exception ex) { - throw ex; - } finally { - connectionPool.release(this.channel); - } - } - - @Override - public long timeout() { - return timeout; - } - - @Override - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - @Override - public void close() { - Optional.ofNullable(this.channel) - .ifPresent(c -> { - worker.shutdownGracefully(); - this.future.channel().close(); - this.channel.close(); - }); - } - - @Override - public boolean isActive() { - return channel.isActive(); - } -} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/RPCClient.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/RPCClient.java index 527f380d..48fda056 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/RPCClient.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/RPCClient.java @@ -17,8 +17,8 @@ package cn.hippo4j.rpc.client; +import cn.hippo4j.rpc.connection.ClientConnection; import cn.hippo4j.rpc.model.Request; -import cn.hippo4j.rpc.model.Response; import java.io.IOException; @@ -37,15 +37,10 @@ public class RPCClient implements Client { } @Override - public Response connection(Request request) { + public R connect(Request request) { return clientConnection.connect(request); } - @Override - public boolean isActive() { - return clientConnection.isActive(); - } - /** * Close the client and release all connections. * diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/coder/NettyEncoder.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/coder/ObjectEncoder.java similarity index 95% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/coder/NettyEncoder.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/coder/ObjectEncoder.java index 8c5ce752..982082e1 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/coder/NettyEncoder.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/coder/ObjectEncoder.java @@ -32,13 +32,13 @@ import java.io.Serializable; * * @since 2.0.0 */ -public class NettyEncoder extends MessageToByteEncoder { +public class ObjectEncoder extends MessageToByteEncoder { private static final int BYTE_LENGTH = 4; private static final byte[] BYTE = new byte[BYTE_LENGTH]; @Override - protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { + protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) { int startIndex = out.writerIndex(); try (ByteBufOutputStream outPut = new ByteBufOutputStream(out)) { outPut.write(BYTE); diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/ClientConnection.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ClientConnection.java similarity index 67% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/ClientConnection.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ClientConnection.java index cc30b3be..fd7d70b6 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/client/ClientConnection.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ClientConnection.java @@ -15,25 +15,31 @@ * limitations under the License. */ -package cn.hippo4j.rpc.client; +package cn.hippo4j.rpc.connection; -import cn.hippo4j.rpc.handler.Connection; import cn.hippo4j.rpc.model.Request; -import cn.hippo4j.rpc.model.Response; + +import java.io.Closeable; /** * Applicable to client connections
+ * Represents a network request connection and provides IO layer support
+ *

+ * This is not a strict and stateless Connection interface, it contains the necessary + * operations that should be done in the connection. It is more like integrating the + * connection and the connection channel together, so creating {@link ClientConnection} is + * very resource intensive, for which caching is recommended * * @since 2.0.0 */ -public interface ClientConnection extends Connection { +public interface ClientConnection extends Closeable { /** * Establish a connection and process * * @param request Request information */ - Response connect(Request request); + R connect(Request request); /** * Get timeout, ms diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyConnectPoolHolder.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ConnectPoolHolder.java similarity index 77% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyConnectPoolHolder.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ConnectPoolHolder.java index 8fada5f7..aa20983a 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyConnectPoolHolder.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ConnectPoolHolder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.rpc.support; +package cn.hippo4j.rpc.connection; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; @@ -35,16 +35,16 @@ import java.util.concurrent.ConcurrentHashMap; * @since 2.0.0 */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class NettyConnectPoolHolder { +public class ConnectPoolHolder { static int maxConnect = 256; - static Map connectPoolMap = new ConcurrentHashMap<>(); + static Map connectPoolMap = new ConcurrentHashMap<>(); - private static NettyConnectPool initPool(InetSocketAddress address, - long timeout, EventLoopGroup worker, - ChannelPoolHandler handler) { - return new NettyConnectPool(address, maxConnect, timeout, worker, NioSocketChannel.class, handler); + private static SimpleConnectPool initPool(InetSocketAddress address, + long timeout, EventLoopGroup worker, + ChannelPoolHandler handler) { + return new SimpleConnectPool(address, maxConnect, timeout, worker, NioSocketChannel.class, handler); } private static String getKey(InetSocketAddress address) { @@ -58,7 +58,7 @@ public class NettyConnectPoolHolder { * @param address the InetSocketAddress * @param pool This parameter applies only to the connection pool of netty */ - public static void createPool(InetSocketAddress address, NettyConnectPool pool) { + public static void createPool(InetSocketAddress address, SimpleConnectPool pool) { connectPoolMap.put(getKey(address), pool); } @@ -68,7 +68,7 @@ public class NettyConnectPoolHolder { * @param address the InetSocketAddress * @return Map to the connection pool */ - public static NettyConnectPool getPool(InetSocketAddress address) { + public static SimpleConnectPool getPool(InetSocketAddress address) { return connectPoolMap.get(getKey(address)); } @@ -82,13 +82,13 @@ public class NettyConnectPoolHolder { * @param handler the chandler for netty * @return Map to the connection pool */ - public static synchronized NettyConnectPool getPool(InetSocketAddress address, - long timeout, EventLoopGroup worker, - ChannelPoolHandler handler) { + public static synchronized SimpleConnectPool getPool(InetSocketAddress address, + long timeout, EventLoopGroup worker, + ChannelPoolHandler handler) { /* * this cannot use the computeIfAbsent method directly here because put is already used in init. Details refer to https://bugs.openjdk.java.net/browse/JDK-8062841 */ - NettyConnectPool pool = getPool(address); + SimpleConnectPool pool = getPool(address); return pool == null ? initPool(address, timeout, worker, handler) : pool; } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/Connection.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ServerConnection.java similarity index 84% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/Connection.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ServerConnection.java index 5f93bab7..3441c7e2 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/Connection.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/ServerConnection.java @@ -15,28 +15,34 @@ * limitations under the License. */ -package cn.hippo4j.rpc.handler; +package cn.hippo4j.rpc.connection; + +import cn.hippo4j.rpc.discovery.ServerPort; import java.io.Closeable; /** + * This applies to server-side connections + *

* Represents a network request connection and provides IO layer support
*

* This is not a strict and stateless Connection interface, it contains the necessary * operations that should be done in the connection. It is more like integrating the - * connection and the connection channel together, so creating {@link Connection} is + * connection and the connection channel together, so creating {@link ServerConnection} is * very resource intensive, for which caching is recommended * * @since 2.0.0 */ -public interface Connection extends Closeable { +public interface ServerConnection extends Closeable { + + /** + * Bind ports and process them + */ + void bind(ServerPort port); /** * Gets the state of the connection, which is interpreted differently by different programs
*

- * Client: Active connection indicates that a connection is being maintained with the server. - * Inactive connection indicates that no connection is being established with the server
- *

* Server: The active connection indicates that the server has been started, is receiving ports, * and can obtain requests at any time. The inactive connection indicates that the server has been * shut down and the ports have been released diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleClientConnection.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleClientConnection.java new file mode 100644 index 00000000..dc7d9e77 --- /dev/null +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleClientConnection.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.connection; + +import cn.hippo4j.rpc.exception.ConnectionException; +import cn.hippo4j.rpc.exception.TimeOutException; +import cn.hippo4j.rpc.model.Request; +import cn.hippo4j.rpc.model.Response; +import cn.hippo4j.rpc.support.ResultHolder; +import io.netty.channel.Channel; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.pool.ChannelPoolHandler; +import lombok.extern.slf4j.Slf4j; + +import java.net.InetSocketAddress; +import java.util.concurrent.locks.LockSupport; + +/** + * Client implemented using netty + * + * @since 2.0.0 + */ +@Slf4j +public class SimpleClientConnection implements ClientConnection { + + InetSocketAddress address; + /** + * Obtain the connection timeout period. The default value is 30s + */ + long timeout = 30000L; + EventLoopGroup worker = new NioEventLoopGroup(); + SimpleConnectPool connectionPool; + static final String TIME_OUT_MSG = "Timeout waiting for server-side response"; + + public SimpleClientConnection(InetSocketAddress address, + ChannelPoolHandler handler) { + this.address = address; + this.connectionPool = ConnectPoolHolder.getPool(address, timeout, worker, handler); + } + + @Override + public R connect(Request request) { + Channel channel = connectionPool.acquire(timeout); + try { + channel.writeAndFlush(request); + return wait(request.getRID()); + } finally { + connectionPool.release(channel); + } + } + + /** + * wait the Response + * + * @param requestId RID + * @return Response + */ + @SuppressWarnings("unchecked") + public R wait(String requestId) { + Response response; + if (log.isDebugEnabled()) { + log.debug("Call successful, target address is {}:{}, request key is {}", address.getHostName(), address.getPort(), requestId); + } + // Wait for execution to complete + ResultHolder.putThread(requestId, Thread.currentThread()); + LockSupport.parkNanos(timeout() * 1000000); + response = ResultHolder.get(requestId); + if (response == null) { + throw new TimeOutException(TIME_OUT_MSG); + } + if (response.isErr()) { + throw new ConnectionException(response.getErrMsg()); + } + if (log.isDebugEnabled()) { + log.debug("The response from {}:{} was received successfully with the response key {}.", address.getHostName(), address.getPort(), requestId); + } + return (R) response.getObj(); + } + + @Override + public long timeout() { + return timeout; + } + + @Override + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + @Override + public void close() { + worker.shutdownGracefully(); + connectionPool.close(); + } + +} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyConnectPool.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleConnectPool.java similarity index 83% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyConnectPool.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleConnectPool.java index 9585adc8..18ca6f13 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyConnectPool.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleConnectPool.java @@ -15,8 +15,9 @@ * limitations under the License. */ -package cn.hippo4j.rpc.support; +package cn.hippo4j.rpc.connection; +import cn.hippo4j.rpc.client.ClientSupport; import cn.hippo4j.rpc.exception.ConnectionException; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; @@ -39,7 +40,7 @@ import java.util.concurrent.TimeUnit; * @since 2.0.0 */ @Slf4j -public class NettyConnectPool { +public class SimpleConnectPool { ChannelHealthChecker healthCheck = ChannelHealthChecker.ACTIVE; FixedChannelPool.AcquireTimeoutAction acquireTimeoutAction = FixedChannelPool.AcquireTimeoutAction.NEW; @@ -48,10 +49,10 @@ public class NettyConnectPool { ChannelPool pool; InetSocketAddress address; - public NettyConnectPool(InetSocketAddress address, int maxConnect, - long timeout, EventLoopGroup worker, - Class socketChannelCls, - ChannelPoolHandler handler) { + public SimpleConnectPool(InetSocketAddress address, int maxConnect, + long timeout, EventLoopGroup worker, + Class socketChannelCls, + ChannelPoolHandler handler) { Bootstrap bootstrap = new Bootstrap() .group(worker) .channel(socketChannelCls) @@ -64,7 +65,7 @@ public class NettyConnectPool { if (log.isDebugEnabled()) { log.info("The connection pool is established with the connection target {}:{}", address.getHostName(), address.getPort()); } - NettyConnectPoolHolder.createPool(address, this); + ConnectPoolHolder.createPool(address, this); } public Channel acquire(long timeoutMillis) { @@ -72,7 +73,7 @@ public class NettyConnectPool { Future fch = pool.acquire(); return fch.get(timeoutMillis, TimeUnit.MILLISECONDS); } catch (Exception e) { - NettyClientSupport.closeClient(address); + ClientSupport.closeClient(address); throw new ConnectionException("Failed to get the connection", e); } } @@ -81,7 +82,7 @@ public class NettyConnectPool { try { return pool.acquire(); } catch (Exception e) { - NettyClientSupport.closeClient(address); + ClientSupport.closeClient(address); throw new ConnectionException("Failed to get the connection", e); } } @@ -92,7 +93,7 @@ public class NettyConnectPool { try { pool.release(channel); } catch (Exception e) { - NettyClientSupport.closeClient(address); + ClientSupport.closeClient(address); throw new ConnectionException("Failed to release the connection", e); } }); @@ -101,9 +102,9 @@ public class NettyConnectPool { public void close() { try { pool.close(); - NettyConnectPoolHolder.remove(address); + ConnectPoolHolder.remove(address); } catch (Exception e) { - NettyClientSupport.closeClient(address); + ClientSupport.closeClient(address); throw new ConnectionException("Failed to close the connection pool", e); } } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/NettyServerConnection.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleServerConnection.java similarity index 73% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/NettyServerConnection.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleServerConnection.java index 224163eb..aa8e29ea 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/NettyServerConnection.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/connection/SimpleServerConnection.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package cn.hippo4j.rpc.server; +package cn.hippo4j.rpc.connection; -import cn.hippo4j.common.toolkit.Assert; -import cn.hippo4j.rpc.coder.NettyEncoder; +import cn.hippo4j.rpc.coder.ObjectEncoder; import cn.hippo4j.rpc.discovery.ServerPort; import cn.hippo4j.rpc.exception.ConnectionException; -import cn.hippo4j.rpc.handler.AbstractNettyHandlerManager; +import cn.hippo4j.rpc.handler.AbstractHandlerManager; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; @@ -48,7 +47,7 @@ import java.util.List; * @since 2.0.0 */ @Slf4j -public class NettyServerConnection extends AbstractNettyHandlerManager implements ServerConnection { +public class SimpleServerConnection extends AbstractHandlerManager implements ServerConnection { ServerPort port; EventLoopGroup leader; @@ -56,32 +55,30 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement Class socketChannelCls = NioServerSocketChannel.class; ChannelFuture future; Channel channel; - private final int maxPortNum = 65535; + private static final int MAX_PORT_NUM = 65535; - public NettyServerConnection(EventLoopGroup leader, EventLoopGroup worker, List handlers) { + public SimpleServerConnection(EventLoopGroup leader, EventLoopGroup worker, List handlers) { super(handlers); - Assert.notNull(leader); - Assert.notNull(worker); this.leader = leader; this.worker = worker; } - public NettyServerConnection(EventLoopGroup leader, EventLoopGroup worker, ChannelHandler... handlers) { + public SimpleServerConnection(EventLoopGroup leader, EventLoopGroup worker, ChannelHandler... handlers) { this(leader, worker, (handlers != null ? Arrays.asList(handlers) : Collections.emptyList())); } - public NettyServerConnection(ChannelHandler... handlers) { + public SimpleServerConnection(ChannelHandler... handlers) { this(handlers != null ? Arrays.asList(handlers) : Collections.emptyList()); } - public NettyServerConnection(List handlers) { + public SimpleServerConnection(List handlers) { this(new NioEventLoopGroup(), new NioEventLoopGroup(), handlers); } @Override public void bind(ServerPort port) { int serverPort = port.getPort(); - if (serverPort < 0 || serverPort > maxPortNum) { + if (serverPort < 0 || serverPort > MAX_PORT_NUM) { throw new ConnectionException("The port number " + serverPort + " is outside 0~65535, which is not a legal port number"); } ServerBootstrap server = new ServerBootstrap(); @@ -93,7 +90,7 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement @Override protected void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast(new NettyEncoder()); + pipeline.addLast(new ObjectEncoder()); pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null))); handlerEntities.stream() .sorted() @@ -106,18 +103,12 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement }); } }); - try { - this.future = server.bind(serverPort).sync(); - this.channel = this.future.channel(); - if (log.isDebugEnabled()) { - log.debug("The server is started and can receive requests. The listening port is {}", serverPort); - } - this.port = port; - this.future.channel().closeFuture().sync(); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - throw new ConnectionException("Listening port failed, Please check whether the port is occupied", ex); + this.future = server.bind(serverPort); + this.channel = this.future.channel(); + if (log.isDebugEnabled()) { + log.debug("The server is started and can receive requests. The listening port is {}", serverPort); } + this.port = port; } @Override @@ -143,13 +134,13 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement } @Override - public NettyServerConnection addLast(String name, ChannelHandler handler) { + public SimpleServerConnection addLast(String name, ChannelHandler handler) { super.addLast(name, handler); return this; } @Override - public NettyServerConnection addFirst(String name, ChannelHandler handler) { + public SimpleServerConnection addFirst(String name, ChannelHandler handler) { super.addFirst(name, handler); return this; } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/ClassRegistry.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/ClassRegistry.java deleted file mode 100644 index 227f19e1..00000000 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/ClassRegistry.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * the registration center for Client and Server - * - * @since 2.0.0 - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ClassRegistry { - - private static final Map> SERVER_REGISTER = new ConcurrentHashMap<>(); - - /** - * get a Obj in Registry center
- * - * @param s key - * @return t element - */ - public static Class get(String s) { - return SERVER_REGISTER.get(s); - } - - /** - * add the element to Registry Table
- * if the key already exists, failure, and return before the value of the key.
- * if success return the element - * - * @param s key - * @param cls element - * @return final mapped value - */ - public static Class set(String s, Class cls) { - return SERVER_REGISTER.putIfAbsent(s, cls); - } - - /** - * add the element to Registry Table
- * if the key already exists, failure, replace it - * - * @param s key - * @param cls element - */ - public static Class put(String s, Class cls) { - return SERVER_REGISTER.put(s, cls); - } - - /** - * clear - */ - public static void clear() { - SERVER_REGISTER.clear(); - } -} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/DefaultInstance.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/DefaultInstance.java deleted file mode 100644 index 0a45d78f..00000000 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/DefaultInstance.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -import cn.hippo4j.common.toolkit.ReflectUtil; - -import java.util.Iterator; -import java.util.ServiceLoader; - -/** - * You simply create an instance of a class based on its name and specific type. - * Load through the ServiceLoader first. If the load fails, load directly through the instantiation. - * If it is an interface, throw an exception. This is not elegant implementation - * - * @since 2.0.0 - */ -public class DefaultInstance implements Instance { - - @Override - public Object getInstance(Class cls) { - ServiceLoader load = ServiceLoader.load(cls); - Iterator iterator = load.iterator(); - if (iterator.hasNext()) { - return iterator.next(); - } - return ReflectUtil.createInstance(cls); - } - - @Override - public Object getInstance(String name) { - try { - Class cls = Class.forName(name); - return getInstance(cls); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } -} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/HandlerNotFoundException.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/HandlerNotFoundException.java new file mode 100644 index 00000000..5bc480e8 --- /dev/null +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/HandlerNotFoundException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.exception; + +/** + * HandlerNotFoundException occurs when no executable handler can be found + * + * @since 2.0.0 + */ +public class HandlerNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 8247610319171014183L; + + public HandlerNotFoundException() { + super(); + } + + public HandlerNotFoundException(String message) { + super(message); + } + + public HandlerNotFoundException(Throwable e) { + super(e.getMessage(), e); + } + + public HandlerNotFoundException(String message, Throwable throwable) { + super(message, throwable); + } + + public HandlerNotFoundException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) { + super(message, throwable, enableSuppression, writableStackTrace); + } + +} \ No newline at end of file diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/Instance.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/OperationException.java similarity index 53% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/Instance.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/OperationException.java index 8d1c92c3..8512777b 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/Instance.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/exception/OperationException.java @@ -15,30 +15,35 @@ * limitations under the License. */ -package cn.hippo4j.rpc.discovery; +package cn.hippo4j.rpc.exception; /** - * Instance interface to get an instance + * a generic operational exception * * @since 2.0.0 */ -public interface Instance { - - /** - * get a instance - * - * @param cls Class object - * @return Information about instances created or found - */ - Object getInstance(Class cls); - - /** - * Gets an instance of a class with a recognizable identity, - * which can be the fully qualified name of class. It can also be a unique name in a container - * - * @param name Identifying name - * @return Information about instances created or found - */ - Object getInstance(String name); +public class OperationException extends RuntimeException { + + private static final long serialVersionUID = 8247610319171014183L; + + public OperationException() { + super(); + } + + public OperationException(String message) { + super(message); + } + + public OperationException(Throwable e) { + super(e.getMessage(), e); + } + + public OperationException(String message, Throwable throwable) { + super(message, throwable); + } + + public OperationException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) { + super(message, throwable, enableSuppression, writableStackTrace); + } } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractNettyHandlerManager.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractHandlerManager.java similarity index 79% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractNettyHandlerManager.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractHandlerManager.java index 85f7289d..1b50900a 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractNettyHandlerManager.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/AbstractHandlerManager.java @@ -17,7 +17,6 @@ package cn.hippo4j.rpc.handler; -import cn.hippo4j.common.toolkit.Assert; import io.netty.channel.ChannelHandler; import java.util.Arrays; @@ -33,7 +32,7 @@ import java.util.stream.Collectors; * * @since 2.0.0 */ -public abstract class AbstractNettyHandlerManager implements HandlerManager { +public abstract class AbstractHandlerManager implements HandlerManager { protected final List> handlerEntities; @@ -41,19 +40,18 @@ public abstract class AbstractNettyHandlerManager implements HandlerManager handlerEntities) { - Assert.notNull(handlerEntities); + protected AbstractHandlerManager(List handlerEntities) { this.handlerEntities = handlerEntities.stream() .filter(Objects::nonNull) .map(c -> getHandlerEntity(lastIndex.getAndIncrement(), c, null)) .collect(Collectors.toList()); } - protected AbstractNettyHandlerManager(ChannelHandler... handlerEntities) { + protected AbstractHandlerManager(ChannelHandler... handlerEntities) { this(handlerEntities != null ? Arrays.asList(handlerEntities) : Collections.emptyList()); } - protected AbstractNettyHandlerManager() { + protected AbstractHandlerManager() { this.handlerEntities = new LinkedList<>(); } @@ -69,8 +67,7 @@ public abstract class AbstractNettyHandlerManager implements HandlerManager { - throw new ConnectionException(cause); + if (log.isWarnEnabled()) { + log.warn(cause.getMessage()); + } }); } @@ -59,8 +61,8 @@ public abstract class AbstractNettyTakeHandler extends ChannelInboundHandlerAdap */ @Override public void handler(Response response) { - ResultHolder.put(response.getKey(), response); - ResultHolder.wake(response.getKey()); + ResultHolder.put(response.getRID(), response); + ResultHolder.wake(response.getRID()); } } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyClientPoolHandler.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ClientPoolHandler.java similarity index 83% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyClientPoolHandler.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ClientPoolHandler.java index 26a195d9..5a61c8da 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyClientPoolHandler.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ClientPoolHandler.java @@ -17,7 +17,7 @@ package cn.hippo4j.rpc.handler; -import cn.hippo4j.rpc.coder.NettyEncoder; +import cn.hippo4j.rpc.coder.ObjectEncoder; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; @@ -36,28 +36,28 @@ import java.util.List; * @since 2.0.0 */ @Slf4j -public class NettyClientPoolHandler extends AbstractNettyHandlerManager implements ChannelPoolHandler { +public class ClientPoolHandler extends AbstractHandlerManager implements ChannelPoolHandler { - public NettyClientPoolHandler(List handlers) { + public ClientPoolHandler(List handlers) { super(handlers); } - public NettyClientPoolHandler(ChannelHandler... handlers) { + public ClientPoolHandler(ChannelHandler... handlers) { super(handlers); } - public NettyClientPoolHandler() { + public ClientPoolHandler() { super(); } @Override - public NettyClientPoolHandler addLast(String name, ChannelHandler handler) { + public ClientPoolHandler addLast(String name, ChannelHandler handler) { super.addLast(name, handler); return this; } @Override - public NettyClientPoolHandler addFirst(String name, ChannelHandler handler) { + public ClientPoolHandler addFirst(String name, ChannelHandler handler) { super.addFirst(name, handler); return this; } @@ -81,7 +81,7 @@ public class NettyClientPoolHandler extends AbstractNettyHandlerManager implemen channel.config() .setTcpNoDelay(false); ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast(new NettyEncoder()); + pipeline.addLast(new ObjectEncoder()); pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null))); this.handlerEntities.stream() .sorted() diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyClientTakeHandler.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ClientTakeHandler.java similarity index 74% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyClientTakeHandler.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ClientTakeHandler.java index 02d7c00d..3266bcc2 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyClientTakeHandler.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ClientTakeHandler.java @@ -17,6 +17,7 @@ package cn.hippo4j.rpc.handler; +import cn.hippo4j.rpc.exception.ConnectionException; import cn.hippo4j.rpc.model.Response; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -27,17 +28,20 @@ import io.netty.channel.ChannelHandlerContext; * @since 2.0.0 */ @ChannelHandler.Sharable -public class NettyClientTakeHandler extends AbstractNettyTakeHandler implements ConnectHandler { +public class ClientTakeHandler extends AbstractTakeHandler implements ConnectHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { try { - Response response = (Response) msg; - handler(response); - ctx.flush(); + if (msg instanceof Response) { + Response response = (Response) msg; + handler(response); + ctx.flush(); + } else { + ctx.fireChannelRead(msg); + } } catch (Exception e) { - ctx.close(); - throw e; + throw new ConnectionException(e); } } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/SpringContextInstance.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ErrorClientHandler.java similarity index 56% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/SpringContextInstance.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ErrorClientHandler.java index 324c0705..7eef3402 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/discovery/SpringContextInstance.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ErrorClientHandler.java @@ -15,25 +15,29 @@ * limitations under the License. */ -package cn.hippo4j.rpc.discovery; +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.exception.HandlerNotFoundException; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; /** - * Adapter Spring, The requested object is managed by spring + * The final handler, which returned an exception because no usable handler could be found * * @since 2.0.0 */ -public class SpringContextInstance implements Instance { +@ChannelHandler.Sharable +public class ErrorClientHandler extends AbstractTakeHandler implements ConnectHandler { - @Override - public Object getInstance(Class cls) { - // return ApplicationContextHolder.getBean(cls); - return null; - } + private static final String ERR_MSG = "no handler found that matches the request"; @Override - public Object getInstance(String name) { - // return ApplicationContextHolder.getInstance().getBean(name); - return null; + public void channelRead(ChannelHandlerContext ctx, Object msg) { + try { + throw new HandlerNotFoundException(ERR_MSG); + } finally { + ctx.close(); + } } -} +} \ No newline at end of file diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyServerTakeHandler.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ErrorServerHandler.java similarity index 50% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyServerTakeHandler.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ErrorServerHandler.java index c83846c7..d3d4828d 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/NettyServerTakeHandler.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ErrorServerHandler.java @@ -17,56 +17,33 @@ package cn.hippo4j.rpc.handler; -import cn.hippo4j.common.toolkit.Assert; -import cn.hippo4j.common.toolkit.ReflectUtil; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.Instance; +import cn.hippo4j.rpc.exception.HandlerNotFoundException; +import cn.hippo4j.rpc.model.DefaultRequest; import cn.hippo4j.rpc.model.DefaultResponse; import cn.hippo4j.rpc.model.Request; import cn.hippo4j.rpc.model.Response; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import java.lang.reflect.Method; - /** - * netty adaptation layer + * The final handler, which returned an exception because no usable handler could be found * * @since 2.0.0 */ @ChannelHandler.Sharable -public class NettyServerTakeHandler extends AbstractNettyTakeHandler implements ConnectHandler { - - Instance instance; +public class ErrorServerHandler extends AbstractTakeHandler { - public NettyServerTakeHandler(Instance instance) { - this.instance = instance; - } + private static final String ERR_MSG = "no handler found that matches the request"; @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { - if (!(msg instanceof Request)) { - return; + HandlerNotFoundException exception = new HandlerNotFoundException(ERR_MSG); + if (!(msg instanceof DefaultRequest)) { + ctx.close(); + throw exception; } Request request = (Request) msg; - Response response = sendHandler(request); + Response response = new DefaultResponse(request.getRID(), ERR_MSG); ctx.writeAndFlush(response); } - - @Override - public Response sendHandler(Request request) { - Response response; - try { - Class cls = ClassRegistry.get(request.getClassName()); - Method method = ReflectUtil.getMethodByName(cls, request.getMethodName(), request.getParameterTypes()); - Assert.notNull(method); - Object invoke = ReflectUtil.invoke(instance.getInstance(cls), method, request.getParameters()); - response = new DefaultResponse(request.getKey(), invoke.getClass(), invoke); - return response; - } catch (Exception e) { - response = new DefaultResponse(request.getKey(), e, e.getMessage()); - return response; - } - } - } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/HandlerManager.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/HandlerManager.java index 0fe0cc38..49b722c5 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/HandlerManager.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/HandlerManager.java @@ -17,6 +17,7 @@ package cn.hippo4j.rpc.handler; +import cn.hippo4j.rpc.exception.OperationException; import io.netty.channel.ChannelHandler; import lombok.AllArgsConstructor; import lombok.Getter; @@ -65,7 +66,7 @@ public interface HandlerManager { boolean b = cls.isAnnotationPresent(ChannelHandler.Sharable.class) || HandlerManager.class.isAssignableFrom(cls); if (!b) { - throw new RuntimeException("Join the execution of the handler must add io.netty.channel.ChannelHandler." + throw new OperationException("Join the execution of the handler must add io.netty.channel.ChannelHandler." + "Sharable annotations, Please for the handler class " + cls.getName() + " add io.netty.channel." + "ChannelHandler.Sharable annotation"); } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerBareTakeHandler.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerBareTakeHandler.java new file mode 100644 index 00000000..39939cee --- /dev/null +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerBareTakeHandler.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.exception.HandlerNotFoundException; +import cn.hippo4j.rpc.model.DefaultResponse; +import cn.hippo4j.rpc.model.Request; +import cn.hippo4j.rpc.model.Response; +import io.netty.channel.ChannelHandler; +import lombok.RequiredArgsConstructor; + +import java.util.function.Supplier; + +/** + * This is a processor that does not support parameters but can get the return value.
+ * Even if the parameters passed by the user will not be recognized, it will even become an error + * + * @since 2.0.0 + */ +@RequiredArgsConstructor +@ChannelHandler.Sharable +public class ServerBareTakeHandler extends ServerHandler { + + final String name; + final Supplier fun; + + @Override + String getName() { + return name; + } + + @Override + public Response sendHandler(Request request) { + try { + Object[] parameters = request.getParameters(); + if (parameters.length != 0) { + throw new HandlerNotFoundException("no handler found that matches the pair " + name + " and function"); + } + T t = fun.get(); + return new DefaultResponse(request.getRID(), t); + } catch (Exception e) { + return new DefaultResponse(request.getRID(), e.getMessage()); + } + } + +} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerBiTakeHandler.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerBiTakeHandler.java new file mode 100644 index 00000000..8bae327c --- /dev/null +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerBiTakeHandler.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.exception.HandlerNotFoundException; +import cn.hippo4j.rpc.model.DefaultRequest; +import cn.hippo4j.rpc.model.DefaultResponse; +import cn.hippo4j.rpc.model.Request; +import cn.hippo4j.rpc.model.Response; +import io.netty.channel.ChannelHandler; +import lombok.RequiredArgsConstructor; + +import java.util.function.BiFunction; + +/** + * netty adaptation layer about {@link DefaultRequest}

+ * Parse the parameters in the request to execute the corresponding method.
+ * This is a relatively flexible processor at present, but there are still great defects.
+ *
For example:
+ *

    + *
  • This handler only supports requests with two parameters, it will not work if the number of parameters does not match
  • + *
  • If you want to pass multiple parameters please wrap them, or customize the processor
  • + *
  • This processor does not consider whether the types match when parsing parameters, and an error occurs if the conversion fails
  • + *
+ * + * @since 2.0.0 + */ +@ChannelHandler.Sharable +@RequiredArgsConstructor +public class ServerBiTakeHandler extends ServerHandler { + + final String name; + + final BiFunction fun; + + @Override + String getName() { + return name; + } + + @Override + @SuppressWarnings("unchecked") + public Response sendHandler(Request request) { + try { + Object[] parameters = request.getParameters(); + if (parameters.length != 2) { + throw new HandlerNotFoundException("no handler found that matches the pair " + name + " and function"); + } + T t = (T) parameters[0]; + P p = (P) parameters[1]; + K r = fun.apply(t, p); + return new DefaultResponse(request.getRID(), r); + } catch (Exception e) { + return new DefaultResponse(request.getRID(), e.getMessage()); + } + } + +} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerHandler.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerHandler.java new file mode 100644 index 00000000..f0372c90 --- /dev/null +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerHandler.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.model.DefaultRequest; +import cn.hippo4j.rpc.model.Request; +import cn.hippo4j.rpc.model.Response; +import io.netty.channel.ChannelHandlerContext; + +import java.util.Objects; + +/** + * The handler located on the server side provides unified operations for the server side + * + * @since 2.0.0 + */ +abstract class ServerHandler extends AbstractTakeHandler { + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) { + if (!(msg instanceof DefaultRequest)) { + ctx.fireChannelRead(msg); + return; + } + Request request = (Request) msg; + if (!Objects.equals(request.getKey(), getName())) { + ctx.fireChannelRead(msg); + return; + } + Response response = sendHandler(request); + ctx.writeAndFlush(response); + } + + /** + * Get the name of the current handler + * + * @return name + */ + abstract String getName(); +} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerTakeHandler.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerTakeHandler.java new file mode 100644 index 00000000..9aaa60e0 --- /dev/null +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/handler/ServerTakeHandler.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.exception.HandlerNotFoundException; +import cn.hippo4j.rpc.model.DefaultRequest; +import cn.hippo4j.rpc.model.DefaultResponse; +import cn.hippo4j.rpc.model.Request; +import cn.hippo4j.rpc.model.Response; +import io.netty.channel.ChannelHandler; +import lombok.RequiredArgsConstructor; + +import java.util.function.Function; + +/** + * netty adaptation layer about {@link DefaultRequest}

+ * Parse the parameters in the request to execute the corresponding method.
+ * This is a relatively flexible processor at present, but there are still great defects.
+ *
For example:
+ *
    + *
  • This handler only supports requests with one parameters, it will not work if the number of parameters does not match
  • + *
  • If you want to pass multiple parameters please wrap them, or customize the processor
  • + *
  • This processor does not consider whether the types match when parsing parameters, and an error occurs if the conversion fails
  • + *
+ * + * @since 2.0.0 + */ +@ChannelHandler.Sharable +@RequiredArgsConstructor +public class ServerTakeHandler extends ServerHandler { + + final String name; + final Function fun; + + @Override + String getName() { + return name; + } + + @Override + @SuppressWarnings("unchecked") + public Response sendHandler(Request request) { + try { + Object[] parameters = request.getParameters(); + if (parameters.length != 1) { + throw new HandlerNotFoundException("no handler found that matches the pair " + name + " and function"); + } + T t = (T) parameters[0]; + R r = fun.apply(t); + return new DefaultResponse(request.getRID(), r); + } catch (Exception e) { + return new DefaultResponse(request.getRID(), e.getMessage()); + } + } + +} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultRequest.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultRequest.java index d615e2ea..5dff2ea1 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultRequest.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultRequest.java @@ -30,38 +30,30 @@ import java.util.Objects; */ public final class DefaultRequest implements Request { + String RID; String key; - String className; - String methodName; - Class[] parameterTypes; + int length; transient Object[] parameters; - public DefaultRequest(String key, String className, String methodName, Class[] parameterTypes, Object[] parameters) { + public DefaultRequest(String RID, String key, Object[] parameters) { + this.RID = RID; this.key = key; - this.className = className; - this.methodName = methodName; - this.parameterTypes = parameterTypes; this.parameters = parameters; + this.length = parameters.length; } - @Override - public String getKey() { - return key; - } - - @Override - public String getClassName() { - return className; + public DefaultRequest(String RID, String key) { + this(RID, key, new Object[]{}); } @Override - public String getMethodName() { - return methodName; + public String getRID() { + return RID; } @Override - public Class[] getParameterTypes() { - return parameterTypes; + public String getKey() { + return key; } @Override @@ -78,14 +70,12 @@ public final class DefaultRequest implements Request { return false; } DefaultRequest that = (DefaultRequest) o; - return Objects.equals(key, that.key) - && Objects.equals(className, that.className) - && Objects.equals(methodName, that.methodName); + return Objects.equals(key, that.key) && Objects.equals(RID, that.RID); } @Override public int hashCode() { - return Objects.hash(key, className, methodName); + return Objects.hash(key, RID); } /** @@ -111,11 +101,7 @@ public final class DefaultRequest implements Request { */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); - if (parameterTypes == null) { - return; - } // Deserialization parameters - int length = parameterTypes.length; Object[] a = new Object[length]; for (int i = 0; i < length; i++) { a[i] = s.readObject(); diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultResponse.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultResponse.java index 0ba5e799..995db662 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultResponse.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/DefaultResponse.java @@ -30,36 +30,27 @@ import java.util.Objects; */ public class DefaultResponse implements Response { - String key; - Class cls; + String RID; transient Object obj; - Throwable throwable; String errMsg; - public DefaultResponse(String key, Class cls, Object obj, Throwable throwable, String errMsg) { - this.key = key; - this.cls = cls; + public DefaultResponse(String RID, Object obj, String errMsg) { + this.RID = RID; this.obj = obj; - this.throwable = throwable; this.errMsg = errMsg; } - public DefaultResponse(String key, Throwable throwable, String errMsg) { - this(key, null, null, throwable, errMsg); + public DefaultResponse(String RID, String errMsg) { + this(RID, null, errMsg); } - public DefaultResponse(String key, Class cls, Object obj) { - this(key, cls, obj, null, null); + public DefaultResponse(String RID, Object obj) { + this(RID, obj, null); } @Override - public String getKey() { - return key; - } - - @Override - public Class getCls() { - return cls; + public String getRID() { + return RID; } @Override @@ -67,11 +58,6 @@ public class DefaultResponse implements Response { return obj; } - @Override - public Throwable getThrowable() { - return throwable; - } - @Override public String getErrMsg() { return errMsg; @@ -79,7 +65,7 @@ public class DefaultResponse implements Response { @Override public boolean isErr() { - return throwable != null || errMsg != null; + return errMsg != null; } @Override @@ -91,12 +77,12 @@ public class DefaultResponse implements Response { return false; } DefaultResponse that = (DefaultResponse) o; - return Objects.equals(key, that.key) && Objects.equals(cls, that.cls); + return Objects.equals(RID, that.RID); } @Override public int hashCode() { - return Objects.hash(key, cls); + return Objects.hash(RID); } /** diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Request.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Request.java index 83d4feae..ee972c74 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Request.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Request.java @@ -27,24 +27,14 @@ import java.io.Serializable; public interface Request extends Serializable { /** - * The unique identity of the current request - */ - String getKey(); - - /** - * The Class name of the current request + * the request id, Used to specify an executable handler */ - String getClassName(); + String getRID(); /** - * The Method name of the current request - */ - String getMethodName(); - - /** - * The parameter type of the current request + * The unique identity of the current request */ - Class[] getParameterTypes(); + String getKey(); /** * The parameters of the current request diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Response.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Response.java index cd7ada9c..aa7a5e33 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Response.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/model/Response.java @@ -29,23 +29,13 @@ public interface Response extends Serializable { /** * The unique identity of the current Response */ - String getKey(); - - /** - * The class of the current Response, The target of deserialization - */ - Class getCls(); + String getRID(); /** * The results of this request can be obtained, The source of deserialization */ Object getObj(); - /** - * The Throwable of the current Response - */ - Throwable getThrowable(); - /** * the error message */ diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/RPCServer.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/RPCServer.java index 1136937e..888fede1 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/RPCServer.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/RPCServer.java @@ -17,7 +17,7 @@ package cn.hippo4j.rpc.server; -import cn.hippo4j.common.toolkit.ThreadUtil; +import cn.hippo4j.rpc.connection.ServerConnection; import cn.hippo4j.rpc.discovery.ServerPort; import java.io.IOException; @@ -36,10 +36,7 @@ public class RPCServer implements Server { public RPCServer(ServerConnection serverConnection, ServerPort port) { this.port = port; this.serverConnection = serverConnection; - this.thread = ThreadUtil.newThread( - () -> serverConnection.bind(port), - "hippo4j-rpc-" + port.getPort(), - false); + this.thread = new Thread(() -> serverConnection.bind(port), "hippo4j-rpc-" + port.getPort()); } /** @@ -61,7 +58,7 @@ public class RPCServer implements Server { */ @Override public void close() throws IOException { - thread = null; + thread.interrupt(); serverConnection.close(); } } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyServerSupport.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/ServerSupport.java similarity index 55% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyServerSupport.java rename to threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/ServerSupport.java index c09f25f2..ba0c0c14 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyServerSupport.java +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/ServerSupport.java @@ -15,22 +15,17 @@ * limitations under the License. */ -package cn.hippo4j.rpc.support; +package cn.hippo4j.rpc.server; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.DefaultInstance; +import cn.hippo4j.rpc.client.ClientSupport; import cn.hippo4j.rpc.discovery.ServerPort; +import cn.hippo4j.rpc.handler.ErrorServerHandler; import cn.hippo4j.rpc.handler.HandlerManager; -import cn.hippo4j.rpc.handler.NettyServerTakeHandler; -import cn.hippo4j.rpc.server.NettyServerConnection; -import cn.hippo4j.rpc.server.RPCServer; -import cn.hippo4j.rpc.server.Server; +import cn.hippo4j.rpc.connection.ServerConnection; +import cn.hippo4j.rpc.connection.SimpleServerConnection; import io.netty.channel.ChannelHandler; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; /** * This is a server-side build class that allows you to quickly prepare data on the server side and start the server side.
@@ -38,17 +33,11 @@ import java.util.List; * The composite pattern is adopted, which means that it is itself a server-side implementation, so it is stateless. * * @see RPCServer - * @see NettyServerConnection - * @see NettyClientSupport + * @see ServerConnection + * @see ClientSupport * @since 2.0.0 */ -public class NettyServerSupport implements Server { - - /** - * The interface that the server side can call, - * All the methods in the interface are brokered during initialization - */ - protected List> classes; +public class ServerSupport implements Server { /** * Extract the port number of the web container, @@ -63,20 +52,11 @@ public class NettyServerSupport implements Server { protected Server server; - public NettyServerSupport(ServerPort serverPort, Class... classes) { - this(serverPort, new NettyServerConnection(), classes); - } - - public NettyServerSupport(ServerPort serverPort, List> classes) { - this(serverPort, new NettyServerConnection(), classes); - } - - public NettyServerSupport(ServerPort serverPort, HandlerManager handlerManager, Class... classes) { - this(serverPort, handlerManager, classes != null ? Arrays.asList(classes) : Collections.emptyList()); + public ServerSupport(ServerPort serverPort) { + this(serverPort, new SimpleServerConnection()); } - public NettyServerSupport(ServerPort serverPort, HandlerManager handlerManager, List> classes) { - this.classes = classes; + public ServerSupport(ServerPort serverPort, HandlerManager handlerManager) { this.serverPort = serverPort; this.handlerManager = handlerManager; initServer(); @@ -88,16 +68,11 @@ public class NettyServerSupport implements Server { * If no processor is available, a default processor is provided */ protected void initServer() { - // Register the interface that can be invoked - classes.stream().filter(Class::isInterface) - .forEach(cls -> ClassRegistry.put(cls.getName(), cls)); - NettyServerConnection connection = (handlerManager instanceof NettyServerConnection) - ? (NettyServerConnection) handlerManager - : new NettyServerConnection(); + SimpleServerConnection connection = (handlerManager instanceof SimpleServerConnection) + ? (SimpleServerConnection) handlerManager + : new SimpleServerConnection(); // Assign a default handler if no handler exists - if (connection.isEmpty()) { - connection.addFirst(null, new NettyServerTakeHandler(new DefaultInstance())); - } + connection.addLast(null, new ErrorServerHandler()); server = new RPCServer(connection, serverPort); } diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/AddressUtil.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/AddressUtil.java new file mode 100644 index 00000000..90fda034 --- /dev/null +++ b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/AddressUtil.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.support; + +import cn.hippo4j.rpc.exception.ConnectionException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.net.InetSocketAddress; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AddressUtil { + + private static final String HTTP = "http://"; + private static final String HTTPS = "https://"; + + /** + * parsing hostname + * + * @param address address + * @return InetAddress + */ + public static InetSocketAddress getInetAddress(String address) { + if (address.startsWith(HTTP)) { + address = address.replaceFirst(HTTP, ""); + } + + if (address.startsWith(HTTPS)) { + address = address.replaceFirst(HTTPS, ""); + } + + String[] addressStr = address.split(":"); + if (addressStr.length < 2) { + throw new ConnectionException("Failed to connect to the server because the IP address is invalid. Procedure"); + } + return InetSocketAddress.createUnresolved(addressStr[0], Integer.parseInt(addressStr[1])); + } + +} diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyProxyCenter.java b/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyProxyCenter.java deleted file mode 100644 index 93214662..00000000 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/support/NettyProxyCenter.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.support; - -import cn.hippo4j.common.toolkit.IdUtil; -import cn.hippo4j.rpc.client.Client; -import cn.hippo4j.rpc.exception.ConnectionException; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.model.DefaultRequest; -import cn.hippo4j.rpc.model.Request; -import cn.hippo4j.rpc.model.Response; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Proxy; -import java.net.InetSocketAddress; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Add a proxy for the request, {@link Proxy} and {@link InvocationHandler} - * - * @since 2.0.0 - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class NettyProxyCenter { - - // cache - static Map map = new ConcurrentHashMap<>(); - - /** - * A proxy object for PRC is obtained through an interface - * - * @param cls The interface type - * @param address address - * @param Object type - * @param handler the pool handler for netty - * @return Proxy objects - */ - @SuppressWarnings("unchecked") - public static T getProxy(Class cls, InetSocketAddress address, NettyClientPoolHandler handler) { - Client client = NettyClientSupport.getClient(address, handler); - String s = address + cls.getName(); - Object o = map.get(s); - if (o != null) { - return (T) o; - } - return createProxy(client, cls, address); - } - - /** - * A proxy object for PRC is obtained through an interface - * - * @param cls The interface type - * @param address address String - * @param Object type - * @return Proxy objects - */ - @SuppressWarnings("unchecked") - public static T getProxy(Class cls, String address) { - String[] addressStr = address.split(":"); - if (addressStr.length < 2) { - throw new ConnectionException("Failed to connect to the server because the IP address is invalid. Procedure"); - } - InetSocketAddress socketAddress = InetSocketAddress.createUnresolved(addressStr[0], Integer.parseInt(addressStr[1])); - String s = socketAddress + cls.getName(); - Object o = map.get(s); - if (o != null) { - return (T) o; - } - Client client = NettyClientSupport.getClient(socketAddress); - return createProxy(client, cls, socketAddress); - } - - /** - * remove proxy object - * - * @param cls the class - * @param address address String - */ - public static void removeProxy(Class cls, String address) { - String[] addressStr = address.split(":"); - if (addressStr.length < 2) { - throw new ConnectionException("Failed to connect to the server because the IP address is invalid. Procedure"); - } - InetSocketAddress socketAddress = InetSocketAddress.createUnresolved(addressStr[0], Integer.parseInt(addressStr[1])); - String s = socketAddress + cls.getName(); - NettyClientSupport.closeClient(socketAddress); - map.remove(s); - } - - @SuppressWarnings("unchecked") - public static T createProxy(Client client, Class cls, InetSocketAddress address) { - boolean b = cls.isInterface(); - if (!b) { - throw new RuntimeException(cls.getName() + "is not a Interface"); - } - String s = address.toString() + cls.getName(); - Object o = map.get(s); - if (o != null) { - return (T) o; - } - T obj = (T) Proxy.newProxyInstance( - cls.getClassLoader(), - new Class[]{cls}, - (proxy, method, args) -> { - String clsName = cls.getName(); - String methodName = method.getName(); - String key = address + clsName + methodName + IdUtil.simpleUUID(); - Class[] parameterTypes = method.getParameterTypes(); - Request request = new DefaultRequest(key, clsName, methodName, parameterTypes, args); - Response response = client.connection(request); - if (response == null) { - return null; - } - if (response.isErr()) { - throw new RuntimeException(response.getErrMsg(), response.getThrowable()); - } - return response.getObj(); - }); - map.put(s, obj); - return obj; - } -} diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/CallManager.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/CallManager.java index 23367936..ac535f4c 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/CallManager.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/CallManager.java @@ -17,7 +17,8 @@ package cn.hippo4j.rpc.client; -import cn.hippo4j.common.toolkit.ThreadUtil; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; public class CallManager { @@ -25,13 +26,17 @@ public class CallManager { return 1; } - public int callTest(Integer a, Integer b) { + public int call(Integer a) { + return a; + } + + public int call(Integer a, Integer b) { return a + b; } public int callTestTimeout() { // thread sleep for 10 seconds - ThreadUtil.sleep(10000); + LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10L)); return 1; } diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/ClientSupportTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/ClientSupportTest.java new file mode 100644 index 00000000..afa523c5 --- /dev/null +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/ClientSupportTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.client; + +import cn.hippo4j.rpc.connection.ClientConnection; +import cn.hippo4j.rpc.connection.ServerConnection; +import cn.hippo4j.rpc.connection.SimpleClientConnection; +import cn.hippo4j.rpc.connection.SimpleServerConnection; +import cn.hippo4j.rpc.handler.ServerBareTakeHandler; +import cn.hippo4j.rpc.handler.ServerBiTakeHandler; +import cn.hippo4j.rpc.discovery.ServerPort; +import cn.hippo4j.rpc.handler.ClientPoolHandler; +import cn.hippo4j.rpc.handler.ClientTakeHandler; +import cn.hippo4j.rpc.handler.ServerTakeHandler; +import cn.hippo4j.rpc.server.RPCServer; +import io.netty.channel.pool.ChannelPoolHandler; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; + +public class ClientSupportTest { + + static ServerPort port = new TestServerPort(); + static final String addressStr = "localhost"; + + static final String take = "serverTake"; + static final String biTake = "biTake"; + static final String bareTake = "bareTake"; + static final String timeout = "timeout"; + static RPCServer rpcServer; + + @BeforeClass + public static void startServer() { + CallManager manager = new CallManager(); + ServerTakeHandler takeHandler = new ServerTakeHandler<>(biTake, manager::call); + ServerBiTakeHandler biTakeHandler = new ServerBiTakeHandler<>(take, manager::call); + ServerBareTakeHandler bareTakeHandler = new ServerBareTakeHandler<>(bareTake, manager::call); + ServerBareTakeHandler timeoutHandler = new ServerBareTakeHandler<>(timeout, manager::callTestTimeout); + ServerConnection connection = new SimpleServerConnection(takeHandler, bareTakeHandler, biTakeHandler, timeoutHandler); + rpcServer = new RPCServer(connection, port); + rpcServer.bind(); + while (!rpcServer.isActive()) { + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1L)); + } + } + + @AfterClass + public static void stopServer() throws IOException { + if (rpcServer.isActive()) { + rpcServer.close(); + } + } + + @Test + public void closeTest() throws IOException { + InetSocketAddress address = InetSocketAddress.createUnresolved(addressStr, port.getPort()); + ChannelPoolHandler channelPoolHandler = new ClientPoolHandler(new ClientTakeHandler()); + ClientConnection clientConnection = new SimpleClientConnection(address, channelPoolHandler); + RPCClient rpcClient = new RPCClient(clientConnection); + + ClientSupport.closeClient(new InetSocketAddress(addressStr, port.getPort())); + rpcClient.close(); + } + + static class TestServerPort implements ServerPort { + + int port = RandomPort.getSafeRandomPort(); + + @Override + public int getPort() { + return port; + } + } + +} diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/RPCClientTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/RPCClientTest.java deleted file mode 100644 index f10cb0eb..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/client/RPCClientTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.client; - -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.DefaultInstance; -import cn.hippo4j.rpc.discovery.Instance; -import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.handler.NettyClientTakeHandler; -import cn.hippo4j.rpc.handler.NettyServerTakeHandler; -import cn.hippo4j.rpc.model.DefaultRequest; -import cn.hippo4j.rpc.model.Request; -import cn.hippo4j.rpc.model.Response; -import cn.hippo4j.rpc.server.NettyServerConnection; -import cn.hippo4j.rpc.server.RPCServer; -import cn.hippo4j.rpc.server.ServerConnection; -import io.netty.channel.pool.ChannelPoolHandler; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; - -public class RPCClientTest { - - String host = "localhost"; - ServerPort port = new TestServerPort(); - ServerPort portTest = new TestPortServerPort(); - - /** - * This test case can be overridden under the handler and coder packages - */ - @Test - public void connection() throws IOException { - Class cls = CallManager.class; - String className = cls.getName(); - ClassRegistry.put(className, cls); - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, portTest); - rpcServer.bind(); - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved(host, portTest.getPort()); - ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - NettyClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - RPCClient rpcClient = new RPCClient(clientConnection); - Class[] classes = new Class[2]; - classes[0] = Integer.class; - classes[1] = Integer.class; - Object[] objects = new Object[2]; - objects[0] = 1; - objects[1] = 2; - Request request = new DefaultRequest("127.0.0.18889", className, "callTest", classes, objects); - Response response = rpcClient.connection(request); - boolean active = rpcClient.isActive(); - Assert.assertTrue(active); - Assert.assertEquals(response.getObj(), 3); - rpcClient.close(); - rpcServer.close(); - } - - @Test - public void connectionTest() throws IOException { - Class cls = CallManager.class; - String className = cls.getName(); - ClassRegistry.put(className, cls); - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, port); - rpcServer.bind(); - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - RPCClient rpcClient = new RPCClient(clientConnection); - Request request = new DefaultRequest("127.0.0.18888", className, "call", null, null); - for (int i = 0; i < 50; i++) { - Response response = rpcClient.connection(request); - boolean active = rpcClient.isActive(); - Assert.assertTrue(active); - Assert.assertEquals(response.getObj(), 1); - } - rpcClient.close(); - rpcServer.close(); - } - - @Test(expected = Exception.class) - public void responseNullExceptionTest() throws IOException { - Class cls = CallManager.class; - String className = cls.getName(); - ClassRegistry.put(className, cls); - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, port); - rpcServer.bind(); - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - clientConnection.setTimeout(300L); - try (RPCClient rpcClient = new RPCClient(clientConnection)) { - Request request = new DefaultRequest("127.0.0.18888", className, "callTestTimeout", null, null); - Response response = rpcClient.connection(request); - Assert.assertNotNull(response.getErrMsg()); - Assert.assertNotNull(response.getThrowable()); - } catch (IOException e) { - // no something - } finally { - rpcServer.close(); - } - } - - static class TestServerPort implements ServerPort { - - int port = RandomPort.getSafeRandomPort(); - - @Override - public int getPort() { - return port; - } - } - - static class TestPortServerPort implements ServerPort { - - int port = RandomPort.getSafeRandomPort(); - - @Override - public int getPort() { - return port; - } - } -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/ClassRegistryTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/ClassRegistryTest.java deleted file mode 100644 index e55c1a22..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/ClassRegistryTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -import org.junit.Assert; -import org.junit.Test; - -public class ClassRegistryTest { - - @Test - public void get() { - String getStr = "GetModel"; - Class cls = ClassRegistry.get(getStr); - Assert.assertNull(cls); - ClassRegistry.put(getStr, GetModel.class); - Class aClass = ClassRegistry.get(getStr); - Assert.assertNotNull(aClass); - ClassRegistry.clear(); - } - - @Test - public void set() { - String getStr = "GetModel"; - ClassRegistry.set(getStr, GetModel.class); - Class aClass = ClassRegistry.get(getStr); - Assert.assertEquals(aClass, GetModel.class); - ClassRegistry.set(getStr, SetModel.class); - Class aClass1 = ClassRegistry.get(getStr); - Assert.assertEquals(aClass1, GetModel.class); - ClassRegistry.clear(); - } - - @Test - public void put() { - String getStr = "GetModel"; - ClassRegistry.put(getStr, GetModel.class); - Class aClass = ClassRegistry.get(getStr); - Assert.assertEquals(aClass, GetModel.class); - ClassRegistry.put(getStr, SetModel.class); - Class aClass1 = ClassRegistry.get(getStr); - Assert.assertEquals(aClass1, SetModel.class); - ClassRegistry.clear(); - } - - public static class GetModel { - - } - - public static class SetModel { - - } -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/DefaultInstanceTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/DefaultInstanceTest.java deleted file mode 100644 index eeff9ee3..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/DefaultInstanceTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -import org.junit.Assert; -import org.junit.Test; - -public class DefaultInstanceTest { - - Instance instance = new DefaultInstance(); - - @Test - public void getInstance() { - Class cls = InstanceModel.class; - Object instanceInstance = instance.getInstance(cls); - Assert.assertNotNull(instanceInstance); - Assert.assertEquals(cls, instanceInstance.getClass()); - } - - @Test - public void testGetInstance() { - String className = "cn.hippo4j.rpc.discovery.InstanceModel"; - Object instanceInstance = instance.getInstance(className); - Assert.assertNotNull(instanceInstance); - Assert.assertEquals(className, instanceInstance.getClass().getName()); - } - - @Test(expected = RuntimeException.class) - public void testGetInstanceTest() { - String className = "cn.hippo4j.rpc.discovery.InstanceModelTest"; - Object instanceInstance = instance.getInstance(className); - Assert.assertNotNull(instanceInstance); - Assert.assertEquals(className, instanceInstance.getClass().getName()); - } - - @Test - public void getInstanceTest() { - Class cls = InstanceServerLoader.class; - Object instanceInstance = instance.getInstance(cls); - Assert.assertNotNull(instanceInstance); - Assert.assertEquals(InstanceServerLoaderImpl.class, instanceInstance.getClass()); - } - -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceModel.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceModel.java deleted file mode 100644 index dbe520eb..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceModel.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.springframework.boot.test.context.TestComponent; - -@Setter -@Getter -@AllArgsConstructor -@NoArgsConstructor -@TestComponent -public class InstanceModel { - - String name; -} diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceServerLoader.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceServerLoader.java deleted file mode 100644 index fd279786..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceServerLoader.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -public interface InstanceServerLoader { - - String getName(); - -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceServerLoaderImpl.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceServerLoaderImpl.java deleted file mode 100644 index 6328e3f4..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/InstanceServerLoaderImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class InstanceServerLoaderImpl implements InstanceServerLoader { - - String name = "name"; - -} diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/SpringContextInstanceTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/SpringContextInstanceTest.java deleted file mode 100644 index 5bce1cff..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/discovery/SpringContextInstanceTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.discovery; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * TODO Common module removes spring dependency leftovers - */ -// @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {InstanceModel.class}) -// @RunWith(SpringJUnit4ClassRunner.class) -public class SpringContextInstanceTest { - - Instance instance = new SpringContextInstance(); - - // @Test - public void getInstance() { - Object obj = instance.getInstance(InstanceModel.class); - Assert.assertNotNull(obj); - Assert.assertEquals(obj.getClass(), InstanceModel.class); - } - - // @Test - public void testGetInstance() { - Object obj = instance.getInstance("instanceModel"); - Assert.assertNotNull(obj); - Assert.assertEquals(obj.getClass(), InstanceModel.class); - } -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ClientPoolHandlerTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ClientPoolHandlerTest.java new file mode 100644 index 00000000..90fe4c2c --- /dev/null +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ClientPoolHandlerTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.exception.OperationException; +import io.netty.channel.ChannelHandler; +import org.junit.Assert; +import org.junit.Test; + +public class ClientPoolHandlerTest { + + static final String test = "Test"; + static final String test1 = "Test1"; + + @Test + public void testGetHandlerEntity() { + TestHandler handler = new TestHandler(); + long order = 0; + String name = test; + ClientPoolHandler poolHandler = new ClientPoolHandler(); + HandlerManager.HandlerEntity entity = poolHandler.getHandlerEntity(order, handler, name); + Assert.assertEquals(entity.getName(), name); + Assert.assertEquals(entity.getOrder(), order); + Assert.assertEquals(entity.getHandler(), handler); + } + + @Test + public void testCompareTo() { + TestHandler handler = new TestHandler(); + long order = 0; + TestHandler handler1 = new TestHandler(); + long order1 = 1; + ClientPoolHandler poolHandler = new ClientPoolHandler(); + HandlerManager.HandlerEntity entity = poolHandler.getHandlerEntity(order, handler, test); + HandlerManager.HandlerEntity entity1 = poolHandler.getHandlerEntity(order1, handler1, test1); + int compare = entity.compareTo(entity1); + Assert.assertTrue(compare < 0); + } + + @Test + public void addLast() { + ClientPoolHandler handler = new ClientPoolHandler(); + Assert.assertTrue(handler.isEmpty()); + handler.addLast(null, new TestHandler()); + Assert.assertFalse(handler.isEmpty()); + } + + @Test + public void addFirst() { + ClientPoolHandler handler = new ClientPoolHandler(); + Assert.assertTrue(handler.isEmpty()); + handler.addFirst(null, new TestHandler()); + Assert.assertFalse(handler.isEmpty()); + } + + @Test + public void testAddLast() { + ClientPoolHandler handler = new ClientPoolHandler(); + Assert.assertTrue(handler.isEmpty()); + handler.addLast(test, new TestHandler()); + Assert.assertFalse(handler.isEmpty()); + } + + @Test + public void testAddFirst() { + ClientPoolHandler handler = new ClientPoolHandler(); + Assert.assertTrue(handler.isEmpty()); + handler.addFirst(test, new TestHandler()); + Assert.assertFalse(handler.isEmpty()); + } + + @Test(expected = OperationException.class) + public void testGetHandlerEntityFalse() { + TestFalseHandler handler = new TestFalseHandler(); + long order = 0; + ClientPoolHandler poolHandler = new ClientPoolHandler(); + poolHandler.getHandlerEntity(order, handler, test); + } + +} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ConnectHandlerTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ConnectHandlerTest.java index 6351364e..59bfe5f1 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ConnectHandlerTest.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ConnectHandlerTest.java @@ -17,73 +17,70 @@ package cn.hippo4j.rpc.handler; -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.client.NettyClientConnection; -import cn.hippo4j.rpc.client.RPCClient; +import cn.hippo4j.rpc.client.CallManager; +import cn.hippo4j.rpc.connection.ServerConnection; import cn.hippo4j.rpc.client.RandomPort; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.DefaultInstance; -import cn.hippo4j.rpc.discovery.Instance; -import cn.hippo4j.rpc.discovery.InstanceServerLoader; import cn.hippo4j.rpc.discovery.ServerPort; import cn.hippo4j.rpc.model.DefaultRequest; import cn.hippo4j.rpc.model.DefaultResponse; import cn.hippo4j.rpc.model.Request; import cn.hippo4j.rpc.model.Response; -import cn.hippo4j.rpc.server.NettyServerConnection; +import cn.hippo4j.rpc.connection.SimpleServerConnection; import cn.hippo4j.rpc.server.RPCServer; -import cn.hippo4j.rpc.support.NettyProxyCenter; -import io.netty.channel.pool.ChannelPoolHandler; +import org.junit.AfterClass; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import java.io.IOException; -import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; public class ConnectHandlerTest { - @Test - public void handlerTest() throws IOException { - // server - Class cls = InstanceServerLoader.class; - ClassRegistry.put(cls.getName(), cls); - ServerPort port = new TestServerPort(); - Instance instance = new DefaultInstance(); - NettyServerTakeHandler serverHandler = new NettyServerTakeHandler(instance); - NettyServerConnection connection = new NettyServerConnection(serverHandler); - RPCServer rpcServer = new RPCServer(connection, port); + static final String take = "serverTake"; + static final String biTake = "biTake"; + static final String bareTake = "bareTake"; + static final String timeout = "timeout"; + static final String key = "key"; + static final String test = "test"; + static RPCServer rpcServer; + static ServerPort port = new TestServerPort(); + + @BeforeClass + public static void startServer() { + CallManager manager = new CallManager(); + ServerTakeHandler takeHandler = new ServerTakeHandler<>(biTake, manager::call); + ServerBiTakeHandler biTakeHandler = new ServerBiTakeHandler<>(take, manager::call); + ServerBareTakeHandler bareTakeHandler = new ServerBareTakeHandler<>(bareTake, manager::call); + ServerBareTakeHandler timeoutHandler = new ServerBareTakeHandler<>(timeout, manager::callTestTimeout); + ServerConnection connection = new SimpleServerConnection(takeHandler, bareTakeHandler, biTakeHandler, timeoutHandler); + rpcServer = new RPCServer(connection, port); rpcServer.bind(); while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1L)); } - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port.getPort()); - ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - NettyClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - RPCClient rpcClient = new RPCClient(clientConnection); + } - InstanceServerLoader loader = NettyProxyCenter.createProxy(rpcClient, cls, address); - String name = loader.getName(); - Assert.assertEquals("name", name); - rpcClient.close(); - rpcServer.close(); + @AfterClass + public static void stopServer() throws IOException { + if (rpcServer.isActive()) { + rpcServer.close(); + } } @Test public void testConnectHandlerDefault() { ConnectHandler handler = new TestConnectHandler(); - - Request request = new DefaultRequest("key", "className", "methodName", new Class[0], new Object[0]); + Request request = new DefaultRequest(key, take, new Object[0]); Response response = handler.sendHandler(request); Assert.assertNull(response); - Response response1 = new DefaultResponse("key", this.getClass(), handler); - String key = response1.getKey(); - Class cls = response1.getCls(); + Response response1 = new DefaultResponse(key, test); + String key = response1.getRID(); Object obj = response1.getObj(); handler.handler(response1); - Assert.assertEquals(key, response1.getKey()); - Assert.assertEquals(cls, response1.getCls()); + Assert.assertEquals(key, response1.getRID()); Assert.assertEquals(obj, response1.getObj()); - } static class TestConnectHandler implements ConnectHandler { diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyConnectPoolHolderTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ConnectPoolHolderTest.java similarity index 61% rename from threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyConnectPoolHolderTest.java rename to threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ConnectPoolHolderTest.java index a08b3adb..6924a423 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyConnectPoolHolderTest.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ConnectPoolHolderTest.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package cn.hippo4j.rpc.support; +package cn.hippo4j.rpc.handler; import cn.hippo4j.rpc.client.RandomPort; +import cn.hippo4j.rpc.connection.ConnectPoolHolder; +import cn.hippo4j.rpc.connection.SimpleConnectPool; import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.handler.NettyClientTakeHandler; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; @@ -30,7 +30,7 @@ import org.junit.Test; import java.net.InetSocketAddress; -public class NettyConnectPoolHolderTest { +public class ConnectPoolHolderTest { String host = "127.0.0.1"; ServerPort port = new TestServerPort(); @@ -41,37 +41,37 @@ public class NettyConnectPoolHolderTest { @Test public void createPool() { - NettyClientPoolHandler handler = new NettyClientPoolHandler(new NettyClientTakeHandler()); + ClientPoolHandler handler = new ClientPoolHandler(new ClientTakeHandler()); InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - NettyConnectPool pool = new NettyConnectPool(address, maxCount, timeout, group, cls, handler); - NettyConnectPool connectPool = NettyConnectPoolHolder.getPool(address); + SimpleConnectPool pool = new SimpleConnectPool(address, maxCount, timeout, group, cls, handler); + SimpleConnectPool connectPool = ConnectPoolHolder.getPool(address); Assert.assertEquals(pool, connectPool); - NettyConnectPoolHolder.clear(); - NettyConnectPool connectPool1 = NettyConnectPoolHolder.getPool(address); + ConnectPoolHolder.clear(); + SimpleConnectPool connectPool1 = ConnectPoolHolder.getPool(address); Assert.assertNull(connectPool1); } @Test public void testGetPool() { - NettyClientPoolHandler handler = new NettyClientPoolHandler(new NettyClientTakeHandler()); + ClientPoolHandler handler = new ClientPoolHandler(new ClientTakeHandler()); InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - NettyConnectPool connectPool = NettyConnectPoolHolder.getPool(address, timeout, group, handler); - NettyConnectPool connectPool1 = NettyConnectPoolHolder.getPool(address); + SimpleConnectPool connectPool = ConnectPoolHolder.getPool(address, timeout, group, handler); + SimpleConnectPool connectPool1 = ConnectPoolHolder.getPool(address); Assert.assertEquals(connectPool1, connectPool); - NettyConnectPoolHolder.clear(); - NettyConnectPool connectPool2 = NettyConnectPoolHolder.getPool(address); + ConnectPoolHolder.clear(); + SimpleConnectPool connectPool2 = ConnectPoolHolder.getPool(address); Assert.assertNull(connectPool2); } @Test public void remove() { - NettyClientPoolHandler handler = new NettyClientPoolHandler(new NettyClientTakeHandler()); + ClientPoolHandler handler = new ClientPoolHandler(new ClientTakeHandler()); InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - NettyConnectPool connectPool = NettyConnectPoolHolder.getPool(address, timeout, group, handler); - NettyConnectPool connectPool1 = NettyConnectPoolHolder.getPool(address); + SimpleConnectPool connectPool = ConnectPoolHolder.getPool(address, timeout, group, handler); + SimpleConnectPool connectPool1 = ConnectPoolHolder.getPool(address); Assert.assertEquals(connectPool1, connectPool); - NettyConnectPoolHolder.remove(address); - NettyConnectPool connectPool2 = NettyConnectPoolHolder.getPool(address); + ConnectPoolHolder.remove(address); + SimpleConnectPool connectPool2 = ConnectPoolHolder.getPool(address); Assert.assertNull(connectPool2); } diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/NettyClientPoolHandlerTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/NettyClientPoolHandlerTest.java deleted file mode 100644 index e6f07600..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/NettyClientPoolHandlerTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.handler; - -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.client.CallManager; -import cn.hippo4j.rpc.client.ClientConnection; -import cn.hippo4j.rpc.client.NettyClientConnection; -import cn.hippo4j.rpc.client.RPCClient; -import cn.hippo4j.rpc.client.RandomPort; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.DefaultInstance; -import cn.hippo4j.rpc.discovery.Instance; -import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.model.DefaultRequest; -import cn.hippo4j.rpc.model.Request; -import cn.hippo4j.rpc.model.Response; -import cn.hippo4j.rpc.server.NettyServerConnection; -import cn.hippo4j.rpc.server.RPCServer; -import cn.hippo4j.rpc.server.ServerConnection; -import io.netty.channel.ChannelHandler; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; - -public class NettyClientPoolHandlerTest { - - @Test - public void testGetHandlerEntity() { - TestHandler handler = new TestHandler(); - long order = 0; - String name = "Test"; - NettyClientPoolHandler poolHandler = new NettyClientPoolHandler(); - HandlerManager.HandlerEntity entity = poolHandler.getHandlerEntity(order, handler, name); - Assert.assertEquals(entity.getName(), name); - Assert.assertEquals(entity.getOrder(), order); - Assert.assertEquals(entity.getHandler(), handler); - } - - @Test - public void testCompareTo() { - TestHandler handler = new TestHandler(); - long order = 0; - String name = "Test"; - TestHandler handler1 = new TestHandler(); - long order1 = 1; - String name1 = "Test1"; - NettyClientPoolHandler poolHandler = new NettyClientPoolHandler(); - HandlerManager.HandlerEntity entity = poolHandler.getHandlerEntity(order, handler, name); - HandlerManager.HandlerEntity entity1 = poolHandler.getHandlerEntity(order1, handler1, name1); - int compare = entity.compareTo(entity1); - Assert.assertTrue(compare < 0); - } - - @Test - public void addLast() { - NettyClientPoolHandler handler = new NettyClientPoolHandler(); - Assert.assertTrue(handler.isEmpty()); - handler.addLast(null, new TestHandler()); - Assert.assertFalse(handler.isEmpty()); - } - - @Test - public void addFirst() { - NettyClientPoolHandler handler = new NettyClientPoolHandler(); - Assert.assertTrue(handler.isEmpty()); - handler.addFirst(null, new TestHandler()); - Assert.assertFalse(handler.isEmpty()); - } - - @Test - public void testAddLast() { - NettyClientPoolHandler handler = new NettyClientPoolHandler(); - Assert.assertTrue(handler.isEmpty()); - handler.addLast("Test", new TestHandler()); - Assert.assertFalse(handler.isEmpty()); - } - - @Test - public void testAddFirst() { - NettyClientPoolHandler handler = new NettyClientPoolHandler(); - Assert.assertTrue(handler.isEmpty()); - handler.addFirst("Test", new TestHandler()); - Assert.assertFalse(handler.isEmpty()); - } - - @Test(expected = RuntimeException.class) - public void testGetHandlerEntityFalse() { - TestFalseHandler handler = new TestFalseHandler(); - long order = 0; - String name = "Test"; - NettyClientPoolHandler poolHandler = new NettyClientPoolHandler(); - poolHandler.getHandlerEntity(order, handler, name); - } - - @Test - public void connectionTest() throws IOException { - ServerPort port = new ServerPort() { - - final int a = RandomPort.getSafeRandomPort(); - - @Override - public int getPort() { - return a; - } - }; - Class cls = CallManager.class; - String className = cls.getName(); - ClassRegistry.put(className, cls); - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, port); - rpcServer.bind(); - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port.getPort()); - List handlers = new ArrayList<>(); - handlers.add(new NettyClientTakeHandler()); - NettyClientPoolHandler channelPoolHandler = new NettyClientPoolHandler(handlers); - channelPoolHandler.addLast("test", new TestHandler()); - ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - RPCClient rpcClient = new RPCClient(clientConnection); - Request request = new DefaultRequest("127.0.0.18888", className, "call", null, null); - for (int i = 0; i < 50; i++) { - Response response = rpcClient.connection(request); - boolean active = rpcClient.isActive(); - Assert.assertTrue(active); - Assert.assertEquals(response.getObj(), 1); - } - rpcClient.close(); - rpcServer.close(); - } -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ServerHandlerTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ServerHandlerTest.java new file mode 100644 index 00000000..6f5a54bc --- /dev/null +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/ServerHandlerTest.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.client.CallManager; +import cn.hippo4j.rpc.client.ClientSupport; +import cn.hippo4j.rpc.client.RPCClient; +import cn.hippo4j.rpc.client.RandomPort; +import cn.hippo4j.rpc.connection.ServerConnection; +import cn.hippo4j.rpc.connection.SimpleClientConnection; +import cn.hippo4j.rpc.connection.SimpleServerConnection; +import cn.hippo4j.rpc.discovery.ServerPort; +import cn.hippo4j.rpc.exception.ConnectionException; +import cn.hippo4j.rpc.model.DefaultRequest; +import cn.hippo4j.rpc.model.Request; +import cn.hippo4j.rpc.server.RPCServer; +import cn.hippo4j.rpc.support.AddressUtil; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; + +public class ServerHandlerTest { + + static final String host = "localhost"; + static ServerPort port = new TestServerPort(); + + static final String take = "serverTakeServer"; + static final String biTake = "biTakeServer"; + static final String bareTake = "bareTakeServer"; + static final String timeout = "timeoutServer"; + static final String error = "errorServer"; + static RPCServer rpcServer; + + @BeforeClass + public static void startServer() { + CallManager manager = new CallManager(); + ServerTakeHandler takeHandler = new ServerTakeHandler<>(take, manager::call); + ServerBiTakeHandler biTakeHandler = new ServerBiTakeHandler<>(biTake, manager::call); + ServerBareTakeHandler bareTakeHandler = new ServerBareTakeHandler<>(bareTake, manager::call); + ServerBareTakeHandler timeoutHandler = new ServerBareTakeHandler<>(timeout, manager::callTestTimeout); + ErrorServerHandler error = new ErrorServerHandler(); + ServerConnection connection = new SimpleServerConnection(takeHandler, bareTakeHandler, biTakeHandler, timeoutHandler, error); + rpcServer = new RPCServer(connection, port); + rpcServer.bind(); + while (!rpcServer.isActive()) { + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1L)); + } + } + + @AfterClass + public static void stopServer() throws IOException { + if (rpcServer.isActive()) { + rpcServer.close(); + } + } + + /** + * This test case can be overridden under the handler and coder packages + */ + @Test + public void connection() { + String s = host + ":" + port.getPort(); + int send = ClientSupport.clientSend(s, take, 1); + Assert.assertEquals(send, 1); + InetSocketAddress socketAddress = AddressUtil.getInetAddress(s); + ClientSupport.closeClient(socketAddress); + } + + @Test(expected = ConnectionException.class) + public void connectionError() { + String s = host + ":" + port.getPort(); + int send = ClientSupport.clientSend(s, error, 1); + Assert.assertEquals(1, send); + InetSocketAddress socketAddress = AddressUtil.getInetAddress(s); + ClientSupport.closeClient(socketAddress); + } + + @Test + public void connectionTest() { + Integer[] params = {1, 6}; + String s = host + ":" + port.getPort(); + int send = ClientSupport.clientSend(s, biTake, params); + Assert.assertEquals(7, send); + InetSocketAddress socketAddress = AddressUtil.getInetAddress(s); + ClientSupport.closeClient(socketAddress); + } + + @Test + public void connectionTestBare() { + String s = host + ":" + port.getPort(); + int send = ClientSupport.clientSend(s, bareTake); + Assert.assertEquals(1, send); + InetSocketAddress socketAddress = AddressUtil.getInetAddress(s); + ClientSupport.closeClient(socketAddress); + } + + @Test(expected = Exception.class) + public void responseNullExceptionTest() { + String s = host + ":" + port.getPort(); + ClientPoolHandler handler = new ClientPoolHandler(new ClientTakeHandler()); + InetSocketAddress socketAddress = AddressUtil.getInetAddress(s); + SimpleClientConnection connection = new SimpleClientConnection(socketAddress, handler); + connection.setTimeout(1L); + RPCClient client = new RPCClient(connection); + Request request = new DefaultRequest(UUID.randomUUID().toString(), timeout); + client.connect(request); + } + + static class TestServerPort implements ServerPort { + + int port = RandomPort.getSafeRandomPort(); + + @Override + public int getPort() { + return port; + } + } + +} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/SimpleConnectPoolTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/SimpleConnectPoolTest.java new file mode 100644 index 00000000..e2fde929 --- /dev/null +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/handler/SimpleConnectPoolTest.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.handler; + +import cn.hippo4j.rpc.client.CallManager; +import cn.hippo4j.rpc.client.RandomPort; +import cn.hippo4j.rpc.connection.SimpleConnectPool; +import cn.hippo4j.rpc.discovery.ServerPort; +import cn.hippo4j.rpc.connection.SimpleServerConnection; +import cn.hippo4j.rpc.server.RPCServer; +import cn.hippo4j.rpc.connection.ServerConnection; +import io.netty.channel.Channel; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.util.concurrent.Future; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; + +public class SimpleConnectPoolTest { + + String host = "127.0.0.1"; + int maxCount = 64; + int timeout = 5000; + EventLoopGroup group = new NioEventLoopGroup(); + Class cls = NioSocketChannel.class; + + static ServerPort port = new TestServerPort(); + + static final String take = "serverTake"; + static final String biTake = "biTake"; + static final String bareTake = "bareTake"; + static final String timeoutTake = "timeout"; + static RPCServer rpcServer; + + @BeforeClass + public static void startServer() { + CallManager manager = new CallManager(); + ServerTakeHandler takeHandler = new ServerTakeHandler<>(biTake, manager::call); + ServerBiTakeHandler biTakeHandler = new ServerBiTakeHandler<>(take, manager::call); + ServerBareTakeHandler bareTakeHandler = new ServerBareTakeHandler<>(bareTake, manager::call); + ServerBareTakeHandler timeoutHandler = new ServerBareTakeHandler<>(timeoutTake, manager::callTestTimeout); + ServerConnection connection = new SimpleServerConnection(takeHandler, bareTakeHandler, biTakeHandler, timeoutHandler); + rpcServer = new RPCServer(connection, port); + rpcServer.bind(); + while (!rpcServer.isActive()) { + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1L)); + } + } + + @AfterClass + public static void stopServer() throws IOException { + if (rpcServer.isActive()) { + rpcServer.close(); + } + } + + @Test + public void acquire() { + InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); + ClientPoolHandler poolHandler = new ClientPoolHandler(new ClientTakeHandler()); + SimpleConnectPool pool = new SimpleConnectPool(address, maxCount, timeout, group, cls, poolHandler); + Channel acquire = pool.acquire(timeout); + Assert.assertNotNull(acquire); + pool.release(acquire); + } + + @Test + public void testAcquire() { + InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); + ClientPoolHandler poolHandler = new ClientPoolHandler(new ClientTakeHandler()); + SimpleConnectPool pool = new SimpleConnectPool(address, maxCount, timeout, group, cls, poolHandler); + Future acquire = pool.acquire(); + Assert.assertNotNull(acquire); + } + + @Test + public void close() { + InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); + ClientPoolHandler poolHandler = new ClientPoolHandler(new ClientTakeHandler()); + SimpleConnectPool pool = new SimpleConnectPool(address, maxCount, timeout, group, cls, poolHandler); + Channel acquire = pool.acquire(timeout); + Assert.assertNotNull(acquire); + pool.release(acquire); + pool.close(); + } + + static class TestServerPort implements ServerPort { + + int port = RandomPort.getSafeRandomPort(); + + @Override + public int getPort() { + return port; + } + } +} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultRequestTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultRequestTest.java index ada1121f..073b6602 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultRequestTest.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultRequestTest.java @@ -17,7 +17,6 @@ package cn.hippo4j.rpc.model; -import cn.hippo4j.rpc.discovery.InstanceServerLoaderImpl; import org.junit.Assert; import org.junit.Test; @@ -26,20 +25,18 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.lang.reflect.Method; public class DefaultRequestTest { + static final String name = "name"; + static final String rid = "rid"; + static final String hippo4j = "hippo4j"; + @Test - public void testReadObject() throws IOException, ClassNotFoundException, NoSuchMethodException { - String key = "name"; - String clsName = InstanceServerLoaderImpl.class.getName(); - Method method = InstanceServerLoaderImpl.class.getMethod("setName", String.class); - String methodName = method.getName(); - Class[] parameterTypes = method.getParameterTypes(); + public void testReadObject() throws IOException, ClassNotFoundException { Object[] parameters = new Object[1]; - parameters[0] = "hippo4j"; - Request request = new DefaultRequest(key, clsName, methodName, parameterTypes, parameters); + parameters[0] = hippo4j; + Request request = new DefaultRequest(rid, name, parameters); byte[] bytes; try ( ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); @@ -55,26 +52,17 @@ public class DefaultRequestTest { request1 = (Request) objectInputStream.readObject(); } Assert.assertEquals(request1.hashCode(), request1.hashCode()); - Assert.assertEquals(key, request1.getKey()); - Assert.assertEquals(clsName, request1.getClassName()); - Assert.assertEquals(methodName, request1.getMethodName()); - Assert.assertArrayEquals(parameterTypes, request1.getParameterTypes()); + Assert.assertEquals(name, request1.getKey()); + Assert.assertEquals(rid, request1.getRID()); Assert.assertArrayEquals(parameters, request1.getParameters()); Assert.assertEquals(request1, request); } @Test - public void testEquals() throws NoSuchMethodException { - String key = "name"; - String clsName = InstanceServerLoaderImpl.class.getName(); - Method method = InstanceServerLoaderImpl.class.getMethod("setName", String.class); - String methodName = method.getName(); - Class[] parameterTypes = method.getParameterTypes(); - Object[] parameters = new Object[1]; - parameters[0] = "hippo4j"; - Request request = new DefaultRequest(key, clsName, methodName, parameterTypes, parameters); + public void testEquals() { + Request request = new DefaultRequest(rid, name); Assert.assertTrue(request.equals(request)); - Assert.assertFalse(request.equals(null)); + Assert.assertFalse(request == null); } } \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultResponseTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultResponseTest.java index c3e4d209..8752cf84 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultResponseTest.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/model/DefaultResponseTest.java @@ -28,12 +28,13 @@ import java.io.ObjectOutputStream; public class DefaultResponseTest { + static final String rid = "name"; + static final Object o = "obj"; + static final String errMsg = "test throwable"; + @Test public void testReadObject() throws IOException, ClassNotFoundException { - String key = "name"; - Object o = "obj"; - Class cls = String.class; - Response response = new DefaultResponse(key, cls, o); + Response response = new DefaultResponse(rid, o); byte[] bytes; try ( ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); @@ -49,19 +50,15 @@ public class DefaultResponseTest { response1 = (Response) objectInputStream.readObject(); } Assert.assertEquals(response1.hashCode(), response.hashCode()); - Assert.assertEquals(key, response1.getKey()); + Assert.assertEquals(rid, response1.getRID()); Assert.assertEquals(o, response1.getObj()); - Assert.assertEquals(cls, response1.getCls()); Assert.assertEquals(response1, response); Assert.assertFalse(response1.isErr()); } @Test public void testWriteObject() throws IOException, ClassNotFoundException { - String key = "name"; - Throwable throwable = new RuntimeException("test throwable"); - String errMsg = "test throwable"; - Response response = new DefaultResponse(key, throwable, errMsg); + Response response = new DefaultResponse(rid, errMsg); byte[] bytes; try ( ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); @@ -76,10 +73,7 @@ public class DefaultResponseTest { ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream)) { response1 = (Response) objectInputStream.readObject(); } - Assert.assertEquals(key, response1.getKey()); - Assert.assertThrows(RuntimeException.class, () -> { - throw response1.getThrowable(); - }); + Assert.assertEquals(rid, response1.getRID()); Assert.assertEquals(response1.hashCode(), response.hashCode()); Assert.assertEquals(errMsg, response1.getErrMsg()); Assert.assertEquals(response1, response); @@ -87,11 +81,8 @@ public class DefaultResponseTest { } @Test - public void testEquals() throws NoSuchMethodException { - String key = "name"; - Object o = "obj"; - Class cls = String.class; - Response response = new DefaultResponse(key, cls, o); + public void testEquals() { + Response response = new DefaultResponse(rid, o); Assert.assertTrue(response.equals(response)); Assert.assertFalse(response.equals(null)); } diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/NettyServerConnectionTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/NettyServerConnectionTest.java index 250429a8..b6e05848 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/NettyServerConnectionTest.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/NettyServerConnectionTest.java @@ -17,41 +17,48 @@ package cn.hippo4j.rpc.server; +import cn.hippo4j.rpc.connection.SimpleServerConnection; import cn.hippo4j.rpc.handler.TestHandler; import org.junit.Assert; import org.junit.Test; public class NettyServerConnectionTest { + static final String test = "Test"; + @Test public void addLast() { - NettyServerConnection connection = new NettyServerConnection(); - Assert.assertTrue(connection.isEmpty()); - connection.addLast(null, new TestHandler()); - Assert.assertFalse(connection.isEmpty()); + try (SimpleServerConnection connection = new SimpleServerConnection()) { + Assert.assertTrue(connection.isEmpty()); + connection.addLast(null, new TestHandler()); + Assert.assertFalse(connection.isEmpty()); + } } @Test public void addFirst() { - NettyServerConnection connection = new NettyServerConnection(); - Assert.assertTrue(connection.isEmpty()); - connection.addFirst(null, new TestHandler()); - Assert.assertFalse(connection.isEmpty()); + try (SimpleServerConnection connection = new SimpleServerConnection()) { + Assert.assertTrue(connection.isEmpty()); + connection.addFirst(null, new TestHandler()); + Assert.assertFalse(connection.isEmpty()); + } } @Test public void testAddLast() { - NettyServerConnection connection = new NettyServerConnection(); - Assert.assertTrue(connection.isEmpty()); - connection.addLast("Test", new TestHandler()); - Assert.assertFalse(connection.isEmpty()); + try (SimpleServerConnection connection = new SimpleServerConnection()) { + Assert.assertTrue(connection.isEmpty()); + connection.addLast(test, new TestHandler()); + Assert.assertFalse(connection.isEmpty()); + } } @Test public void testAddFirst() { - NettyServerConnection connection = new NettyServerConnection(); - Assert.assertTrue(connection.isEmpty()); - connection.addFirst("Test", new TestHandler()); - Assert.assertFalse(connection.isEmpty()); + try (SimpleServerConnection connection = new SimpleServerConnection()) { + Assert.assertTrue(connection.isEmpty()); + connection.addFirst(test, new TestHandler()); + Assert.assertFalse(connection.isEmpty()); + } } } \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/RPCServerTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/RPCServerTest.java index ac6f2637..b53fd4fb 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/RPCServerTest.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/RPCServerTest.java @@ -17,43 +17,31 @@ package cn.hippo4j.rpc.server; -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.client.CallManager; -import cn.hippo4j.rpc.client.ClientConnection; -import cn.hippo4j.rpc.client.NettyClientConnection; -import cn.hippo4j.rpc.client.RPCClient; import cn.hippo4j.rpc.client.RandomPort; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.DefaultInstance; -import cn.hippo4j.rpc.discovery.Instance; -import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.handler.NettyClientTakeHandler; -import cn.hippo4j.rpc.handler.NettyServerTakeHandler; -import cn.hippo4j.rpc.handler.TestHandler; -import cn.hippo4j.rpc.model.DefaultRequest; -import cn.hippo4j.rpc.model.Request; -import cn.hippo4j.rpc.model.Response; +import cn.hippo4j.rpc.connection.ServerConnection; +import cn.hippo4j.rpc.connection.SimpleServerConnection; +import cn.hippo4j.rpc.handler.ServerTakeHandler; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.pool.ChannelPoolHandler; import org.junit.Assert; import org.junit.Test; import java.io.IOException; -import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; public class RPCServerTest { + static final String instance = "instance"; + @Test public void bind() throws IOException { - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); + ServerTakeHandler handler = new ServerTakeHandler(instance, o -> 1); + ServerConnection connection = new SimpleServerConnection(handler); RPCServer rpcServer = new RPCServer(connection, RandomPort::getSafeRandomPort); rpcServer.bind(); while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1L)); } boolean active = rpcServer.isActive(); Assert.assertTrue(active); @@ -62,71 +50,18 @@ public class RPCServerTest { @Test public void bindTest() throws IOException { - Instance instance = new DefaultInstance(); EventLoopGroup leader = new NioEventLoopGroup(); EventLoopGroup worker = new NioEventLoopGroup(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(leader, worker, handler); + ServerTakeHandler handler = new ServerTakeHandler(instance, o -> 1); + ServerConnection connection = new SimpleServerConnection(leader, worker, handler); RPCServer rpcServer = new RPCServer(connection, RandomPort::getSafeRandomPort); rpcServer.bind(); while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1L)); } boolean active = rpcServer.isActive(); Assert.assertTrue(active); rpcServer.close(); } - @Test - public void bindPipelineTest() throws IOException { - ServerPort serverPort = new ServerPort() { - - final int port = RandomPort.getSafeRandomPort(); - - @Override - public int getPort() { - return port; - } - }; - Class cls = CallManager.class; - String className = cls.getName(); - ClassRegistry.put(className, cls); - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - NettyServerConnection connection = new NettyServerConnection(handler); - connection.addLast("Test", new TestHandler()); - RPCServer rpcServer = new RPCServer(connection, serverPort); - rpcServer.bind(); - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", serverPort.getPort()); - ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - RPCClient rpcClient = new RPCClient(clientConnection); - Request request = new DefaultRequest("127.0.0.18888", className, "call", null, null); - for (int i = 0; i < 50; i++) { - Response response = rpcClient.connection(request); - boolean active = rpcClient.isActive(); - Assert.assertTrue(active); - Assert.assertEquals(response.getObj(), 1); - } - rpcClient.close(); - rpcServer.close(); - } - - @Test - public void bindNegativeTest() { - ServerPort serverPort = () -> -1; - Class cls = CallManager.class; - String className = cls.getName(); - ClassRegistry.put(className, cls); - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - NettyServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, serverPort); - rpcServer.bind(); - } } \ No newline at end of file diff --git a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/ServerConnection.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/ServerSupportTest.java similarity index 58% rename from threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/ServerConnection.java rename to threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/ServerSupportTest.java index a72d2318..036e0a79 100644 --- a/threadpool/rpc/src/main/java/cn/hippo4j/rpc/server/ServerConnection.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/server/ServerSupportTest.java @@ -17,19 +17,25 @@ package cn.hippo4j.rpc.server; -import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.handler.Connection; +import cn.hippo4j.rpc.client.RandomPort; +import org.junit.Assert; +import org.junit.Test; -/** - * This applies to server-side connections - * - * @since 2.0.0 - */ -public interface ServerConnection extends Connection { +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; + +public class ServerSupportTest { - /** - * Bind ports and process them - */ - void bind(ServerPort port); + @Test + public void bind() throws IOException { + ServerSupport support = new ServerSupport(RandomPort::getSafeRandomPort); + support.bind(); + while (!support.isActive()) { + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L)); + } + Assert.assertTrue(support.isActive()); + support.close(); + } -} +} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/AddressUtilTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/AddressUtilTest.java new file mode 100644 index 00000000..e8b857a5 --- /dev/null +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/AddressUtilTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.rpc.support; + +import cn.hippo4j.rpc.exception.ConnectionException; +import org.junit.Assert; +import org.junit.Test; + +import java.net.InetSocketAddress; + +public class AddressUtilTest { + + String address1 = "http://hippo4j.cn/login:8080"; + String address2 = "https://hippo4j.cn/login:8080"; + String address3 = "https://hippo4j.cn/login"; + String addressHostName = "hippo4j.cn/login"; + int addressPort = 8080; + + @Test + public void test() { + InetSocketAddress address = AddressUtil.getInetAddress(address1); + Assert.assertEquals(addressHostName, address.getHostName()); + Assert.assertEquals(addressPort, address.getPort()); + } + + @Test + public void testAddress2() { + InetSocketAddress address = AddressUtil.getInetAddress(address2); + Assert.assertEquals(addressHostName, address.getHostName()); + Assert.assertEquals(addressPort, address.getPort()); + } + + @Test(expected = ConnectionException.class) + public void testAddress3() { + AddressUtil.getInetAddress(address3); + } +} diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyClientSupportTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyClientSupportTest.java deleted file mode 100644 index f1d5e09f..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyClientSupportTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.support; - -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.client.CallManager; -import cn.hippo4j.rpc.client.ClientConnection; -import cn.hippo4j.rpc.client.NettyClientConnection; -import cn.hippo4j.rpc.client.RPCClient; -import cn.hippo4j.rpc.client.RandomPort; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.DefaultInstance; -import cn.hippo4j.rpc.discovery.Instance; -import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.handler.NettyClientTakeHandler; -import cn.hippo4j.rpc.handler.NettyServerTakeHandler; -import cn.hippo4j.rpc.handler.TestHandler; -import cn.hippo4j.rpc.server.NettyServerConnection; -import cn.hippo4j.rpc.server.RPCServer; -import io.netty.channel.pool.ChannelPoolHandler; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; - -public class NettyClientSupportTest { - - @Test - public void closeTest() throws IOException { - int port = RandomPort.getSafeRandomPort(); - ServerPort serverPort = () -> port; - Class cls = CallManager.class; - String className = cls.getName(); - ClassRegistry.put(className, cls); - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - NettyServerConnection connection = new NettyServerConnection(handler); - connection.addLast("Test", new TestHandler()); - RPCServer rpcServer = new RPCServer(connection, serverPort); - rpcServer.bind(); - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port); - ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - RPCClient rpcClient = new RPCClient(clientConnection); - - NettyClientSupport.closeClient(new InetSocketAddress("localhost", port)); - - rpcClient.close(); - rpcServer.close(); - } - -} diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyConnectPoolTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyConnectPoolTest.java deleted file mode 100644 index bdc45d42..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyConnectPoolTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.support; - -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.client.RandomPort; -import cn.hippo4j.rpc.discovery.DefaultInstance; -import cn.hippo4j.rpc.discovery.Instance; -import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.handler.NettyClientTakeHandler; -import cn.hippo4j.rpc.handler.NettyServerTakeHandler; -import cn.hippo4j.rpc.server.NettyServerConnection; -import cn.hippo4j.rpc.server.RPCServer; -import cn.hippo4j.rpc.server.ServerConnection; -import io.netty.channel.Channel; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.util.concurrent.Future; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; - -public class NettyConnectPoolTest { - - String host = "127.0.0.1"; - ServerPort port = new TestServerPort(); - int maxCount = 64; - int timeout = 5000; - EventLoopGroup group = new NioEventLoopGroup(); - Class cls = NioSocketChannel.class; - - @Test - public void acquire() throws IOException { - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, port); - rpcServer.bind(); - // Given the delay in starting the server, wait here - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - NettyClientPoolHandler poolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - NettyConnectPool pool = new NettyConnectPool(address, maxCount, timeout, group, cls, poolHandler); - Channel acquire = pool.acquire(timeout); - Assert.assertNotNull(acquire); - pool.release(acquire); - rpcServer.close(); - } - - @Test - public void testAcquire() throws IOException { - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, port); - rpcServer.bind(); - // Given the delay in starting the server, wait here - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - NettyClientPoolHandler poolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - NettyConnectPool pool = new NettyConnectPool(address, maxCount, timeout, group, cls, poolHandler); - Future acquire = pool.acquire(); - Assert.assertNotNull(acquire); - rpcServer.close(); - } - - @Test - public void close() throws IOException { - // The mode connection was denied when the server was started on the specified port - Instance instance = new DefaultInstance(); - NettyServerTakeHandler handler = new NettyServerTakeHandler(instance); - ServerConnection connection = new NettyServerConnection(handler); - RPCServer rpcServer = new RPCServer(connection, port); - rpcServer.bind(); - // Given the delay in starting the server, wait here - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort()); - NettyClientPoolHandler poolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - NettyConnectPool pool = new NettyConnectPool(address, maxCount, timeout, group, cls, poolHandler); - Channel acquire = pool.acquire(timeout); - Assert.assertNotNull(acquire); - pool.release(acquire); - pool.close(); - rpcServer.close(); - } - - static class TestServerPort implements ServerPort { - - int port = RandomPort.getSafeRandomPort(); - @Override - public int getPort() { - return port; - } - } -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyProxyCenterTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyProxyCenterTest.java deleted file mode 100644 index c807c514..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyProxyCenterTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.support; - -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.client.Client; -import cn.hippo4j.rpc.client.NettyClientConnection; -import cn.hippo4j.rpc.client.RPCClient; -import cn.hippo4j.rpc.client.RandomPort; -import cn.hippo4j.rpc.discovery.ClassRegistry; -import cn.hippo4j.rpc.discovery.DefaultInstance; -import cn.hippo4j.rpc.discovery.Instance; -import cn.hippo4j.rpc.discovery.InstanceServerLoader; -import cn.hippo4j.rpc.discovery.ServerPort; -import cn.hippo4j.rpc.exception.ConnectionException; -import cn.hippo4j.rpc.handler.NettyClientPoolHandler; -import cn.hippo4j.rpc.handler.NettyClientTakeHandler; -import cn.hippo4j.rpc.handler.NettyServerTakeHandler; -import cn.hippo4j.rpc.server.NettyServerConnection; -import cn.hippo4j.rpc.server.RPCServer; -import io.netty.channel.pool.ChannelPoolHandler; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; - -public class NettyProxyCenterTest { - - ServerPort port = new TestServerPort(); - - @Test - public void getProxy() { - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port.getPort()); - NettyClientPoolHandler handler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - ProxyInterface localhost = NettyProxyCenter.getProxy(ProxyInterface.class, address, handler); - Assert.assertNotNull(localhost); - } - - @Test - public void createProxy() { - ProxyInterface localhost = NettyProxyCenter.getProxy(ProxyInterface.class, "localhost:8894"); - Assert.assertNotNull(localhost); - NettyProxyCenter.getProxy(ProxyInterface.class, "localhost:8894"); - InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("localhost", 8894); - Client client = NettyClientSupport.getClient(socketAddress); - ProxyInterface proxy = NettyProxyCenter.createProxy(client, ProxyInterface.class, socketAddress); - Assert.assertNotNull(proxy); - } - - @Test(expected = ConnectionException.class) - public void createProxyException() { - NettyProxyCenter.getProxy(ProxyInterface.class, "localhost8894"); - } - - @Test - public void removeProxy() { - NettyProxyCenter.getProxy(ProxyInterface.class, "localhost:8894"); - NettyProxyCenter.removeProxy(ProxyInterface.class, "localhost:8894"); - } - - @Test(expected = ConnectionException.class) - public void removeProxyException() { - NettyProxyCenter.removeProxy(ProxyInterface.class, "localhost8894"); - } - - @Test(expected = RuntimeException.class) - public void getProxyTest() { - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port.getPort()); - NettyClientPoolHandler handler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - ProxyClass localhost = NettyProxyCenter.getProxy(ProxyClass.class, address, handler); - Assert.assertNotNull(localhost); - } - - @Test - public void bindPipelineTest() throws IOException { - // server - Class cls = InstanceServerLoader.class; - ClassRegistry.put(cls.getName(), cls); - ServerPort port = new TestServerPort(); - Instance instance = new DefaultInstance(); - NettyServerTakeHandler serverHandler = new NettyServerTakeHandler(instance); - NettyServerConnection connection = new NettyServerConnection(serverHandler); - RPCServer rpcServer = new RPCServer(connection, port); - rpcServer.bind(); - while (!rpcServer.isActive()) { - ThreadUtil.sleep(100L); - } - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port.getPort()); - ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler()); - NettyClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler); - RPCClient rpcClient = new RPCClient(clientConnection); - - InstanceServerLoader loader = NettyProxyCenter.createProxy(rpcClient, cls, address); - String name = loader.getName(); - Assert.assertEquals("name", name); - rpcClient.close(); - rpcServer.close(); - } - - interface ProxyInterface { - - void hello(); - } - - static class ProxyClass { - - } - - static class TestServerPort implements ServerPort { - - int port = RandomPort.getSafeRandomPort(); - - @Override - public int getPort() { - return port; - } - } -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyServerSupportTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyServerSupportTest.java deleted file mode 100644 index bb9a9be0..00000000 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/NettyServerSupportTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.rpc.support; - -import cn.hippo4j.common.toolkit.ThreadUtil; -import cn.hippo4j.rpc.client.RandomPort; -import cn.hippo4j.rpc.discovery.InstanceServerLoader; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class NettyServerSupportTest { - - @Test - public void bind() throws IOException { - NettyServerSupport support = new NettyServerSupport(RandomPort::getSafeRandomPort, InstanceServerLoader.class); - support.bind(); - while (!support.isActive()) { - ThreadUtil.sleep(100L); - } - Assert.assertTrue(support.isActive()); - support.close(); - } - - @Test - public void bindTest() throws IOException { - List> classes = new ArrayList<>(); - classes.add(InstanceServerLoader.class); - NettyServerSupport support = new NettyServerSupport(RandomPort::getSafeRandomPort, classes); - support.bind(); - while (!support.isActive()) { - ThreadUtil.sleep(100L); - } - Assert.assertTrue(support.isActive()); - support.close(); - } - -} \ No newline at end of file diff --git a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/ResultHolderTest.java b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/ResultHolderTest.java index 4302a335..7f2f01ef 100644 --- a/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/ResultHolderTest.java +++ b/threadpool/rpc/src/test/java/cn/hippo4j/rpc/support/ResultHolderTest.java @@ -17,10 +17,10 @@ package cn.hippo4j.rpc.support; -import cn.hippo4j.common.toolkit.IdUtil; import org.junit.Assert; import org.junit.Test; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -28,12 +28,15 @@ import java.util.concurrent.locks.LockSupport; public class ResultHolderTest { + static final String str1 = "1"; + static final String str2 = "2"; + @Test public void test() { - String s1 = IdUtil.simpleUUID(); - String o1 = s1 + "1"; - String s2 = IdUtil.simpleUUID(); - String o2 = s2 + "2"; + String s1 = UUID.randomUUID().toString(); + String o1 = s1 + str1; + String s2 = UUID.randomUUID().toString(); + String o2 = s2 + str2; ResultHolder.put(s1, o1); ResultHolder.put(s2, o2); @@ -48,8 +51,8 @@ public class ResultHolderTest { @Test public void testThread() throws InterruptedException { AtomicInteger a = new AtomicInteger(); - String s1 = IdUtil.simpleUUID(); - String o1 = s1 + "1"; + String s1 = UUID.randomUUID().toString(); + String o1 = s1 + str1; CompletableFuture.runAsync(() -> { ResultHolder.putThread(o1, Thread.currentThread()); LockSupport.park(); diff --git a/threadpool/rpc/src/test/resources/META-INF/services/cn.hippo4j.rpc.discovery.InstanceServerLoader b/threadpool/rpc/src/test/resources/META-INF/services/cn.hippo4j.rpc.discovery.InstanceServerLoader deleted file mode 100644 index 3014d7e6..00000000 --- a/threadpool/rpc/src/test/resources/META-INF/services/cn.hippo4j.rpc.discovery.InstanceServerLoader +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -cn.hippo4j.rpc.discovery.InstanceServerLoaderImpl \ No newline at end of file diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java index e64ab45c..408aa3d4 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java @@ -19,12 +19,14 @@ package cn.hippo4j.auth.filter; import cn.hippo4j.auth.model.biz.user.JwtUser; import cn.hippo4j.auth.model.biz.user.LoginUser; +import cn.hippo4j.auth.toolkit.AESUtil; import cn.hippo4j.auth.toolkit.JwtTokenUtil; import cn.hippo4j.auth.toolkit.ReturnT; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.server.common.base.Results; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.codec.DecodingException; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -38,6 +40,7 @@ import javax.servlet.FilterChain; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -69,10 +72,17 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte Authentication authenticate = null; try { LoginUser loginUser = new ObjectMapper().readValue(request.getInputStream(), LoginUser.class); + String key = new StringBuffer(loginUser.getTag()).reverse().toString(); + String password = AESUtil.decrypt(loginUser.getPassword(), key); + loginUser.setPassword(password); + request.setAttribute("loginUser", loginUser); rememberMe.set(loginUser.getRememberMe()); authenticate = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken(loginUser.getUsername(), loginUser.getPassword(), new ArrayList())); + } catch (GeneralSecurityException e) { + log.warn("Password decode exception: {}", e.getMessage()); + throw new DecodingException(e.getMessage()); } catch (UsernameNotFoundException e) { log.warn("User {} not found", e.getMessage()); throw e; diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/biz/user/LoginUser.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/biz/user/LoginUser.java index 0c15778c..b5cd71d3 100644 --- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/biz/user/LoginUser.java +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/model/biz/user/LoginUser.java @@ -24,6 +24,10 @@ import lombok.Data; */ @Data public class LoginUser { + /** + * encode key reverse + */ + private String tag; /** * username diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/toolkit/AESUtil.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/toolkit/AESUtil.java new file mode 100644 index 00000000..5a1ed033 --- /dev/null +++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/toolkit/AESUtil.java @@ -0,0 +1,92 @@ +package cn.hippo4j.auth.toolkit; + +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import lombok.experimental.UtilityClass; + +import javax.crypto.*; +import javax.crypto.spec.GCMParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.StandardCharsets; +import java.security.GeneralSecurityException; +import java.util.Base64; + +/** + * AES encryption and decryption algorithm tool class + * + * @author Serenity + * @date 2023/5/21 14:37 + * @since JDK1.8+ + */ +@UtilityClass +public class AESUtil { + + private static final String AES_GCM_CIPHER = "AES/GCM/PKCS5Padding"; + + /** + * encrypt + * + * @param data Content that needs to be encrypted + * @param key Encrypt the password + * @return byte[] + */ + public static byte[] encrypt(byte[] data, byte[] key) throws GeneralSecurityException { + SecretKeySpec sKeySpec = new SecretKeySpec(key, "AES"); + Cipher cipher = Cipher.getInstance(AES_GCM_CIPHER); + cipher.init(Cipher.ENCRYPT_MODE, sKeySpec); + byte[] iv = cipher.getIV(); + byte[] encryptData = cipher.doFinal(data); + byte[] message = new byte[12 + data.length + 16]; + System.arraycopy(iv, 0, message, 0, 12); + System.arraycopy(encryptData, 0, message, 12, encryptData.length); + return message; + } + + /** + * decrypt + * + * @param data The content to be decrypted + * @param key Decryption key + * @return byte[] + */ + public static byte[] decrypt(byte[] data, byte[] key) throws GeneralSecurityException{ + GCMParameterSpec iv = new GCMParameterSpec(128, data, 0, 12); + Cipher cipher = Cipher.getInstance(AES_GCM_CIPHER); + SecretKey key2 = new SecretKeySpec(key, "AES"); + cipher.init(Cipher.DECRYPT_MODE, key2, iv); + return cipher.doFinal(data, 12, data.length - 12); + } + + /** + * encrypt + * + * @param data Content that needs to be encrypted + * @param key Encrypt the password + * @return String + */ + public static String encrypt(String data, String key) throws GeneralSecurityException { + byte[] valueByte = encrypt(data.getBytes(StandardCharsets.UTF_8), key.getBytes(StandardCharsets.UTF_8)); + return Base64.getEncoder().encodeToString(valueByte); + } + + /** + * decrypt + * + * @param data The content to be decrypted is a base64 string + * @param key Decryption key + * @return String + */ + public static String decrypt(String data, String key) throws GeneralSecurityException { + byte[] originalData = Base64.getDecoder().decode(data.getBytes()); + byte[] valueByte = decrypt(originalData, key.getBytes(StandardCharsets.UTF_8)); + return new String(valueByte); + } + + /** + * Generate a random string key + * + * @return The string key + */ + public static String generateRandomKey() { + return IdWorker.get32UUID().substring(0, 16); + } +} diff --git a/threadpool/server/bootstrap/pom.xml b/threadpool/server/bootstrap/pom.xml index 2fd29939..071f18a3 100644 --- a/threadpool/server/bootstrap/pom.xml +++ b/threadpool/server/bootstrap/pom.xml @@ -11,7 +11,7 @@ true - ${project.parent.parent.parent.basedir}/docker/threadpool + ${project.parent.parent.parent.basedir}/docker @@ -70,7 +70,7 @@ UTF-8 - ../../../docker/threadpool/conf/ + ../../../docker/conf/ conf @@ -91,7 +91,7 @@ UTF-8 - ../../../docker/threadpool/target + ../../../docker/target target