diff --git a/hippo4j-agent/hippo4j-agent-core/pom.xml b/hippo4j-agent/hippo4j-agent-core/pom.xml
index e158237c..e5d711ec 100644
--- a/hippo4j-agent/hippo4j-agent-core/pom.xml
+++ b/hippo4j-agent/hippo4j-agent-core/pom.xml
@@ -79,6 +79,12 @@
jmh-generator-annprocesstest
+
+ cn.hippo4j
+ hippo4j-common
+ ${project.version}
+ provided
+
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java
index 66d148a8..3fe8d1e0 100644
--- a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/boot/SpringBootConfigInitializer.java
@@ -20,6 +20,7 @@ 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.agent.core.util.ConfigInitializer;
+import lombok.extern.slf4j.Slf4j;
import java.util.Collections;
import java.util.HashSet;
@@ -38,17 +39,21 @@ public class SpringBootConfigInitializer {
private static long PROPERTIES_LOAD_TIME;
- private static Properties SPRING_PROPERTIES = null;
+ public static Properties SPRING_PROPERTIES = null;
private SpringBootConfigInitializer() {
}
+ public static boolean isSpringPropertiesEmpty() {
+ return SPRING_PROPERTIES == null || SPRING_PROPERTIES.isEmpty();
+ }
+
public static synchronized void initializeConfig(SpringBootConfig springBootConfig) {
if (SPRING_PROPERTIES != null) {
try {
LOG.info("initialize Spring Config Class {}.", springBootConfig.root());
- ConfigInitializer.initialize(SPRING_PROPERTIES, springBootConfig.root());
+ ConfigInitializer.initialize(SPRING_PROPERTIES, springBootConfig.root(), true);
} catch (Throwable e) {
LOG.error(e, "Failed to set the agent settings {} to Config={} ", SPRING_PROPERTIES, springBootConfig.root());
}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java
index ee8d3d0b..0321ea43 100755
--- a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Config.java
@@ -17,6 +17,7 @@
package cn.hippo4j.agent.core.conf;
+import cn.hippo4j.agent.core.boot.SpringBootConfig;
import cn.hippo4j.agent.core.logging.core.LogLevel;
import cn.hippo4j.agent.core.logging.core.LogOutput;
import cn.hippo4j.agent.core.logging.core.ResolverType;
@@ -358,6 +359,31 @@ public class Config {
* Mount the folders of the plugins. The folder path is relative to agent.jar.
*/
public static List MOUNT = Arrays.asList("plugins", "activations");
+
+ public static class ThreadPool {
+
+ public static List EXCLUDE_PACKAGE_PREFIX = Arrays.asList(
+ "java", "sun", "okhttp3", "retrofit2", "reactor",
+ "org.apache", "io.netty", "org.springframework", "com.ctrip", "com.google",
+ "io.undertow", "org.xnio", "org.jboss", "com.zaxxer", "org.redisson", "com.alibaba",
+ "com.netflix", "com.mysql", "rx.internal", "io.shardingjdbc", "org.drools", "org.elasticsearch",
+ "ch.qos.logback", "net.sf.ehcache");
+ }
+
+ public static class Apollo {
+ public static class App {
+
+ public static String ID;
+ }
+ public static String META;
+
+ public static class BootStrap {
+
+ public static boolean ENABLED = false;
+
+ public static List NAMESPACES;
+ }
+ }
}
public static class Correlation {
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java
index 26433f2e..25f3d7bb 100644
--- a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/Constants.java
@@ -33,4 +33,7 @@ public class Constants {
public static String EVENT_LAYER_NAME = "GENERAL";
public static int NULL_VALUE = 0;
+
+ public static String SPRING_BOOT_CONFIG_PREFIX = "spring.dynamic.thread-pool";
+
}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java
index b71ed425..6db4e6b4 100644
--- a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/conf/SnifferConfigInitializer.java
@@ -106,9 +106,9 @@ public class SnifferConfigInitializer {
Config.Agent.CLUSTER);
}
}
- if (StringUtil.isEmpty(Config.Collector.BACKEND_SERVICE)) {
- throw new ExceptionInInitializerError("`collector.backend_service` is missing.");
- }
+ // if (StringUtil.isEmpty(Config.Collector.BACKEND_SERVICE)) {
+ // throw new ExceptionInInitializerError("`collector.backend_service` is missing.");
+ // }
if (Config.Plugin.PEER_MAX_LENGTH <= 3) {
LOGGER.warn(
"PEER_MAX_LENGTH configuration:{} error, the default value of 200 will be used.",
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.java
new file mode 100644
index 00000000..deccaa59
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.agent.core.registry;
+
+import cn.hippo4j.agent.core.logging.api.ILog;
+import cn.hippo4j.agent.core.logging.api.LogManager;
+import cn.hippo4j.common.config.ExecutorProperties;
+import lombok.Data;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Data
+public class AgentThreadPoolExecutorHolder {
+
+ private static final ILog LOGGER = LogManager.getLogger(AgentThreadPoolExecutorHolder.class);
+
+ public static final AgentThreadPoolExecutorHolder EMPTY = new AgentThreadPoolExecutorHolder();
+
+ private String executorName;
+
+ private ThreadPoolExecutor executor;
+
+ private ExecutorProperties properties;
+
+ public AgentThreadPoolExecutorHolder() {
+ }
+
+ public AgentThreadPoolExecutorHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties properties) {
+ this.executorName = executorName;
+ this.executor = executor;
+ this.properties = properties;
+ }
+
+ public boolean isEmpty() {
+ return this == EMPTY;
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.java
new file mode 100644
index 00000000..b70228c3
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.java
@@ -0,0 +1,63 @@
+/*
+ * 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.agent.core.registry;
+
+import cn.hippo4j.agent.core.logging.api.ILog;
+import cn.hippo4j.agent.core.logging.api.LogManager;
+import cn.hippo4j.common.config.ExecutorProperties;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadPoolExecutor;
+
+public class AgentThreadPoolInstanceRegistry {
+
+ private static final ILog LOGGER = LogManager.getLogger(AgentThreadPoolInstanceRegistry.class);
+
+ private final Map holderMap = new ConcurrentHashMap<>();
+
+ private volatile static AgentThreadPoolInstanceRegistry INSTANCE;
+
+ private AgentThreadPoolInstanceRegistry() {
+ }
+
+ public static AgentThreadPoolInstanceRegistry getInstance() {
+ if (INSTANCE == null) {
+ synchronized (AgentThreadPoolInstanceRegistry.class) {
+ if (INSTANCE == null) {
+ INSTANCE = new AgentThreadPoolInstanceRegistry();
+ }
+ }
+ }
+ return INSTANCE;
+ }
+
+ public Map getHolderMap() {
+ return holderMap;
+ }
+
+ public void putHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties properties) {
+ AgentThreadPoolExecutorHolder holder = new AgentThreadPoolExecutorHolder(executorName, executor, properties);
+ holderMap.put(executorName, holder);
+ }
+
+ public AgentThreadPoolExecutorHolder getHolder(String executorName) {
+ return Optional.ofNullable(holderMap.get(executorName)).orElse(AgentThreadPoolExecutorHolder.EMPTY);
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.java
new file mode 100644
index 00000000..bdfbdaac
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.java
@@ -0,0 +1,27 @@
+/*
+ * 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.agent.core.util;
+
+public interface AgentThreadPoolConstants {
+
+ String TOMCAT_NAME_PREFIX = "namePrefix";
+ String DUBBO_NAME_PREFIX = "mPrefix";
+ String DUBBO_THREAD_NAME = "DubboServerHandler";
+ String THREAD_POOL_NAME_DUBBO = "dubbo";
+
+}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java
index 0037ae76..587c84f8 100644
--- a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/CollectionUtil.java
@@ -41,4 +41,24 @@ public final class CollectionUtil {
public static boolean isEmpty(Collection collection) {
return collection == null || collection.isEmpty();
}
+
+ /**
+ * Is empty.
+ *
+ * @param map
+ * @return
+ */
+ public static boolean isEmpty(Map, ?> map) {
+ return map == null || map.isEmpty();
+ }
+
+ /**
+ * Is not empty.
+ *
+ * @param map
+ * @return
+ */
+ public static boolean isNotEmpty(Map, ?> map) {
+ return !isEmpty(map);
+ }
}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java
index 3bb87ccd..8ebb4c81 100644
--- a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ConfigInitializer.java
@@ -30,14 +30,18 @@ import java.util.*;
public class ConfigInitializer {
public static void initialize(Properties properties, Class> rootConfigType) throws IllegalAccessException {
- initNextLevel(properties, rootConfigType, new ConfigDesc());
+ 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) throws IllegalArgumentException, IllegalAccessException {
+ ConfigDesc parentDesc, boolean isSpringProperties) throws IllegalArgumentException, IllegalAccessException {
for (Field field : recentConfigType.getFields()) {
if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
- String configKey = (parentDesc + "." + field.getName()).toLowerCase();
+ String configKey = (parentDesc + "." + (isSpringProperties ? field.getName().replace("_", "-") : field.getName())).toLowerCase();
Class> type = field.getType();
if (type.equals(Map.class)) {
@@ -78,8 +82,10 @@ public class ConfigInitializer {
}
}
for (Class> innerConfiguration : recentConfigType.getClasses()) {
- parentDesc.append(innerConfiguration.getSimpleName());
- initNextLevel(properties, innerConfiguration, parentDesc);
+ String simpleName = innerConfiguration.getSimpleName();
+ String description = isSpringProperties ? simpleName.replace("_", "-") : simpleName;
+ parentDesc.append(description);
+ initNextLevel(properties, innerConfiguration, parentDesc, isSpringProperties);
parentDesc.removeLastDesc();
}
}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.java
new file mode 100644
index 00000000..7a597187
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.java
@@ -0,0 +1,44 @@
+/*
+ * 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.agent.core.util;
+
+import cn.hippo4j.agent.core.logging.api.ILog;
+import cn.hippo4j.agent.core.logging.api.LogManager;
+
+import java.lang.reflect.Field;
+
+public class ExecutorNameUtil {
+
+ private static final ILog LOGGER = LogManager.getLogger(ExecutorNameUtil.class);
+
+ public static boolean isTomcatExecutor(Object threadFactory) {
+ try {
+ if ("org.apache.tomcat.util.threads.TaskThreadFactory".equals(threadFactory.getClass().getName())) {
+ Field namePrefixField = threadFactory.getClass().getDeclaredField(AgentThreadPoolConstants.TOMCAT_NAME_PREFIX);
+ namePrefixField.setAccessible(true);
+ String namePrefix = (String) namePrefixField.get(threadFactory);
+ if (RegexUtil.isTomcatNameMatch(namePrefix)) {
+ return true;
+ }
+ }
+ } catch (Throwable t) {
+ LOGGER.error("Fail to put tomcat executor", t);
+ }
+ return false;
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.java
new file mode 100644
index 00000000..3a59b535
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.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.agent.core.util;
+
+import cn.hippo4j.agent.core.logging.api.ILog;
+import cn.hippo4j.agent.core.logging.api.LogManager;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ReflectUtil {
+
+ private static final ILog LOGGER = LogManager.getLogger(ReflectUtil.class);
+
+ public static List getStaticFieldsFromType(Class> clazz, Class> declaredType) {
+ Field[] fields = clazz.getFields();
+ List result = new ArrayList<>();
+ for (Field field : fields) {
+ if (field.getType().isAssignableFrom(declaredType) &&
+ Modifier.isStatic(field.getModifiers())) {
+ result.add(field);
+ }
+ }
+ return result;
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RegexUtil.java b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RegexUtil.java
new file mode 100644
index 00000000..7d01353b
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/RegexUtil.java
@@ -0,0 +1,31 @@
+/*
+ * 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.agent.core.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class RegexUtil {
+
+ private static final String TOMCAT_NAME_PATTERN_STRING = "http\\S+nio\\S+-exec-";
+ private static final Pattern TOMCAT_NAME_PATTERN = Pattern.compile(TOMCAT_NAME_PATTERN_STRING);
+
+ public static boolean isTomcatNameMatch(String executorName) {
+ return TOMCAT_NAME_PATTERN.matcher(executorName).find();
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/pom.xml b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/pom.xml
new file mode 100644
index 00000000..c50abc5e
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/pom.xml
@@ -0,0 +1,27 @@
+
+
+ 4.0.0
+
+ cn.hippo4j
+ hippo4j-agent-plugin
+ ${revision}
+
+
+ apollo-plugin
+
+
+ 1.9.1
+
+
+
+
+ com.ctrip.framework.apollo
+ apollo-client
+ ${apollo.version}
+ provided
+
+
+
+
\ No newline at end of file
diff --git a/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/DefaultConfigConstructorInterceptor.java b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/DefaultConfigConstructorInterceptor.java
new file mode 100644
index 00000000..4936a383
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/DefaultConfigConstructorInterceptor.java
@@ -0,0 +1,51 @@
+/*
+ * 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.agent.plugin.apollo;
+
+import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+import com.ctrip.framework.apollo.ConfigChangeListener;
+import com.ctrip.framework.apollo.ConfigFile;
+import com.ctrip.framework.apollo.ConfigService;
+import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
+import com.ctrip.framework.apollo.internals.DefaultConfig;
+import com.ctrip.framework.apollo.model.ConfigChange;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DefaultConfigConstructorInterceptor implements InstanceConstructorInterceptor {
+
+ @Override
+ public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable {
+ // DefaultConfig config = (DefaultConfig) objInst;
+ // ConfigChangeListener configChangeListener = configChangeEvent -> {
+ // String namespace = this.namespace.replaceAll("." + bootstrapConfigProperties.getConfigFileType().getValue(), "");
+ // ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(bootstrapConfigProperties.getConfigFileType().getValue());
+ // ConfigFile configFile = ConfigService.getConfigFile(namespace, configFileFormat);
+ // Map newChangeValueMap = new HashMap<>();
+ // configChangeEvent.changedKeys().stream().filter(each -> each.contains(BootstrapConfigProperties.PREFIX)).forEach(each -> {
+ // ConfigChange change = configChangeEvent.getChange(each);
+ // String newValue = change.getNewValue();
+ // newChangeValueMap.put(each, newValue);
+ // });
+ // dynamicRefresh(configFile.getContent(), newChangeValueMap);
+ // };
+ // config.addChangeListener(configChangeListener);
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/boot/ApolloPluginBootService.java b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/boot/ApolloPluginBootService.java
new file mode 100644
index 00000000..9ad1dd0f
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/boot/ApolloPluginBootService.java
@@ -0,0 +1,45 @@
+/*
+ * 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.agent.plugin.apollo.boot;
+
+import cn.hippo4j.agent.core.boot.BootService;
+import cn.hippo4j.agent.core.boot.DefaultImplementor;
+
+@DefaultImplementor
+public class ApolloPluginBootService implements BootService {
+
+ @Override
+ public void prepare() throws Throwable {
+
+ }
+
+ @Override
+ public void boot() throws Throwable {
+
+ }
+
+ @Override
+ public void onComplete() throws Throwable {
+
+ }
+
+ @Override
+ public void shutdown() throws Throwable {
+
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/define/ApolloInstrumentation.java b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/define/ApolloInstrumentation.java
new file mode 100644
index 00000000..6ae9d63c
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/java/cn/hippo4j/agent/plugin/apollo/define/ApolloInstrumentation.java
@@ -0,0 +1,63 @@
+/*
+ * 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.agent.plugin.apollo.define;
+
+import cn.hippo4j.agent.core.plugin.interceptor.ConstructorInterceptPoint;
+import cn.hippo4j.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import cn.hippo4j.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+import cn.hippo4j.agent.core.plugin.match.ClassMatch;
+import cn.hippo4j.agent.core.plugin.match.NameMatch;
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+public class ApolloInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String ENHANCE_CLASS = "com.ctrip.framework.apollo.internals.DefaultConfig";
+
+ private static final String CONSTRUCTOR_INTERCEPT_CLASS = "cn.hippo4j.agent.plugin.apollo.DefaultConfigConstructorInterceptor";
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return NameMatch.byName(ENHANCE_CLASS);
+ }
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[]{
+ new ConstructorInterceptPoint() {
+
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return any();
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return CONSTRUCTOR_INTERCEPT_CLASS;
+ }
+ }
+ };
+ }
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[0];
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/META-INF/services/cn.hippo4j.agent.core.boot.BootService b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/META-INF/services/cn.hippo4j.agent.core.boot.BootService
new file mode 100644
index 00000000..8832c467
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/META-INF/services/cn.hippo4j.agent.core.boot.BootService
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cn.hippo4j.agent.plugin.apollo.boot.ApolloPluginBootService
\ No newline at end of file
diff --git a/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/hippo4j-plugin.def b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/hippo4j-plugin.def
new file mode 100644
index 00000000..ede6239b
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-plugin/apollo-plugin/src/main/resources/hippo4j-plugin.def
@@ -0,0 +1,17 @@
+# 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.
+
+apollo-plugin=cn.hippo4j.agent.plugin.apollo.define.ApolloInstrumentation
\ No newline at end of file
diff --git a/hippo4j-agent/hippo4j-agent-plugin/pom.xml b/hippo4j-agent/hippo4j-agent-plugin/pom.xml
index dc1770b1..1a3db451 100644
--- a/hippo4j-agent/hippo4j-agent-plugin/pom.xml
+++ b/hippo4j-agent/hippo4j-agent-plugin/pom.xml
@@ -13,6 +13,8 @@
pomspring-plugins
+ thread-pool-plugin
+ apollo-plugin
@@ -29,6 +31,21 @@
1.8.1
+
+
+ cn.hippo4j
+ hippo4j-agent-core
+ ${project.version}
+ provided
+
+
+ net.bytebuddy
+ byte-buddy
+ ${bytebuddy.version}
+ provided
+
+
+
diff --git a/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/pom.xml b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/pom.xml
index 1d85f539..200bfd2a 100644
--- a/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/pom.xml
+++ b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/pom.xml
@@ -32,19 +32,4 @@
-
-
- cn.hippo4j
- hippo4j-agent-core
- ${project.version}
- provided
-
-
- net.bytebuddy
- byte-buddy
- ${bytebuddy.version}
- provided
-
-
-
\ No newline at end of file
diff --git a/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml
index d52b781c..e144cf35 100644
--- a/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml
+++ b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/pom.xml
@@ -13,8 +13,21 @@
1.5.22.RELEASE
+ 1.9.1
+
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ ${spring.boot.version}
+ pom
+ import
+
+
+
+
cn.hippo4j
@@ -24,10 +37,30 @@
org.springframework.boot
- spring-boot-autoconfigure
+ spring-boot-starter${spring.boot.version}provided
+
+
+ com.ctrip.framework.apollo
+ apollo-client
+ ${apollo.version}
+ provided
+
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+
+ cn.hippo4j
+ hippo4j-config-spring-boot-1x-starter
+ ${project.version}
+ provided
+
\ No newline at end of file
diff --git a/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/ApolloSpringBootProperties.java b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/ApolloSpringBootProperties.java
new file mode 100644
index 00000000..1bf70dc3
--- /dev/null
+++ b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/ApolloSpringBootProperties.java
@@ -0,0 +1,45 @@
+/*
+ * 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.agent.plugin.spring.boot.v1;
+
+import cn.hippo4j.agent.core.boot.SpringBootConfig;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class ApolloSpringBootProperties {
+
+
+ public static class Spring {
+
+ public static class Dynamic {
+
+ @SpringBootConfig(root = ApolloSpringBootProperties.class)
+ public static class Thread_Pool {
+
+ @SpringBootConfig(root = ApolloSpringBootProperties.class)
+ public static class Apollo {
+
+ public static List NAMESPACE = Arrays.asList("application");
+ }
+
+ public static String CONFIG_FILE_TYPE;
+ }
+ }
+ }
+}
diff --git a/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/EventPublishingFinishedInterceptor.java b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/EventPublishingFinishedInterceptor.java
index c7dc072f..688ae0bf 100644
--- a/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/EventPublishingFinishedInterceptor.java
+++ b/hippo4j-agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1.x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/EventPublishingFinishedInterceptor.java
@@ -17,27 +17,59 @@
package cn.hippo4j.agent.plugin.spring.boot.v1;
-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.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import cn.hippo4j.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import cn.hippo4j.agent.core.registry.AgentThreadPoolExecutorHolder;
+import cn.hippo4j.agent.core.registry.AgentThreadPoolInstanceRegistry;
import cn.hippo4j.agent.plugin.spring.common.SpringPropertiesLoader;
+import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
+import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
+import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue;
+import cn.hippo4j.common.toolkit.CollectionUtil;
+import cn.hippo4j.common.toolkit.MapUtil;
+import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
+import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
+import cn.hippo4j.common.config.ExecutorProperties;
+import cn.hippo4j.config.springboot.starter.parser.ConfigFileTypeEnum;
+import cn.hippo4j.config.springboot.starter.parser.ConfigParserHandler;
+import cn.hippo4j.config.springboot.starter.support.GlobalCoreThreadPoolManage;
+import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
+import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
+import com.ctrip.framework.apollo.ConfigChangeListener;
+import com.ctrip.framework.apollo.ConfigFile;
+import com.ctrip.framework.apollo.ConfigService;
+import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
+import com.ctrip.framework.apollo.model.ConfigChange;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.PropertyValues;
+import org.springframework.beans.support.ResourceEditorRegistrar;
+import org.springframework.boot.bind.CustomPropertyNamePatternsMatcher;
+import org.springframework.boot.bind.RelaxedDataBinder;
+import org.springframework.boot.bind.RelaxedNames;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.core.env.EnumerablePropertySource;
-import org.springframework.core.env.PropertySource;
+import org.springframework.core.env.MapPropertySource;
+import org.springframework.core.env.MutablePropertySources;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static cn.hippo4j.agent.core.conf.Constants.SPRING_BOOT_CONFIG_PREFIX;
+import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
+import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD_POOL_TEXT;
+import static cn.hippo4j.config.springboot1x.starter.refresher.SpringBoot1xBootstrapConfigPropertiesBinderAdapt.getNames;
public class EventPublishingFinishedInterceptor implements InstanceMethodsAroundInterceptor {
- private static final ILog LOGGER = LogManager.getLogger(EventPublishingFinishedInterceptor.class);
+ private static final ILog FILE_LOGGER = LogManager.getLogger(EventPublishingFinishedInterceptor.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(EventPublishingFinishedInterceptor.class);
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
@@ -48,9 +80,211 @@ public class EventPublishingFinishedInterceptor implements InstanceMethodsAround
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes, Object ret) throws Throwable {
ConfigurableApplicationContext context = (ConfigurableApplicationContext) allArguments[0];
SpringPropertiesLoader.loadSpringProperties(context.getEnvironment());
+
+ List apolloNamespaces = ApolloSpringBootProperties.Spring.Dynamic.Thread_Pool.Apollo.NAMESPACE;
+
+ String namespace = apolloNamespaces.get(0);
+ String configFileType = ApolloSpringBootProperties.Spring.Dynamic.Thread_Pool.CONFIG_FILE_TYPE;
+ com.ctrip.framework.apollo.Config config = ConfigService.getConfig(String.format("%s.%s", namespace, configFileType));
+ ConfigChangeListener configChangeListener = configChangeEvent -> {
+ String replacedNamespace = namespace.replaceAll("." + configFileType, "");
+ ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(configFileType);
+ ConfigFile configFile = ConfigService.getConfigFile(replacedNamespace, configFileFormat);
+ Map newChangeValueMap = new HashMap<>();
+ configChangeEvent.changedKeys().stream().filter(each -> each.contains(SPRING_BOOT_CONFIG_PREFIX)).forEach(each -> {
+ ConfigChange change = configChangeEvent.getChange(each);
+ String newValue = change.getNewValue();
+ newChangeValueMap.put(each, newValue);
+ });
+ dynamicRefresh(configFile.getContent(), newChangeValueMap, context);
+ };
+ config.addChangeListener(configChangeListener);
+ LOGGER.info("Dynamic thread pool refresher, add apollo listener success. namespace: {}", namespace);
return ret;
}
+ public BootstrapConfigProperties bindProperties(Map