[Enhancement] Log printing failure problem in agent mode (#1513)

* Feature: server add Ldap user authentication

* Fix Server-example Unknown user

* Remove RFC7230Config.class

* Fix Log printing failure problem in agent mode

* Remove import *

* fix: The Gson version dependency in pom under the infra package is provided
dependabot/npm_and_yarn/docs/webpack-5.94.0
Pan_Yujie 3 months ago committed by GitHub
parent 41efe403e0
commit d687133dd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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.PluginFinder;
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;

@ -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;

@ -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;

@ -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;

@ -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.List;
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 <code>SnifferConfigInitializer</code> initializes all configs in several way.
@ -204,7 +206,7 @@ public class SnifferConfigInitializer {
*
* @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);

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -20,9 +20,8 @@ package cn.hippo4j.agent.core.plugin;
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

@ -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;

@ -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.

@ -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;

@ -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.StaticMethodsInterceptPoint;
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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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<File> classpath;
private List<Jar> allJars;
private static List<Jar> allJars;
private ReentrantLock jarScanLock = new ReentrantLock();
public static AgentClassLoader getDefault() {
@ -192,7 +192,6 @@ public class AgentClassLoader extends ClassLoader {
jarScanLock.unlock();
}
}
return allJars;
}

@ -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;

@ -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;
/**

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -19,8 +19,8 @@ package cn.hippo4j.agent.plugin.spring.boot.v2.boot;
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

@ -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;

@ -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;

@ -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;

@ -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

@ -10,6 +10,12 @@
<artifactId>hippo4j-threadpool-infra-common</artifactId>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.agent.core.boot;
package cn.hippo4j.common.boot;
public class AgentPackageNotFoundException extends Exception {

@ -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.");
}
}

@ -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
}
}

@ -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;

@ -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;

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.agent.core.conf;
package cn.hippo4j.common.conf;
public class ConfigNotFoundException extends Exception {

@ -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;
}

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.agent.core.conf;
package cn.hippo4j.common.conf;
public class RuntimeContextConfiguration {

@ -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.

@ -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

@ -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.

@ -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.

@ -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;

@ -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.

@ -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;

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.agent.core.logging.core;
package cn.hippo4j.common.logging.core;
public interface IWriter {

@ -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 {

@ -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;

@ -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.

@ -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

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.agent.core.logging.core;
package cn.hippo4j.common.logging.core;
/**
* The <code>LogMessageHolder</code> is a {@link String} holder, in order to in-process propagation String across the

@ -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

@ -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;

@ -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 {

@ -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

@ -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

@ -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;

@ -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 class WriterFactory {
if (WRITER != null) {
return WRITER;
}
if (SnifferConfigInitializer.isInitCompleted()
&& PluginFinder.isPluginInitCompleted()
if (Constants.IS_INIT_COMPLETED
&& AgentPackagePath.isPathFound()) {
if (StringUtil.isEmpty(Config.Logging.DIR)) {
try {

@ -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 {

@ -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().

@ -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;

@ -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()

@ -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.

@ -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()

@ -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()

@ -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;

@ -390,4 +390,69 @@ public class StringUtil {
}
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);
}
}

@ -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.
* <p>
*/
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<Enum>) 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<Object, Object> 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<String> convert2List(String value) {
if (StringUtil.isEmpty(value)) {
return Collections.emptyList();
}
List<String> 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<String> 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);
}
}

@ -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();
}

@ -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 = ":";
}

@ -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. <p>
* 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<String, String> wellKnownSimplePrefixes = new HashMap<String, String>(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<String>());
}
protected String parseStringValue(String value, PlaceholderResolver placeholderResolver,
Set<String> 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);
}
}

@ -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);
}
}

@ -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

@ -24,12 +24,12 @@ import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
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 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD
@RequiredArgsConstructor
public class DynamicThreadPoolRefreshListener implements Observer<BootstrapConfigProperties> {
private static final Logger LOGGER = LoggerFactory.getLogger(DynamicThreadPoolRefreshListener.class);
private static final ILog LOG = LogManager.getLogger(DynamicThreadPoolRefreshListener.class);
@Override
public void accept(ObserverMessage<BootstrapConfigProperties> observerMessage) {
@ -127,15 +127,14 @@ public class DynamicThreadPoolRefreshListener implements Observer<BootstrapConfi
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()),

@ -78,6 +78,7 @@
<spotless-maven-plugin.version>2.22.1</spotless-maven-plugin.version>
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
<spring-boot-maven-plugin.version>2.3.2.RELEASE</spring-boot-maven-plugin.version>
<gson.version>2.8.9</gson.version>
</properties>
<dependencyManagement>

Loading…
Cancel
Save