diff --git a/agent/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 index 64f6ce9c69..4da18b4a94 100644 --- a/agent/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 @@ -17,13 +17,9 @@ package cn.hippo4j.agent.bootstrap; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; import cn.hippo4j.agent.core.boot.ServiceManager; -import cn.hippo4j.agent.core.conf.Config; import cn.hippo4j.agent.core.conf.SnifferConfigInitializer; import cn.hippo4j.agent.core.jvm.LoadedLibraryCollector; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.AbstractClassEnhancePluginDefine; import cn.hippo4j.agent.core.plugin.EnhanceContext; import cn.hippo4j.agent.core.plugin.InstrumentDebuggingClass; @@ -33,6 +29,10 @@ import cn.hippo4j.agent.core.plugin.bootstrap.BootstrapInstrumentBoost; import cn.hippo4j.agent.core.plugin.bytebuddy.CacheableTransformerDecorator; import cn.hippo4j.agent.core.plugin.jdk9module.JDK9ModuleExporter; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import net.bytebuddy.ByteBuddy; import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.description.NamedElement; diff --git a/agent/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 index 029a4bfbcf..02b3c6657a 100644 --- a/agent/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 @@ -17,8 +17,9 @@ package cn.hippo4j.agent.core.boot; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; import java.io.File; import java.net.MalformedURLException; diff --git a/agent/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 index 2026ea9f94..7391f1c261 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.boot; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.loader.AgentClassLoader; import java.util.Collections; diff --git a/agent/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 index eb2eafef7c..5d12c1e6eb 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.boot; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.util.ConfigInitializer; import java.util.Collections; diff --git a/agent/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 index 570a68c881..b1c0a56cce 100644 --- a/agent/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 @@ -17,15 +17,17 @@ package cn.hippo4j.agent.core.conf; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; -import cn.hippo4j.agent.core.boot.AgentPackagePath; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; -import cn.hippo4j.agent.core.logging.core.JsonLogResolver; -import cn.hippo4j.agent.core.logging.core.PatternLogResolver; -import cn.hippo4j.agent.core.util.ConfigInitializer; -import cn.hippo4j.agent.core.util.PropertyPlaceholderHelper; -import cn.hippo4j.agent.core.util.StringUtil; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.boot.AgentPackagePath; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.conf.ConfigNotFoundException; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; +import cn.hippo4j.common.logging.core.JsonLogResolver; +import cn.hippo4j.common.logging.core.PatternLogResolver; +import cn.hippo4j.common.toolkit.StringUtil; +import cn.hippo4j.common.toolkit.agent.ConfigInitializer; +import cn.hippo4j.common.toolkit.agent.PropertyPlaceholderHelper; import java.io.File; import java.io.FileInputStream; @@ -37,7 +39,7 @@ import java.util.Map; import java.util.Properties; -import static cn.hippo4j.agent.core.conf.Constants.SERVICE_NAME_PART_CONNECTOR; +import static cn.hippo4j.common.conf.Constants.SERVICE_NAME_PART_CONNECTOR; /** * The SnifferConfigInitializer initializes all configs in several way. @@ -204,7 +206,7 @@ private static void overrideConfigBySystemProp() { * * @return the config file {@link InputStream}, or null if not needEnhance. */ - private static InputStreamReader loadConfig() throws AgentPackageNotFoundException, ConfigNotFoundException { + private static InputStreamReader loadConfig() throws AgentPackageNotFoundException, cn.hippo4j.common.conf.ConfigNotFoundException { String specifiedConfigPath = System.getProperty(SPECIFIED_CONFIG_PATH); File configFile = StringUtil.isEmpty(specifiedConfigPath) ? new File( AgentPackagePath.getPath(), DEFAULT_CONFIG_FILE_NAME) : new File(specifiedConfigPath); diff --git a/agent/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 index f8a466a6c4..aebec1f038 100644 --- a/agent/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 @@ -17,9 +17,9 @@ package cn.hippo4j.agent.core.jvm; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.util.CollectionUtil; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import com.google.gson.Gson; import com.google.gson.GsonBuilder; diff --git a/agent/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 index 41384b1ab6..82278a6a5f 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.interceptor.ConstructorInterceptPoint; import cn.hippo4j.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import cn.hippo4j.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; diff --git a/agent/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 index e82258fb18..02a900ccd2 100644 --- a/agent/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 @@ -17,11 +17,11 @@ package cn.hippo4j.agent.core.plugin; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; import cn.hippo4j.agent.core.boot.AgentPackagePath; -import cn.hippo4j.agent.core.conf.Config; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.conf.Config; import net.bytebuddy.dynamic.DynamicType; import java.io.File; diff --git a/agent/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 index 12dffe3914..f76fe19d83 100644 --- a/agent/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 @@ -17,10 +17,10 @@ package cn.hippo4j.agent.core.plugin; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.loader.AgentClassLoader; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import java.net.URL; import java.util.ArrayList; diff --git a/agent/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 index 81e5027b8f..fe707c9ca0 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.exception.IllegalPluginDefineException; import java.io.BufferedReader; diff --git a/agent/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 index 06058a0b52..861995eeaf 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.loader.AgentClassLoader; import java.io.IOException; diff --git a/agent/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 index 8f336b36e2..4859909ee1 100644 --- a/agent/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 @@ -20,9 +20,8 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import cn.hippo4j.agent.core.conf.Config; -import static cn.hippo4j.agent.core.conf.Config.Plugin.EXCLUDE_PLUGINS; +import static cn.hippo4j.common.conf.Config.Plugin.EXCLUDE_PLUGINS; /** * Select some plugins in activated plugins diff --git a/agent/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 index 3260e439b5..7138ea8574 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.bootstrap; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.AbstractClassEnhancePluginDefine; import cn.hippo4j.agent.core.plugin.ByteBuddyCoreClasses; import cn.hippo4j.agent.core.plugin.InstrumentDebuggingClass; diff --git a/agent/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 index 868b1c2c86..bdcbcfdc0f 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.bootstrap; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; /** * The log bridge makes the ILog accessible inside bootstrap classloader, especially for internal interceptor. diff --git a/agent/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 index 8341772c23..fd653f6091 100644 --- a/agent/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 @@ -17,12 +17,13 @@ package cn.hippo4j.agent.core.plugin.bytebuddy; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; import cn.hippo4j.agent.core.boot.AgentPackagePath; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.util.FileUtils; import cn.hippo4j.agent.core.util.IOUtils; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.boot.ClassCacheMode; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.agent.builder.ResettableClassFileTransformer; import net.bytebuddy.utility.RandomString; diff --git a/agent/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 index 70dddbadb2..5790f80ce2 100644 --- a/agent/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 @@ -17,8 +17,6 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.AbstractClassEnhancePluginDefine; import cn.hippo4j.agent.core.plugin.EnhanceContext; import cn.hippo4j.agent.core.plugin.PluginException; @@ -31,6 +29,8 @@ import cn.hippo4j.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point; import cn.hippo4j.agent.core.plugin.interceptor.v2.StaticMethodsInterceptV2Point; import cn.hippo4j.agent.core.util.StringUtil; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.dynamic.DynamicType; diff --git a/agent/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 index d5b24c1d6c..7896eb22e0 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.PluginException; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; import net.bytebuddy.implementation.bind.annotation.AllArguments; diff --git a/agent/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 index 489c54d3e2..1d5dd6c1c0 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.PluginException; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; import net.bytebuddy.implementation.bind.annotation.AllArguments; diff --git a/agent/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 index 5febdb8310..57bc744442 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.PluginException; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; import net.bytebuddy.implementation.bind.annotation.AllArguments; diff --git a/agent/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 index 3be9ccbab1..0a98c7de57 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; import net.bytebuddy.implementation.bind.annotation.AllArguments; import net.bytebuddy.implementation.bind.annotation.Origin; diff --git a/agent/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 index 99f83a17b3..e7c11a7fb5 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; import net.bytebuddy.implementation.bind.annotation.AllArguments; import net.bytebuddy.implementation.bind.annotation.Morph; diff --git a/agent/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 index 3967736a4f..eea316d00b 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance.v2; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.PluginException; import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; diff --git a/agent/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 index f9cd51d609..9aaa9888ac 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance.v2; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.PluginException; import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance; import cn.hippo4j.agent.core.plugin.interceptor.enhance.OverrideCallable; diff --git a/agent/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 index 9778577098..7bd4c2f184 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance.v2; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; import net.bytebuddy.implementation.bind.annotation.AllArguments; import net.bytebuddy.implementation.bind.annotation.Origin; diff --git a/agent/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 index 467af26a05..ca86bf2ec1 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.interceptor.enhance.v2; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.interceptor.enhance.OverrideCallable; import cn.hippo4j.agent.core.plugin.loader.InterceptorInstanceLoader; import net.bytebuddy.implementation.bind.annotation.AllArguments; diff --git a/agent/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 index 1ff3514ee4..07c69b5485 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.jdk9module; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.ByteBuddyCoreClasses; import net.bytebuddy.agent.builder.AgentBuilder; diff --git a/agent/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 index 3fec67cc41..d227ec7e17 100644 --- a/agent/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 @@ -17,16 +17,16 @@ package cn.hippo4j.agent.core.plugin.loader; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; import cn.hippo4j.agent.core.boot.AgentPackagePath; import cn.hippo4j.agent.core.boot.PluginConfig; -import cn.hippo4j.agent.core.boot.SpringBootConfigNode; import cn.hippo4j.agent.core.boot.SpringBootConfigInitializer; -import cn.hippo4j.agent.core.conf.Config; +import cn.hippo4j.agent.core.boot.SpringBootConfigNode; import cn.hippo4j.agent.core.conf.SnifferConfigInitializer; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.PluginBootstrap; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import lombok.RequiredArgsConstructor; import java.io.BufferedInputStream; @@ -62,7 +62,7 @@ public class AgentClassLoader extends ClassLoader { private static AgentClassLoader DEFAULT_LOADER; private List classpath; - private List allJars; + private static List allJars; private ReentrantLock jarScanLock = new ReentrantLock(); public static AgentClassLoader getDefault() { @@ -192,7 +192,6 @@ private List getAllJars() { jarScanLock.unlock(); } } - return allJars; } diff --git a/agent/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 index cd1e03520d..e5c55ad46a 100644 --- a/agent/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 @@ -17,7 +17,7 @@ package cn.hippo4j.agent.core.plugin.loader; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; import java.util.HashMap; import java.util.Map; diff --git a/agent/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 index d0ec36cb55..7a02b30027 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.plugin.match; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import net.bytebuddy.matcher.ElementMatcher; /** diff --git a/agent/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 index 4912936bfe..f4aebf8a01 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.util; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import java.lang.reflect.Array; import java.lang.reflect.Field; diff --git a/agent/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 index 7a597187fd..e605e1ad15 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.util; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import java.lang.reflect.Field; diff --git a/agent/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 index e6fed965c6..105a5274c6 100644 --- a/agent/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 @@ -17,8 +17,8 @@ package cn.hippo4j.agent.core.util; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import java.lang.reflect.Field; import java.lang.reflect.Modifier; diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java index 777194f0f4..dcee872618 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java @@ -18,8 +18,8 @@ package cn.hippo4j.agent.plugin.spring.boot.v1.interceptor; import cn.hippo4j.agent.adapter.dubbo.DubboThreadPoolAdapter; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance; import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import cn.hippo4j.agent.core.plugin.interceptor.enhance.MethodInterceptResult; diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java index bcda15e4b5..6f70bf237c 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/DynamicThreadPoolChangeHandlerSpring2x.java @@ -17,8 +17,8 @@ package cn.hippo4j.agent.plugin.spring.boot.v2; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.plugin.spring.common.conf.SpringBootConfig; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.threadpool.dynamic.mode.config.refresher.AbstractConfigThreadPoolDynamicRefresh; diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/boot/SpringBootV2PluginBootService.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/boot/SpringBootV2PluginBootService.java index c9b8c85bb1..d4763704cd 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/boot/SpringBootV2PluginBootService.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/boot/SpringBootV2PluginBootService.java @@ -19,8 +19,8 @@ import cn.hippo4j.agent.core.boot.BootService; import cn.hippo4j.agent.core.boot.DefaultImplementor; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; /** * SpringBoot v1 plugin boot service diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java index 0718469249..d9df47722e 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java @@ -17,8 +17,8 @@ package cn.hippo4j.agent.plugin.spring.boot.v2.interceptor; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance; import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import cn.hippo4j.agent.core.plugin.interceptor.enhance.MethodInterceptResult; diff --git a/agent/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 index bebfb843a8..8b215ec0bc 100644 --- a/agent/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 @@ -18,8 +18,8 @@ package cn.hippo4j.agent.plugin.spring.common.support; import cn.hippo4j.agent.core.boot.SpringBootConfigInitializer; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.PropertySource; diff --git a/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java b/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java index fb4194c852..fa4424a899 100644 --- a/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java +++ b/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java @@ -17,14 +17,15 @@ package cn.hippo4j.agent.plugin.thread.pool.interceptor; -import cn.hippo4j.agent.core.conf.Config; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance; import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; import cn.hippo4j.agent.core.util.CollectionUtil; import cn.hippo4j.agent.core.util.StringUtil; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; diff --git a/examples/threadpool-example/agent/config-apollo/src/main/resources/bootstrap.properties b/examples/threadpool-example/agent/config-apollo/src/main/resources/bootstrap.properties index 88187c9c8a..d467930f4b 100644 --- a/examples/threadpool-example/agent/config-apollo/src/main/resources/bootstrap.properties +++ b/examples/threadpool-example/agent/config-apollo/src/main/resources/bootstrap.properties @@ -31,3 +31,18 @@ spring.dynamic.thread-pool.check-state-interval=3 spring.dynamic.thread-pool.apollo.namespace=application spring.dynamic.thread-pool.config-file-type=properties +spring.dynamic.thread-pool.executors[0].thread-name-prefix = DynamicThreadPoolConfig#FIELD1 +spring.dynamic.thread-pool.executors[0].core-pool-size = 2 +spring.dynamic.thread-pool.executors[0].thread-pool-id = cn.hippo4j.example.agent.config.apollo.ThreadPoolConfiguration#RUN_MESSAGE_SEND_TASK_EXECUTOR +spring.dynamic.thread-pool.executors[0].maximum-pool-size = 20 +spring.dynamic.thread-pool.executors[0].queue-capacity = 1024 +spring.dynamic.thread-pool.executors[0].blocking-queue = ResizableCapacityLinkedBlockingQueue +spring.dynamic.thread-pool.executors[0].execute-time-out = 800 +spring.dynamic.thread-pool.executors[0].rejected-handler = AbortPolicy +spring.dynamic.thread-pool.executors[0].keep-alive-time = 6691 +spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out = true +spring.dynamic.thread-pool.executors[0].alarm = true +spring.dynamic.thread-pool.executors[0].active-alarm = 80 +spring.dynamic.thread-pool.executors[0].capacity-alarm = 80 +spring.dynamic.thread-pool.executors[0].notify.interval = 8 +spring.dynamic.thread-pool.executors[0].notify.receives = nobodyiam diff --git a/infra/common/pom.xml b/infra/common/pom.xml index 20f67cbb08..607b5cafa0 100644 --- a/infra/common/pom.xml +++ b/infra/common/pom.xml @@ -10,6 +10,12 @@ hippo4j-threadpool-infra-common + + com.google.code.gson + gson + ${gson.version} + provided + com.fasterxml.jackson.core jackson-databind diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackageNotFoundException.java b/infra/common/src/main/java/cn/hippo4j/common/boot/AgentPackageNotFoundException.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackageNotFoundException.java rename to infra/common/src/main/java/cn/hippo4j/common/boot/AgentPackageNotFoundException.java index e26aae8a72..273d47e6ae 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/AgentPackageNotFoundException.java +++ b/infra/common/src/main/java/cn/hippo4j/common/boot/AgentPackageNotFoundException.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.boot; +package cn.hippo4j.common.boot; public class AgentPackageNotFoundException extends Exception { diff --git a/infra/common/src/main/java/cn/hippo4j/common/boot/AgentPackagePath.java b/infra/common/src/main/java/cn/hippo4j/common/boot/AgentPackagePath.java new file mode 100644 index 0000000000..1afbdfb750 --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/boot/AgentPackagePath.java @@ -0,0 +1,85 @@ +/* + * 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.common.boot; + +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; + +/** + * AgentPackagePath is a flag and finder to locate the Hippo4j agent.jar. It gets the absolute path of the agent jar. + * The path is the required metadata for agent core looking up the plugins and toolkit activations. If the lookup + * mechanism fails, the agent will exit directly. + */ +public class AgentPackagePath { + + private static final ILog LOGGER = LogManager.getLogger(AgentPackagePath.class); + + private static File AGENT_PACKAGE_PATH; + + public static File getPath() throws AgentPackageNotFoundException { + if (AGENT_PACKAGE_PATH == null) { + AGENT_PACKAGE_PATH = findPath(); + } + return AGENT_PACKAGE_PATH; + } + + public static boolean isPathFound() { + return AGENT_PACKAGE_PATH != null; + } + + private static File findPath() throws AgentPackageNotFoundException { + String classResourcePath = AgentPackagePath.class.getName().replaceAll("\\.", "/") + ".class"; + + URL resource = ClassLoader.getSystemClassLoader().getResource(classResourcePath); + if (resource != null) { + String urlString = resource.toString(); + + LOGGER.debug("The beacon class location is {}.", urlString); + + int insidePathIndex = urlString.indexOf('!'); + boolean isInJar = insidePathIndex > -1; + + if (isInJar) { + urlString = urlString.substring(urlString.indexOf("file:"), insidePathIndex); + File agentJarFile = null; + try { + agentJarFile = new File(new URL(urlString).toURI()); + } catch (MalformedURLException | URISyntaxException e) { + LOGGER.error(e, "Can not locate agent jar file by url:" + urlString); + } + if (agentJarFile.exists()) { + return agentJarFile.getParentFile(); + } + } else { + int prefixLength = "file:".length(); + String classLocation = urlString.substring( + prefixLength, urlString.length() - classResourcePath.length()); + return new File(classLocation); + } + } + + LOGGER.error("Can not locate agent jar file."); + throw new AgentPackageNotFoundException("Can not locate agent jar file."); + } + +} diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ClassCacheMode.java b/infra/common/src/main/java/cn/hippo4j/common/boot/ClassCacheMode.java similarity index 90% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ClassCacheMode.java rename to infra/common/src/main/java/cn/hippo4j/common/boot/ClassCacheMode.java index d5baf606ca..5db729f50e 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/plugin/bytebuddy/ClassCacheMode.java +++ b/infra/common/src/main/java/cn/hippo4j/common/boot/ClassCacheMode.java @@ -15,11 +15,8 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.plugin.bytebuddy; +package cn.hippo4j.common.boot; -/** - * ByteBuddy class cache mode - */ public enum ClassCacheMode { FILE, MEMORY -} +} \ No newline at end of file diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultNamedThreadFactory.java b/infra/common/src/main/java/cn/hippo4j/common/boot/DefaultNamedThreadFactory.java similarity index 97% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultNamedThreadFactory.java rename to infra/common/src/main/java/cn/hippo4j/common/boot/DefaultNamedThreadFactory.java index 41c41204bc..1bbe203ce6 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/DefaultNamedThreadFactory.java +++ b/infra/common/src/main/java/cn/hippo4j/common/boot/DefaultNamedThreadFactory.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.boot; +package cn.hippo4j.common.boot; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java b/infra/common/src/main/java/cn/hippo4j/common/conf/Config.java old mode 100755 new mode 100644 similarity index 95% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java rename to infra/common/src/main/java/cn/hippo4j/common/conf/Config.java index 89e1c57794..8503055444 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java +++ b/infra/common/src/main/java/cn/hippo4j/common/conf/Config.java @@ -15,14 +15,13 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.conf; - -import cn.hippo4j.agent.core.logging.core.LogLevel; -import cn.hippo4j.agent.core.logging.core.LogOutput; -import cn.hippo4j.agent.core.logging.core.ResolverType; -import cn.hippo4j.agent.core.logging.core.WriterFactory; -import cn.hippo4j.agent.core.plugin.bytebuddy.ClassCacheMode; -import cn.hippo4j.agent.core.util.Length; +package cn.hippo4j.common.conf; + +import cn.hippo4j.common.boot.ClassCacheMode; +import cn.hippo4j.common.logging.core.LogLevel; +import cn.hippo4j.common.logging.core.LogOutput; +import cn.hippo4j.common.logging.core.ResolverType; +import cn.hippo4j.common.toolkit.agent.Length; import java.util.Arrays; import java.util.List; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/ConfigNotFoundException.java b/infra/common/src/main/java/cn/hippo4j/common/conf/ConfigNotFoundException.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/ConfigNotFoundException.java rename to infra/common/src/main/java/cn/hippo4j/common/conf/ConfigNotFoundException.java index 9d7d387c59..b32bd864c0 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/ConfigNotFoundException.java +++ b/infra/common/src/main/java/cn/hippo4j/common/conf/ConfigNotFoundException.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.conf; +package cn.hippo4j.common.conf; public class ConfigNotFoundException extends Exception { diff --git a/infra/common/src/main/java/cn/hippo4j/common/conf/Constants.java b/infra/common/src/main/java/cn/hippo4j/common/conf/Constants.java new file mode 100644 index 0000000000..1973cebe9b --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/conf/Constants.java @@ -0,0 +1,39 @@ +/* + * 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.common.conf; + +public class Constants { + + public static String PATH_SEPARATOR = System.getProperty("file.separator", "/"); + + public static String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); + + public static String EMPTY_STRING = ""; + + public static char SERVICE_NAME_PART_CONNECTOR = '|'; + + // The name of the layer that represents agent-installed services, + // which is defined at + // https://github.com/apache/skywalking/blob/85ce1645be53e46286f36c0ea206c60db2d1a716/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/Layer.java#L30 + public static String EVENT_LAYER_NAME = "GENERAL"; + + public static int NULL_VALUE = 0; + + public static boolean IS_INIT_COMPLETED = false; + +} diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/RuntimeContextConfiguration.java b/infra/common/src/main/java/cn/hippo4j/common/conf/RuntimeContextConfiguration.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/RuntimeContextConfiguration.java rename to infra/common/src/main/java/cn/hippo4j/common/conf/RuntimeContextConfiguration.java index 0864baa0e2..372492eb92 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/RuntimeContextConfiguration.java +++ b/infra/common/src/main/java/cn/hippo4j/common/conf/RuntimeContextConfiguration.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.conf; +package cn.hippo4j.common.conf; public class RuntimeContextConfiguration { diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/ILog.java b/infra/common/src/main/java/cn/hippo4j/common/logging/api/ILog.java similarity index 97% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/ILog.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/api/ILog.java index 89f1031f97..3bb9cba0ec 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/ILog.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/api/ILog.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.api; +package cn.hippo4j.common.logging.api; /** * The Log interface. It's very easy to understand, like any other log-component. Do just like log4j or log4j2 does. diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogManager.java b/infra/common/src/main/java/cn/hippo4j/common/logging/api/LogManager.java similarity index 95% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogManager.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/api/LogManager.java index cb6514bc68..3c72d7ef4b 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogManager.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/api/LogManager.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.api; +package cn.hippo4j.common.logging.api; -import cn.hippo4j.agent.core.logging.core.PatternLogResolver; +import cn.hippo4j.common.logging.core.PatternLogResolver; /** * LogManager is the {@link LogResolver} implementation manager. By using {@link LogResolver}, {@link diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogResolver.java b/infra/common/src/main/java/cn/hippo4j/common/logging/api/LogResolver.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogResolver.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/api/LogResolver.java index 4f145dbb7a..a6cf32a03b 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/LogResolver.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/api/LogResolver.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.api; +package cn.hippo4j.common.logging.api; /** * {@link LogResolver} just do only one thing: return the {@link ILog} implementation. diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/NoopLogger.java b/infra/common/src/main/java/cn/hippo4j/common/logging/api/NoopLogger.java similarity index 98% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/NoopLogger.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/api/NoopLogger.java index 9f544b63a4..99bc3db7f7 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/api/NoopLogger.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/api/NoopLogger.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.api; +package cn.hippo4j.common.logging.api; /** * No operation logger implementation. Just implement {@link ILog} interface, but do nothing. diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/AbstractLogger.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/AbstractLogger.java similarity index 91% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/AbstractLogger.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/AbstractLogger.java index 05a53ff08b..c67121c776 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/AbstractLogger.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/AbstractLogger.java @@ -15,17 +15,11 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; - -import cn.hippo4j.agent.core.conf.Config; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.core.converters.AgentNameConverter; -import cn.hippo4j.agent.core.logging.core.converters.ClassConverter; -import cn.hippo4j.agent.core.logging.core.converters.DateConverter; -import cn.hippo4j.agent.core.logging.core.converters.LevelConverter; -import cn.hippo4j.agent.core.logging.core.converters.MessageConverter; -import cn.hippo4j.agent.core.logging.core.converters.ThreadConverter; -import cn.hippo4j.agent.core.logging.core.converters.ThrowableConverter; +package cn.hippo4j.common.logging.core; + +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.core.converters.*; import java.util.ArrayList; import java.util.HashMap; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Converter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/Converter.java similarity index 95% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Converter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/Converter.java index 0bf8d9795e..27dd8981b5 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Converter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/Converter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; /** * The Converter, it is used to convert the LogEvent to the String. diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/FileWriter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/FileWriter.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/FileWriter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/FileWriter.java index e2fde3087e..72397d7170 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/FileWriter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/FileWriter.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; -import cn.hippo4j.agent.core.boot.DefaultNamedThreadFactory; -import cn.hippo4j.agent.core.conf.Config; -import cn.hippo4j.agent.core.conf.Constants; -import cn.hippo4j.agent.core.util.RunnableWithExceptionProtection; +import cn.hippo4j.common.boot.DefaultNamedThreadFactory; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.constant.Constants; +import cn.hippo4j.common.toolkit.agent.RunnableWithExceptionProtection; import java.io.File; import java.io.FileNotFoundException; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/IWriter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/IWriter.java similarity index 95% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/IWriter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/IWriter.java index 1dae6b82d1..d0acc94f9f 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/IWriter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/IWriter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; public interface IWriter { diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogResolver.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/JsonLogResolver.java similarity index 88% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogResolver.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/JsonLogResolver.java index 913bc770c4..befbdc9a1d 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogResolver.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/JsonLogResolver.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogResolver; +import cn.hippo4j.common.logging.api.LogResolver; +import cn.hippo4j.common.logging.api.ILog; import com.google.gson.Gson; public class JsonLogResolver implements LogResolver { diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogger.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/JsonLogger.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogger.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/JsonLogger.java index fc657ef1ea..001684dffe 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/JsonLogger.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/JsonLogger.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; -import cn.hippo4j.agent.core.logging.core.converters.LiteralConverter; +import cn.hippo4j.common.logging.core.converters.LiteralConverter; import com.google.gson.Gson; import java.util.HashMap; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogEvent.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogEvent.java similarity index 97% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogEvent.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/LogEvent.java index 1246232d1b..a0aa11ab68 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogEvent.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogEvent.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; /** * The representation of logging events. This instance is pass around to the List of Converter. diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogLevel.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogLevel.java similarity index 95% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogLevel.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/LogLevel.java index facc35b317..73791af9a2 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogLevel.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogLevel.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; public enum LogLevel { TRACE, DEBUG, INFO, WARN, ERROR, OFF diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogMessageHolder.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogMessageHolder.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogMessageHolder.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/LogMessageHolder.java index 244733b57d..005d2d4d87 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogMessageHolder.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogMessageHolder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; /** * The LogMessageHolder is a {@link String} holder, in order to in-process propagation String across the diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogOutput.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogOutput.java similarity index 95% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogOutput.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/LogOutput.java index 2bf279a841..c8ba7bc269 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/LogOutput.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/LogOutput.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; public enum LogOutput { FILE, CONSOLE diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Parser.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/Parser.java similarity index 98% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Parser.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/Parser.java index 999b78f7ca..24cabc4a0c 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/Parser.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/Parser.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; -import cn.hippo4j.agent.core.logging.core.converters.LiteralConverter; +import cn.hippo4j.common.logging.core.converters.LiteralConverter; import java.util.ArrayList; import java.util.List; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogResolver.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/PatternLogResolver.java similarity index 85% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogResolver.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/PatternLogResolver.java index 075c2e01a2..0a761683a5 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogResolver.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/PatternLogResolver.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; -import cn.hippo4j.agent.core.conf.Config; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.logging.api.LogResolver; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.logging.api.LogResolver; +import cn.hippo4j.common.logging.api.ILog; public class PatternLogResolver implements LogResolver { diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogger.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/PatternLogger.java similarity index 94% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogger.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/PatternLogger.java index b9e4ef67d0..c713bb5abd 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/PatternLogger.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/PatternLogger.java @@ -15,10 +15,9 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; -import cn.hippo4j.agent.core.logging.api.ILog; -import cn.hippo4j.agent.core.util.StringUtil; +import cn.hippo4j.common.toolkit.StringUtil; /** * A flexible Logger configurable with pattern string. This is default implementation of {@link ILog} This can parse a diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/ResolverType.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/ResolverType.java similarity index 95% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/ResolverType.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/ResolverType.java index 734d9294fc..774cb310ab 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/ResolverType.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/ResolverType.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; public enum ResolverType { JSON, PATTERN diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/SystemOutWriter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/SystemOutWriter.java similarity index 96% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/SystemOutWriter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/SystemOutWriter.java index e4cce11990..312d8fd2e0 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/SystemOutWriter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/SystemOutWriter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; import java.io.PrintStream; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/WriterFactory.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/WriterFactory.java similarity index 78% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/WriterFactory.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/WriterFactory.java index 72f2ddeee4..4bf5331b1a 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/WriterFactory.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/WriterFactory.java @@ -15,14 +15,13 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core; +package cn.hippo4j.common.logging.core; -import cn.hippo4j.agent.core.boot.AgentPackageNotFoundException; -import cn.hippo4j.agent.core.boot.AgentPackagePath; -import cn.hippo4j.agent.core.conf.Config; -import cn.hippo4j.agent.core.conf.SnifferConfigInitializer; -import cn.hippo4j.agent.core.plugin.PluginFinder; -import cn.hippo4j.agent.core.util.StringUtil; +import cn.hippo4j.common.boot.AgentPackageNotFoundException; +import cn.hippo4j.common.boot.AgentPackagePath; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.conf.Constants; +import cn.hippo4j.common.toolkit.StringUtil; public class WriterFactory { @@ -35,8 +34,7 @@ public static IWriter getLogWriter() { if (WRITER != null) { return WRITER; } - if (SnifferConfigInitializer.isInitCompleted() - && PluginFinder.isPluginInitCompleted() + if (Constants.IS_INIT_COMPLETED && AgentPackagePath.isPathFound()) { if (StringUtil.isEmpty(Config.Logging.DIR)) { try { diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/AgentNameConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/AgentNameConverter.java similarity index 83% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/AgentNameConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/AgentNameConverter.java index 21090d2574..d6015b2179 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/AgentNameConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/AgentNameConverter.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.conf.Config; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.conf.Config; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; public class AgentNameConverter implements Converter { diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ClassConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ClassConverter.java similarity index 87% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ClassConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ClassConverter.java index 5dc9951dbf..96dbcdc294 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ClassConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ClassConverter.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; /** * Just return logEvent.getTargetClass(). diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/DateConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/DateConverter.java similarity index 88% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/DateConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/DateConverter.java index e3a68067fb..f18da36b24 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/DateConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/DateConverter.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; import java.text.SimpleDateFormat; import java.util.Date; diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LevelConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/LevelConverter.java similarity index 87% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LevelConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/LevelConverter.java index 775c97ce78..ff818c18a7 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LevelConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/LevelConverter.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; /** * Just return logEvent.getLevel().name() diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LiteralConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/LiteralConverter.java similarity index 88% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LiteralConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/LiteralConverter.java index bd334955a9..58bb473442 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/LiteralConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/LiteralConverter.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; /** * This Converter is used to return the literal. diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/MessageConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/MessageConverter.java similarity index 87% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/MessageConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/MessageConverter.java index a38cc3c7c7..fc15990fd9 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/MessageConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/MessageConverter.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; /** * Just return the logEvent.getMessage() diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThreadConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ThreadConverter.java similarity index 87% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThreadConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ThreadConverter.java index 7bd6b16fdd..a22e16dfd1 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThreadConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ThreadConverter.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; /** * Just return the Thread.currentThread().getName() diff --git a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThrowableConverter.java b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ThrowableConverter.java similarity index 88% rename from agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThrowableConverter.java rename to infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ThrowableConverter.java index 8d307f0ad8..3bab6e2b9c 100644 --- a/agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/logging/core/converters/ThrowableConverter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/logging/core/converters/ThrowableConverter.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package cn.hippo4j.agent.core.logging.core.converters; +package cn.hippo4j.common.logging.core.converters; -import cn.hippo4j.agent.core.conf.Constants; -import cn.hippo4j.agent.core.logging.core.Converter; -import cn.hippo4j.agent.core.logging.core.LogEvent; +import cn.hippo4j.common.constant.Constants; +import cn.hippo4j.common.logging.core.Converter; +import cn.hippo4j.common.logging.core.LogEvent; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/infra/common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java b/infra/common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java index 7c74e2cc3a..d85065068e 100644 --- a/infra/common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java +++ b/infra/common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java @@ -390,4 +390,69 @@ private static boolean containsText(CharSequence str) { } return false; } + + public static String join(final char delimiter, final String... strings) { + if (strings.length == 0) { + return null; + } + if (strings.length == 1) { + return strings[0]; + } + int length = strings.length - 1; + for (final String s : strings) { + if (s == null) { + continue; + } + length += s.length(); + } + final StringBuilder sb = new StringBuilder(length); + if (strings[0] != null) { + sb.append(strings[0]); + } + for (int i = 1; i < strings.length; ++i) { + if (!isEmpty(strings[i])) { + sb.append(delimiter).append(strings[i]); + } else { + sb.append(delimiter); + } + } + return sb.toString(); + } + + public static boolean substringMatch(CharSequence str, int index, CharSequence substring) { + if (index + substring.length() > str.length()) { + return false; + } + for (int i = 0; i < substring.length(); i++) { + if (str.charAt(index + i) != substring.charAt(i)) { + return false; + } + } + return true; + } + + public static String cut(String str, int threshold) { + if (isEmpty(str) || str.length() <= threshold) { + return str; + } + return str.substring(0, threshold); + } + + public static String trim(final String str, final char ch) { + if (isEmpty(str)) { + return null; + } + + final char[] chars = str.toCharArray(); + + int i = 0, j = chars.length - 1; + // noinspection StatementWithEmptyBody + for (; i < chars.length && chars[i] == ch; i++) { + } + // noinspection StatementWithEmptyBody + for (; j > 0 && chars[j] == ch; j--) { + } + + return new String(chars, i, j - i + 1); + } } diff --git a/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/ConfigInitializer.java b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/ConfigInitializer.java new file mode 100644 index 0000000000..d1b250e9e9 --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/ConfigInitializer.java @@ -0,0 +1,210 @@ +/* + * 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.common.toolkit.agent; + +import cn.hippo4j.common.toolkit.StringUtil; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.*; + +/** + * Init a class's static fields by a {@link Properties}, including static fields and static inner classes. + *

+ */ +public class ConfigInitializer { + + public static void initialize(Properties properties, Class rootConfigType) throws IllegalAccessException { + initNextLevel(properties, rootConfigType, new ConfigDesc(), false); + } + + public static void initialize(Properties properties, Class rootConfigType, boolean isSpringProperties) throws IllegalAccessException { + initNextLevel(properties, rootConfigType, new ConfigDesc(), isSpringProperties); + } + + private static void initNextLevel(Properties properties, Class recentConfigType, + ConfigDesc parentDesc, boolean isSpringProperties) throws IllegalArgumentException, IllegalAccessException { + for (Field field : recentConfigType.getFields()) { + if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) { + String configKey = (parentDesc + "." + (isSpringProperties ? field.getName().replace("_", "-") : field.getName())).toLowerCase(); + Class type = field.getType(); + + if (type.equals(Map.class)) { + /* + * Map config format is, config_key[map_key]=map_value Such as plugin.opgroup.resttemplate.rule[abc]=/url/path + */ + // Deduct two generic types of the map + ParameterizedType genericType = (ParameterizedType) field.getGenericType(); + Type[] argumentTypes = genericType.getActualTypeArguments(); + + Type keyType = null; + Type valueType = null; + if (argumentTypes != null && argumentTypes.length == 2) { + // Get key type and value type of the map + keyType = argumentTypes[0]; + valueType = argumentTypes[1]; + } + Map map = (Map) field.get(null); + // Set the map from config key and properties + setForMapType(configKey, map, properties, keyType, valueType); + } else { + /* + * Others typical field type + */ + String value = properties.getProperty(configKey); + // Convert the value into real type + final Length lengthDefine = field.getAnnotation(Length.class); + if (lengthDefine != null) { + if (value != null && value.length() > lengthDefine.value()) { + value = value.substring(0, lengthDefine.value()); + } + } + Object convertedValue = convertToTypicalType(type, value); + if (convertedValue != null) { + field.set(null, convertedValue); + } + } + } + } + for (Class innerConfiguration : recentConfigType.getClasses()) { + String simpleName = innerConfiguration.getSimpleName(); + String description = isSpringProperties ? simpleName.replace("_", "-") : simpleName; + parentDesc.append(description); + initNextLevel(properties, innerConfiguration, parentDesc, isSpringProperties); + parentDesc.removeLastDesc(); + } + } + + /** + * Convert string value to typical type. + * + * @param type type to convert + * @param value string value to be converted + * @return converted value or null + */ + private static Object convertToTypicalType(Type type, String value) { + if (value == null || type == null) { + return null; + } + + Object result = null; + if (String.class.equals(type)) { + result = value; + } else if (int.class.equals(type) || Integer.class.equals(type)) { + result = Integer.valueOf(value); + } else if (long.class.equals(type) || Long.class.equals(type)) { + result = Long.valueOf(value); + } else if (boolean.class.equals(type) || Boolean.class.equals(type)) { + result = Boolean.valueOf(value); + } else if (float.class.equals(type) || Float.class.equals(type)) { + result = Float.valueOf(value); + } else if (double.class.equals(type) || Double.class.equals(type)) { + result = Double.valueOf(value); + } else if (List.class.equals(type)) { + result = convert2List(value); + } else if (type instanceof Class) { + Class clazz = (Class) type; + if (clazz.isEnum()) { + result = Enum.valueOf((Class) type, value.toUpperCase()); + } + } + return result; + } + + /** + * Set map items. + * + * @param configKey config key must not be null + * @param map map to set must not be null + * @param properties properties must not be null + * @param keyType key type of the map + * @param valueType value type of the map + */ + private static void setForMapType(String configKey, Map map, Properties properties, + final Type keyType, final Type valueType) { + + Objects.requireNonNull(configKey); + Objects.requireNonNull(map); + Objects.requireNonNull(properties); + + String prefix = configKey + "["; + String suffix = "]"; + + properties.forEach((propertyKey, propertyValue) -> { + String propertyStringKey = propertyKey.toString(); + if (propertyStringKey.startsWith(prefix) && propertyStringKey.endsWith(suffix)) { + String itemKey = propertyStringKey.substring( + prefix.length(), propertyStringKey.length() - suffix.length()); + Object keyObj; + Object valueObj; + + keyObj = convertToTypicalType(keyType, itemKey); + valueObj = convertToTypicalType(valueType, propertyValue.toString()); + + if (keyObj == null) { + keyObj = itemKey; + } + + if (valueObj == null) { + valueObj = propertyValue; + } + + map.put(keyObj, valueObj); + } + }); + } + + private static List convert2List(String value) { + if (StringUtil.isEmpty(value)) { + return Collections.emptyList(); + } + List result = new LinkedList<>(); + + String[] segments = value.split(","); + for (String segment : segments) { + String trimmedSegment = segment.trim(); + if (StringUtil.isNotEmpty(trimmedSegment)) { + result.add(trimmedSegment); + } + } + return result; + } + +} + +class ConfigDesc { + + private LinkedList descs = new LinkedList<>(); + + void append(String currentDesc) { + if (StringUtil.isNotEmpty(currentDesc)) { + descs.addLast(currentDesc); + } + } + + void removeLastDesc() { + descs.removeLast(); + } + + @Override + public String toString() { + return String.join(".", descs); + } +} diff --git a/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/Length.java b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/Length.java new file mode 100644 index 0000000000..f926a9da7f --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/Length.java @@ -0,0 +1,33 @@ +/* + * 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.common.toolkit.agent; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The length rule of the target field. + */ +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Length { + + int value(); +} diff --git a/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/PlaceholderConfigurerSupport.java b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/PlaceholderConfigurerSupport.java new file mode 100644 index 0000000000..df6d59ec9a --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/PlaceholderConfigurerSupport.java @@ -0,0 +1,37 @@ +/* + * 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.common.toolkit.agent; + +public class PlaceholderConfigurerSupport { + + /** + * Default placeholder prefix: {@value} + */ + public static final String DEFAULT_PLACEHOLDER_PREFIX = "${"; + + /** + * Default placeholder suffix: {@value} + */ + public static final String DEFAULT_PLACEHOLDER_SUFFIX = "}"; + + /** + * Default value separator: {@value} + */ + public static final String DEFAULT_VALUE_SEPARATOR = ":"; + +} diff --git a/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/PropertyPlaceholderHelper.java b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/PropertyPlaceholderHelper.java new file mode 100644 index 0000000000..8d945584e0 --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/PropertyPlaceholderHelper.java @@ -0,0 +1,210 @@ +/* + * 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.common.toolkit.agent; + +import cn.hippo4j.common.toolkit.StringUtil; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +/** + * Utility class for working with Strings that have placeholder values in them. A placeholder takes the form {@code + * ${name}}. Using {@code PropertyPlaceholderHelper} these placeholders can be substituted for user-supplied values.

+ * Values for substitution can be supplied using a {@link Properties} instance or using a {@link PlaceholderResolver}. + */ +public enum PropertyPlaceholderHelper { + + INSTANCE( + PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX, + PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX, PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, + true); + + private final String placeholderPrefix; + + private final String placeholderSuffix; + + private final String simplePrefix; + + private final String valueSeparator; + + private final boolean ignoreUnresolvablePlaceholders; + + /** + * Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix. + * + * @param placeholderPrefix the prefix that denotes the start of a placeholder + * @param placeholderSuffix the suffix that denotes the end of a placeholder + * @param valueSeparator the separating character between the placeholder variable and the + * associated default value, if any + * @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should be ignored ({@code + * true}) or cause an exception ({@code false}) + */ + PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix, String valueSeparator, + boolean ignoreUnresolvablePlaceholders) { + if (StringUtil.isEmpty(placeholderPrefix) || StringUtil.isEmpty(placeholderSuffix)) { + throw new UnsupportedOperationException("'placeholderPrefix or placeholderSuffix' must not be null"); + } + + final Map wellKnownSimplePrefixes = new HashMap(4); + + wellKnownSimplePrefixes.put("}", "{"); + wellKnownSimplePrefixes.put("]", "["); + wellKnownSimplePrefixes.put(")", "("); + + this.placeholderPrefix = placeholderPrefix; + this.placeholderSuffix = placeholderSuffix; + String simplePrefixForSuffix = wellKnownSimplePrefixes.get(this.placeholderSuffix); + if (simplePrefixForSuffix != null && this.placeholderPrefix.endsWith(simplePrefixForSuffix)) { + this.simplePrefix = simplePrefixForSuffix; + } else { + this.simplePrefix = this.placeholderPrefix; + } + this.valueSeparator = valueSeparator; + this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders; + } + + /** + * Replaces all placeholders of format {@code ${name}} with the corresponding property from the supplied {@link + * Properties}. + * + * @param value the value containing the placeholders to be replaced + * @param properties the {@code Properties} to use for replacement + * @return the supplied value with placeholders replaced inline + */ + public String replacePlaceholders(String value, final Properties properties) { + return replacePlaceholders(value, new PlaceholderResolver() { + + @Override + public String resolvePlaceholder(String placeholderName) { + return getConfigValue(placeholderName, properties); + } + }); + } + + private String getConfigValue(String key, final Properties properties) { + String value = System.getProperty(key); + if (value == null) { + value = System.getenv(key); + } + if (value == null) { + value = properties.getProperty(key); + } + return value; + } + + /** + * Replaces all placeholders of format {@code ${name}} with the value returned from the supplied {@link + * PlaceholderResolver}. + * + * @param value the value containing the placeholders to be replaced + * @param placeholderResolver the {@code PlaceholderResolver} to use for replacement + * @return the supplied value with placeholders replaced inline + */ + public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) { + return parseStringValue(value, placeholderResolver, new HashSet()); + } + + protected String parseStringValue(String value, PlaceholderResolver placeholderResolver, + Set visitedPlaceholders) { + + StringBuilder result = new StringBuilder(value); + + int startIndex = value.indexOf(this.placeholderPrefix); + while (startIndex != -1) { + int endIndex = findPlaceholderEndIndex(result, startIndex); + if (endIndex != -1) { + String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex); + String originalPlaceholder = placeholder; + if (!visitedPlaceholders.add(originalPlaceholder)) { + throw new IllegalArgumentException( + "Circular placeholder reference '" + originalPlaceholder + "' in property definitions"); + } + // Recursive invocation, parsing placeholders contained in the placeholder key. + placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders); + // Now obtain the value for the fully resolved key... + String propVal = placeholderResolver.resolvePlaceholder(placeholder); + if (propVal == null && this.valueSeparator != null) { + int separatorIndex = placeholder.indexOf(this.valueSeparator); + if (separatorIndex != -1) { + String actualPlaceholder = placeholder.substring(0, separatorIndex); + String defaultValue = placeholder.substring(separatorIndex + this.valueSeparator.length()); + propVal = placeholderResolver.resolvePlaceholder(actualPlaceholder); + if (propVal == null) { + propVal = defaultValue; + } + } + } + if (propVal != null) { + // Recursive invocation, parsing placeholders contained in the + // previously resolved placeholder value. + propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); + result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); + startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length()); + } else if (this.ignoreUnresolvablePlaceholders) { + // Proceed with unprocessed value. + startIndex = result.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length()); + } else { + throw new IllegalArgumentException( + "Could not resolve placeholder '" + placeholder + "'" + " in value \"" + value + "\""); + } + visitedPlaceholders.remove(originalPlaceholder); + } else { + startIndex = -1; + } + } + return result.toString(); + } + + private int findPlaceholderEndIndex(CharSequence buf, int startIndex) { + int index = startIndex + this.placeholderPrefix.length(); + int withinNestedPlaceholder = 0; + while (index < buf.length()) { + if (StringUtil.substringMatch(buf, index, this.placeholderSuffix)) { + if (withinNestedPlaceholder > 0) { + withinNestedPlaceholder--; + index = index + this.placeholderSuffix.length(); + } else { + return index; + } + } else if (StringUtil.substringMatch(buf, index, this.simplePrefix)) { + withinNestedPlaceholder++; + index = index + this.simplePrefix.length(); + } else { + index++; + } + } + return -1; + } + + /** + * Strategy interface used to resolve replacement values for placeholders contained in Strings. + */ + public interface PlaceholderResolver { + + /** + * Resolve the supplied placeholder name to the replacement value. + * + * @param placeholderName the name of the placeholder to resolve + * @return the replacement value, or {@code null} if no replacement is to be made + */ + String resolvePlaceholder(String placeholderName); + } +} diff --git a/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/RunnableWithExceptionProtection.java b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/RunnableWithExceptionProtection.java new file mode 100644 index 0000000000..f4179cf1a7 --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/toolkit/agent/RunnableWithExceptionProtection.java @@ -0,0 +1,43 @@ +/* + * 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.common.toolkit.agent; + +public class RunnableWithExceptionProtection implements Runnable { + + private Runnable run; + private CallbackWhenException callback; + + public RunnableWithExceptionProtection(Runnable run, CallbackWhenException callback) { + this.run = run; + this.callback = callback; + } + + @Override + public void run() { + try { + run.run(); + } catch (Throwable t) { + callback.handle(t); + } + } + + public interface CallbackWhenException { + + void handle(Throwable t); + } +} diff --git a/infra/common/src/test/java/cn/hippo4j/common/toolkit/MessageConvertTest.java b/infra/common/src/test/java/cn/hippo4j/common/toolkit/MessageConvertTest.java index 52470aadb7..4d834dcf1f 100644 --- a/infra/common/src/test/java/cn/hippo4j/common/toolkit/MessageConvertTest.java +++ b/infra/common/src/test/java/cn/hippo4j/common/toolkit/MessageConvertTest.java @@ -18,13 +18,21 @@ package cn.hippo4j.common.toolkit; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; -import cn.hippo4j.common.monitor.*; +import cn.hippo4j.common.monitor.AbstractMessage; +import cn.hippo4j.common.monitor.Message; +import cn.hippo4j.common.monitor.MessageTypeEnum; +import cn.hippo4j.common.monitor.MessageWrapper; +import cn.hippo4j.common.monitor.RuntimeMessage; import org.junit.Test; import org.junit.jupiter.api.Assertions; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /*** * @description : Todo diff --git a/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java b/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java index 7a49151ddc..252e6d0b61 100644 --- a/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java +++ b/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java @@ -24,12 +24,12 @@ import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue; import cn.hippo4j.common.extension.design.Observer; import cn.hippo4j.common.extension.design.ObserverMessage; +import cn.hippo4j.common.logging.api.ILog; +import cn.hippo4j.common.logging.api.LogManager; import cn.hippo4j.common.model.executor.ExecutorProperties; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import lombok.RequiredArgsConstructor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.Objects; @@ -46,7 +46,7 @@ @RequiredArgsConstructor public class DynamicThreadPoolRefreshListener implements Observer { - private static final Logger LOGGER = LoggerFactory.getLogger(DynamicThreadPoolRefreshListener.class); + private static final ILog LOG = LogManager.getLogger(DynamicThreadPoolRefreshListener.class); @Override public void accept(ObserverMessage observerMessage) { @@ -127,15 +127,14 @@ private void dynamicRefreshThreadPool(ThreadPoolExecutorHolder executorHolder, E ResizableCapacityLinkedBlockingQueue queue = (ResizableCapacityLinkedBlockingQueue) executor.getQueue(); queue.setCapacity(properties.getQueueCapacity()); } else { - LOGGER.warn("The queue length cannot be modified. Queue type mismatch. Current queue type: {}", executor.getQueue().getClass().getSimpleName()); + LOG.warn("The queue length cannot be modified. Queue type mismatch. Current queue type: {}", executor.getQueue().getClass().getSimpleName()); } } } private void sendChangeNotificationMessage(ThreadPoolExecutorHolder executorHolder, ExecutorProperties properties) { ExecutorProperties executorProperties = executorHolder.getExecutorProperties(); - // TODO log cannot be printed - LOGGER.info(CHANGE_THREAD_POOL_TEXT, + LOG.info(CHANGE_THREAD_POOL_TEXT, executorHolder.getThreadPoolId(), String.format(CHANGE_DELIMITER, executorProperties.getCorePoolSize(), properties.getCorePoolSize()), String.format(CHANGE_DELIMITER, executorProperties.getMaximumPoolSize(), properties.getMaximumPoolSize()), diff --git a/pom.xml b/pom.xml index d63fbf73ce..6237e82f19 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,7 @@ 2.22.1 3.1.0 2.3.2.RELEASE + 2.8.9