diff --git a/agent/hippo4j-agent-core/pom.xml b/agent/hippo4j-agent-core/pom.xml index 97412d51eb..ee49874b5d 100644 --- a/agent/hippo4j-agent-core/pom.xml +++ b/agent/hippo4j-agent-core/pom.xml @@ -83,6 +83,11 @@ hippo4j-threadpool-dynamic-mode-config ${project.version} + + cn.hippo4j + hippo4j-threadpool-kernel-monitor + ${project.version} + diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java index 818efb62b5..0718469249 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java @@ -28,6 +28,7 @@ import cn.hippo4j.common.extension.design.AbstractSubjectCenter; import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh; import cn.hippo4j.threadpool.dynamic.mode.config.refresher.event.DynamicThreadPoolRefreshListener; +import lombok.extern.slf4j.Slf4j; import org.springframework.context.ConfigurableApplicationContext; import java.lang.reflect.Method; @@ -35,6 +36,7 @@ /** * Event publishing started interceptor */ +@Slf4j public class EventPublishingStartedInterceptor implements InstanceMethodsAroundInterceptor { private static final ILog LOGGER = LogManager.getLogger(EventPublishingStartedInterceptor.class); @@ -57,6 +59,7 @@ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allA dynamicRefresh.registerListener(); AbstractSubjectCenter.register(AbstractSubjectCenter.SubjectType.THREAD_POOL_DYNAMIC_REFRESH, new DynamicThreadPoolRefreshListener()); + return ret; } diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java index 813369c3d7..ca9794322f 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/conf/SpringBootConfig.java @@ -52,6 +52,23 @@ public static class Apollo { public static List NAMESPACE = Arrays.asList("application"); } + /** + * Monitor + */ + @SpringBootConfigNode(root = SpringBootConfig.class) + public static class Monitor { + + public static Boolean enable = Boolean.TRUE; + + public static String collectTypes = "micrometer"; + + public static String threadPoolTypes = "dynamic"; + + public static Long initialDelay = 10000L; + + public static Long collectInterval = 5000L; + } + public static String CONFIG_FILE_TYPE; } } diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/define/SpringApplicationInstrumentation.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/define/SpringApplicationInstrumentation.java new file mode 100644 index 0000000000..bcd7f5c37f --- /dev/null +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/define/SpringApplicationInstrumentation.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.agent.plugin.spring.common.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 net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static cn.hippo4j.agent.core.plugin.match.NameMatch.byName; +import static net.bytebuddy.matcher.ElementMatchers.named; + +public class SpringApplicationInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.springframework.boot.SpringApplication"; + + private static final String RUN_INTERCEPTOR = "cn.hippo4j.agent.plugin.spring.common.interceptor.SpringApplicationRunInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + + @Override + public ElementMatcher getMethodsMatcher() { + return named("run"); + } + + @Override + public String getMethodsInterceptor() { + return RUN_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected String[] witnessClasses() { + return new String[]{"org.springframework.boot.SpringApplication"}; + } +} diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java index 8439d567d7..65a9f4cbbd 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java @@ -21,6 +21,7 @@ import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; +import cn.hippo4j.common.handler.DynamicThreadPoolAdapterChoose; import cn.hippo4j.common.model.executor.ExecutorProperties; import cn.hippo4j.common.toolkit.BooleanUtil; import org.slf4j.Logger; @@ -64,13 +65,12 @@ public static void registerThreadPoolInstances(ApplicationContext context) { for (Map.Entry entry : beansWithAnnotation.entrySet()) { String beanName = entry.getKey(); Executor bean = entry.getValue(); - ThreadPoolExecutor executor = (ThreadPoolExecutor) bean; - // TODO - // if (DynamicThreadPoolAdapterChoose.match(bean)) { - // executor = DynamicThreadPoolAdapterChoose.unwrap(bean); - // } else { - // executor = (ThreadPoolExecutor) bean; - // } + ThreadPoolExecutor executor; + if (DynamicThreadPoolAdapterChoose.match(bean)) { + executor = DynamicThreadPoolAdapterChoose.unwrap(bean); + } else { + executor = (ThreadPoolExecutor) bean; + } if (executor == null) { LOGGER.warn("[Hippo4j-Agent] Thread pool is null, ignore bean registration. beanName={}, beanClass={}", beanName, bean.getClass().getName()); } else { diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapter.java b/infra/common/src/main/java/cn/hippo4j/common/api/DynamicThreadPoolAdapter.java similarity index 97% rename from threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapter.java rename to infra/common/src/main/java/cn/hippo4j/common/api/DynamicThreadPoolAdapter.java index 6296321e82..b47fe01dcf 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapter.java +++ b/infra/common/src/main/java/cn/hippo4j/common/api/DynamicThreadPoolAdapter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.core.executor.support.adpter; +package cn.hippo4j.common.api; import java.util.concurrent.Executor; import java.util.concurrent.ThreadPoolExecutor; diff --git a/infra/common/src/main/java/cn/hippo4j/common/handler/DynamicThreadPoolAdapterChoose.java b/infra/common/src/main/java/cn/hippo4j/common/handler/DynamicThreadPoolAdapterChoose.java new file mode 100644 index 0000000000..3f2b3d17b3 --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/handler/DynamicThreadPoolAdapterChoose.java @@ -0,0 +1,96 @@ +/* + * 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.handler; + +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; +import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry; +import cn.hippo4j.common.toolkit.CollectionUtil; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * Dynamic thread pool adapter choose. + */ +public class DynamicThreadPoolAdapterChoose { + + private static final List DYNAMIC_THREAD_POOL_ADAPTERS = new ArrayList<>(); + + static { + DYNAMIC_THREAD_POOL_ADAPTERS.add(new TransmittableThreadLocalExecutorAdapter()); + DYNAMIC_THREAD_POOL_ADAPTERS.add(new TransmittableThreadLocalExecutorServiceAdapter()); + DYNAMIC_THREAD_POOL_ADAPTERS.add(new ZipkinExecutorAdapter()); + loadCustomerAdapter(); + } + + /** + * Check if the object contains thread pool information. + * + * @param executor objects where there may be instances + * of dynamic thread pools + * @return matching results + */ + public static boolean match(Object executor) { + return DYNAMIC_THREAD_POOL_ADAPTERS.stream().anyMatch(each -> each.match(executor)); + } + + /** + * Get the dynamic thread pool reference in the object. + * + * @param executor objects where there may be instances + * of dynamic thread pools + * @return get the real dynamic thread pool instance + */ + public static ThreadPoolExecutor unwrap(Object executor) { + Optional dynamicThreadPoolAdapterOptional = DYNAMIC_THREAD_POOL_ADAPTERS.stream().filter(each -> each.match(executor)).findFirst(); + return dynamicThreadPoolAdapterOptional.map(each -> each.unwrap(executor)).orElse(null); + } + + /** + * If the {@link DynamicThreadPoolAdapter#match(Object)} conditions are met, + * the thread pool is replaced with a dynamic thread pool. + * + * @param executor objects where there may be instances + * of dynamic thread pools + * @param dynamicThreadPoolExecutor dynamic thread-pool executor + */ + public static void replace(Object executor, Executor dynamicThreadPoolExecutor) { + Optional dynamicThreadPoolAdapterOptional = DYNAMIC_THREAD_POOL_ADAPTERS.stream().filter(each -> each.match(executor)).findFirst(); + dynamicThreadPoolAdapterOptional.ifPresent(dynamicThreadPoolAdapter -> dynamicThreadPoolAdapter.replace(executor, dynamicThreadPoolExecutor)); + } + + /** + * Load SPI customer adapter. + */ + private static void loadCustomerAdapter() { + ServiceLoaderRegistry.register(DynamicThreadPoolAdapter.class); + Collection instances = ServiceLoaderRegistry.getSingletonServiceInstances(DynamicThreadPoolAdapter.class); + if (CollectionUtil.isEmpty(instances)) { + return; + } + for (DynamicThreadPoolAdapter instance : instances) { + if (instance != null) { + DYNAMIC_THREAD_POOL_ADAPTERS.add(instance); + } + } + } +} diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/ThreadPoolStatusHandler.java b/infra/common/src/main/java/cn/hippo4j/common/handler/ThreadPoolStatusHandler.java similarity index 98% rename from threadpool/core/src/main/java/cn/hippo4j/core/executor/state/ThreadPoolStatusHandler.java rename to infra/common/src/main/java/cn/hippo4j/common/handler/ThreadPoolStatusHandler.java index 30bad4a2c9..5cba367673 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/ThreadPoolStatusHandler.java +++ b/infra/common/src/main/java/cn/hippo4j/common/handler/ThreadPoolStatusHandler.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.core.executor.state; +package cn.hippo4j.common.handler; import cn.hippo4j.common.toolkit.ReflectUtil; import lombok.extern.slf4j.Slf4j; diff --git a/infra/common/src/main/java/cn/hippo4j/common/handler/TransmittableThreadLocalExecutorAdapter.java b/infra/common/src/main/java/cn/hippo4j/common/handler/TransmittableThreadLocalExecutorAdapter.java new file mode 100644 index 0000000000..079fc11eec --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/handler/TransmittableThreadLocalExecutorAdapter.java @@ -0,0 +1,50 @@ +/* + * 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.handler; + +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; +import cn.hippo4j.common.toolkit.ReflectUtil; + +import java.util.Objects; +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * Transmittable thread local executor adapter. + */ +public class TransmittableThreadLocalExecutorAdapter implements DynamicThreadPoolAdapter { + + private static final String MATCH_CLASS_NAME = "ExecutorTtlWrapper"; + + private static final String FIELD_NAME = "executor"; + + @Override + public boolean match(Object executor) { + return Objects.equals(MATCH_CLASS_NAME, executor.getClass().getSimpleName()); + } + + @Override + public ThreadPoolExecutor unwrap(Object executor) { + return (ThreadPoolExecutor) ReflectUtil.getFieldValue(executor, FIELD_NAME); + } + + @Override + public void replace(Object executor, Executor dynamicThreadPoolExecutor) { + ReflectUtil.setFieldValue(executor, FIELD_NAME, dynamicThreadPoolExecutor); + } +} diff --git a/infra/common/src/main/java/cn/hippo4j/common/handler/TransmittableThreadLocalExecutorServiceAdapter.java b/infra/common/src/main/java/cn/hippo4j/common/handler/TransmittableThreadLocalExecutorServiceAdapter.java new file mode 100644 index 0000000000..5dd27df958 --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/handler/TransmittableThreadLocalExecutorServiceAdapter.java @@ -0,0 +1,50 @@ +/* + * 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.handler; + +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; +import cn.hippo4j.common.toolkit.ReflectUtil; + +import java.util.Objects; +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * Transmittable thread local executor service adapter. + */ +public class TransmittableThreadLocalExecutorServiceAdapter implements DynamicThreadPoolAdapter { + + private static final String MATCH_CLASS_NAME = "ExecutorServiceTtlWrapper"; + + private static final String FIELD_NAME = "executorService"; + + @Override + public boolean match(Object executor) { + return Objects.equals(MATCH_CLASS_NAME, executor.getClass().getSimpleName()); + } + + @Override + public ThreadPoolExecutor unwrap(Object executor) { + return (ThreadPoolExecutor) ReflectUtil.getFieldValue(executor, FIELD_NAME); + } + + @Override + public void replace(Object executor, Executor dynamicThreadPoolExecutor) { + ReflectUtil.setFieldValue(executor, FIELD_NAME, dynamicThreadPoolExecutor); + } +} diff --git a/infra/common/src/main/java/cn/hippo4j/common/handler/ZipkinExecutorAdapter.java b/infra/common/src/main/java/cn/hippo4j/common/handler/ZipkinExecutorAdapter.java new file mode 100644 index 0000000000..7177c070bc --- /dev/null +++ b/infra/common/src/main/java/cn/hippo4j/common/handler/ZipkinExecutorAdapter.java @@ -0,0 +1,76 @@ +/* + * 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.handler; + +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; +import cn.hippo4j.common.toolkit.ReflectUtil; + +import java.lang.reflect.Field; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * Zipkin thread local executor adapter. + */ +public class ZipkinExecutorAdapter implements DynamicThreadPoolAdapter { + + private static final String MATCH_CLASS_NAME = "brave.internal.WrappingExecutorService"; + private static final String FIELD_NAME = "delegate"; + private static final String TYPE_NAME = "java.util.concurrent.ExecutorService"; + + @Override + public boolean match(Object executor) { + return matchSuper(executor); + } + + public boolean matchSuper(Object executor) { + if (Objects.equals(MATCH_CLASS_NAME, Optional.ofNullable(executor).map(Object::getClass).map(Class::getName).orElse(null))) { + return true; + } else { + return Objects.equals(MATCH_CLASS_NAME, Optional.ofNullable(executor).map(Object::getClass).map(Class::getSuperclass).map(Class::getName).orElse(null)); + } + } + + @Override + public ThreadPoolExecutor unwrap(Object executor) { + Object unwrap = doUnwrap(executor); + if (unwrap == null) { + return null; + } + return (ThreadPoolExecutor) unwrap; + } + + @Override + public void replace(Object executor, Executor dynamicThreadPoolExecutor) { + Field field = ReflectUtil.findField(executor, FIELD_NAME, TYPE_NAME); + ReflectUtil.setFieldValue(executor, field, dynamicThreadPoolExecutor); + } + + private Object doUnwrap(Object executor) { + Object unwrap = ReflectUtil.getFieldValue(executor, FIELD_NAME); + if (unwrap == null) { + Field field = ReflectUtil.findField(executor, FIELD_NAME, TYPE_NAME); + if (field != null) { + return ReflectUtil.getFieldValue(executor, field); + } + } + return null; + } +} diff --git a/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterState.java b/infra/common/src/main/java/cn/hippo4j/common/model/ThreadPoolAdapterState.java similarity index 97% rename from threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterState.java rename to infra/common/src/main/java/cn/hippo4j/common/model/ThreadPoolAdapterState.java index b46c6c262b..ad7322d998 100644 --- a/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterState.java +++ b/infra/common/src/main/java/cn/hippo4j/common/model/ThreadPoolAdapterState.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.adapter.base; +package cn.hippo4j.common.model; import lombok.Data; diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntime.java b/infra/common/src/main/java/cn/hippo4j/common/support/AbstractThreadPoolRuntime.java similarity index 88% rename from threadpool/core/src/main/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntime.java rename to infra/common/src/main/java/cn/hippo4j/common/support/AbstractThreadPoolRuntime.java index 0066438e26..f227137e7e 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntime.java +++ b/infra/common/src/main/java/cn/hippo4j/common/support/AbstractThreadPoolRuntime.java @@ -15,16 +15,17 @@ * limitations under the License. */ -package cn.hippo4j.core.executor.state; +package cn.hippo4j.common.support; import cn.hippo4j.common.executor.ThreadPoolExecutorHolder; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.CalculateUtil; -import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.common.toolkit.ReflectUtil; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executor; import java.util.concurrent.ThreadPoolExecutor; @@ -68,7 +69,13 @@ public ThreadPoolRunStateInfo getPoolRunState(String threadPoolId, Executor exec int activeCount = actualExecutor.getActiveCount(); int largestPoolSize = actualExecutor.getLargestPoolSize(); BlockingQueue blockingQueue = actualExecutor.getQueue(); - long rejectCount = actualExecutor instanceof DynamicThreadPoolExecutor ? ((DynamicThreadPoolExecutor) actualExecutor).getRejectCountNum() : NO_REJECT_COUNT_NUM; + long rejectCount = NO_REJECT_COUNT_NUM; + if (Objects.equals(actualExecutor.getClass().getName(), "cn.hippo4j.core.executor.DynamicThreadPoolExecutor")) { + Object actualRejectCountNum = ReflectUtil.invoke(actualExecutor, "getRejectCountNum"); + if (actualRejectCountNum != null) { + rejectCount = (long) actualRejectCountNum; + } + } ThreadPoolRunStateInfo stateInfo = ThreadPoolRunStateInfo.builder() .tpId(threadPoolId) .activeSize(activeCount) diff --git a/kernel/monitor/pom.xml b/kernel/monitor/pom.xml new file mode 100644 index 0000000000..cdfd04bdf1 --- /dev/null +++ b/kernel/monitor/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-kernel + ${revision} + + + hippo4j-threadpool-kernel-monitor + + + + cn.hippo4j + hippo4j-threadpool-infra-common + ${project.version} + + + \ No newline at end of file diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AdapterThreadPoolMonitor.java b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/AdapterThreadPoolMonitor.java similarity index 95% rename from threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AdapterThreadPoolMonitor.java rename to kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/AdapterThreadPoolMonitor.java index 520b4ffd21..b7f823bc01 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AdapterThreadPoolMonitor.java +++ b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/AdapterThreadPoolMonitor.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.monitor.base; +package cn.hippo4j.threadpool.monitor.api; /** * Adapter thread-pool monitor. diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/DynamicThreadPoolMonitor.java b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/DynamicThreadPoolMonitor.java similarity index 95% rename from threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/DynamicThreadPoolMonitor.java rename to kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/DynamicThreadPoolMonitor.java index 7e8c745216..135673471d 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/DynamicThreadPoolMonitor.java +++ b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/DynamicThreadPoolMonitor.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.monitor.base; +package cn.hippo4j.threadpool.monitor.api; /** * Dynamic thread-pool monitor. diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/ThreadPoolMonitor.java b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/ThreadPoolMonitor.java similarity index 96% rename from threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/ThreadPoolMonitor.java rename to kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/ThreadPoolMonitor.java index b8f54211ba..9ece85ce36 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/ThreadPoolMonitor.java +++ b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/ThreadPoolMonitor.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.monitor.base; +package cn.hippo4j.threadpool.monitor.api; /** * Thread-pool runtime monitor. diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/WebThreadPoolMonitor.java b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/WebThreadPoolMonitor.java similarity index 89% rename from threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/WebThreadPoolMonitor.java rename to kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/WebThreadPoolMonitor.java index 75b40fb774..069f3e31a0 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/WebThreadPoolMonitor.java +++ b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/api/WebThreadPoolMonitor.java @@ -15,7 +15,9 @@ * limitations under the License. */ -package cn.hippo4j.monitor.base; +package cn.hippo4j.threadpool.monitor.api; + +import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor; /** * Web thread-pool monitor. diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/MonitorThreadPoolTypeEnum.java b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/support/MonitorThreadPoolTypeEnum.java similarity index 95% rename from threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/MonitorThreadPoolTypeEnum.java rename to kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/support/MonitorThreadPoolTypeEnum.java index 1aabdec400..00b5265a65 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/MonitorThreadPoolTypeEnum.java +++ b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/support/MonitorThreadPoolTypeEnum.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.monitor.base; +package cn.hippo4j.threadpool.monitor.support; /** * Monitor thread-pool type enum. diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/MonitorTypeEnum.java b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/support/MonitorTypeEnum.java similarity index 95% rename from threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/MonitorTypeEnum.java rename to kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/support/MonitorTypeEnum.java index ee6f5dc74b..7574279ac2 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/MonitorTypeEnum.java +++ b/kernel/monitor/src/main/java/cn/hippo4j/threadpool/monitor/support/MonitorTypeEnum.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package cn.hippo4j.monitor.base; +package cn.hippo4j.threadpool.monitor.support; /** * Monitor type enum. diff --git a/kernel/pom.xml b/kernel/pom.xml index 3b194094d3..3448f00b3f 100644 --- a/kernel/pom.xml +++ b/kernel/pom.xml @@ -16,5 +16,6 @@ alarm dynamic message + monitor \ No newline at end of file diff --git a/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfiguration.java b/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfiguration.java index af82973df3..3087ec5824 100644 --- a/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfiguration.java +++ b/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebAdapterConfiguration.java @@ -20,13 +20,19 @@ import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose; import cn.hippo4j.adapter.web.WebThreadPoolRunStateHandler; import cn.hippo4j.core.config.ApplicationContextHolder; +import cn.hippo4j.core.config.UtilAutoConfiguration; import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.toolkit.inet.InetUtils; import lombok.RequiredArgsConstructor; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Import; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; /** @@ -37,6 +43,7 @@ WebThreadPoolHandlerConfiguration.EmbeddedJetty.class, WebThreadPoolHandlerConfiguration.EmbeddedUndertow.class}) @RequiredArgsConstructor +@AutoConfigureAfter(UtilAutoConfiguration.class) public class WebAdapterConfiguration { private final ConfigurableEnvironment environment; diff --git a/starters/threadpool/adapter/web/src/main/resources/META-INF/spring.factories b/starters/threadpool/adapter/web/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..2354dd6a1a --- /dev/null +++ b/starters/threadpool/adapter/web/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration diff --git a/starters/threadpool/config-spring-boot-1x/src/main/java/cn/hippo4j/config/springboot1x/starter/web/tomcat/TomcatWebThreadPoolHandler1x.java b/starters/threadpool/config-spring-boot-1x/src/main/java/cn/hippo4j/config/springboot1x/starter/web/tomcat/TomcatWebThreadPoolHandler1x.java index 5d87bb67a0..66dfa28918 100644 --- a/starters/threadpool/config-spring-boot-1x/src/main/java/cn/hippo4j/config/springboot1x/starter/web/tomcat/TomcatWebThreadPoolHandler1x.java +++ b/starters/threadpool/config-spring-boot-1x/src/main/java/cn/hippo4j/config/springboot1x/starter/web/tomcat/TomcatWebThreadPoolHandler1x.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.web.tomcat.TomcatWebThreadPoolHandlerSupport; import cn.hippo4j.config.springboot1x.starter.web.AbstractWebThreadPoolService1x; -import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime; +import cn.hippo4j.common.support.AbstractThreadPoolRuntime; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; diff --git a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java index 079d0f05ee..bdc0196e26 100644 --- a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java +++ b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/ConfigHandlerConfiguration.java @@ -38,6 +38,7 @@ * Config handler configuration. */ @Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") public class ConfigHandlerConfiguration { private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager"; diff --git a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index b1cc647a4c..a00fe0fd6a 100644 --- a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -19,7 +19,6 @@ import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.common.toolkit.StringUtil; -import cn.hippo4j.config.springboot.starter.monitor.ThreadPoolMonitorExecutor; import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder; import cn.hippo4j.config.springboot.starter.refresher.event.AdapterExecutorsRefreshListener; import cn.hippo4j.config.springboot.starter.refresher.event.DynamicThreadPoolRefreshListener; @@ -29,12 +28,9 @@ import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolConfigService; import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolPostProcessor; import cn.hippo4j.core.config.ApplicationContextHolder; -import cn.hippo4j.core.config.UtilAutoConfiguration; import cn.hippo4j.core.enable.MarkerConfiguration; import cn.hippo4j.core.executor.handler.DynamicThreadPoolBannerHandler; import cn.hippo4j.core.extension.initialize.Hippo4jDynamicThreadPoolInitializer; -import cn.hippo4j.message.config.MessageConfiguration; -import cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration; import cn.hippo4j.threadpool.alarm.api.ThreadPoolCheckAlarm; import cn.hippo4j.threadpool.alarm.handler.DefaultThreadPoolCheckAlarmHandler; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; @@ -46,7 +42,6 @@ import cn.hippo4j.threadpool.message.core.service.WebThreadPoolConfigChangeHandler; import lombok.AllArgsConstructor; import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -54,6 +49,7 @@ import org.springframework.boot.info.BuildProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -70,10 +66,9 @@ @Configuration @AllArgsConstructor @ConditionalOnBean(MarkerConfiguration.Marker.class) -@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @EnableConfigurationProperties(SpringBootstrapConfigProperties.class) @Import(ConfigHandlerConfiguration.class) -@ImportAutoConfiguration({WebAdapterConfiguration.class, UtilAutoConfiguration.class, MessageConfiguration.class}) +@ConditionalOnProperty(prefix = BootstrapConfigProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") public class DynamicThreadPoolAutoConfiguration { private final BootstrapConfigProperties bootstrapConfigProperties; @@ -114,15 +109,11 @@ public WebThreadPoolConfigChangeHandler webThreadPoolConfigChangeHandler(Bootstr } @Bean - public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor(ApplicationContextHolder hippo4jApplicationContextHolder) { + @DependsOn("hippo4jApplicationContextHolder") + public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor() { return new DynamicThreadPoolPostProcessor(bootstrapConfigProperties); } - @Bean - public ThreadPoolMonitorExecutor hippo4jDynamicThreadPoolMonitorExecutor() { - return new ThreadPoolMonitorExecutor(bootstrapConfigProperties); - } - @Bean @SuppressWarnings("all") public DynamicThreadPoolRefreshListener hippo4jExecutorsListener(DefaultThreadPoolConfigChangeHandler threadPoolConfigChange, diff --git a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/MonitorConfiguration.java b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/MonitorConfiguration.java new file mode 100644 index 0000000000..8eceb02317 --- /dev/null +++ b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/config/MonitorConfiguration.java @@ -0,0 +1,41 @@ +/* + * 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.config.springboot.starter.config; + +import cn.hippo4j.config.springboot.starter.monitor.ThreadPoolMonitorExecutor; +import cn.hippo4j.core.enable.MarkerConfiguration; +import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; +import lombok.AllArgsConstructor; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@AllArgsConstructor +@EnableConfigurationProperties(SpringBootstrapConfigProperties.class) +public class MonitorConfiguration { + + private final BootstrapConfigProperties bootstrapConfigProperties; + + @Bean + public ThreadPoolMonitorExecutor hippo4jDynamicThreadPoolMonitorExecutor() { + return new ThreadPoolMonitorExecutor(bootstrapConfigProperties); + } +} diff --git a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java index ef9447cb12..a9cce9b0a2 100644 --- a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java +++ b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java @@ -22,10 +22,10 @@ import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry; import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.core.config.ApplicationContextHolder; -import cn.hippo4j.monitor.base.DynamicThreadPoolMonitor; -import cn.hippo4j.monitor.base.ThreadPoolMonitor; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.MonitorProperties; +import cn.hippo4j.threadpool.monitor.api.DynamicThreadPoolMonitor; +import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.DisposableBean; diff --git a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AdapterExecutorsRefreshListener.java b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AdapterExecutorsRefreshListener.java index 7bd823e357..b521a52620 100644 --- a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AdapterExecutorsRefreshListener.java +++ b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/event/AdapterExecutorsRefreshListener.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.CollectionUtil; diff --git a/starters/threadpool/config/src/main/resources/META-INF/spring.factories b/starters/threadpool/config/src/main/resources/META-INF/spring.factories index 89ccf30182..0d75c58b3b 100644 --- a/starters/threadpool/config/src/main/resources/META-INF/spring.factories +++ b/starters/threadpool/config/src/main/resources/META-INF/spring.factories @@ -1 +1,5 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot.starter.config.DynamicThreadPoolAutoConfiguration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.config.springboot.starter.config.DynamicThreadPoolAutoConfiguration,\ +cn.hippo4j.core.config.UtilAutoConfiguration,\ +cn.hippo4j.message.config.MessageConfiguration,\ +cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration,\ +cn.hippo4j.config.springboot.starter.config.MonitorConfiguration \ No newline at end of file diff --git a/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-elasticsearch/src/main/java/cn/hippo4j/springboot/starter/monitor/elasticsearch/ElasticSearchMonitorAutoConfiguration.java b/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-elasticsearch/src/main/java/cn/hippo4j/springboot/starter/monitor/elasticsearch/ElasticSearchMonitorAutoConfiguration.java index c5b2e2f085..5c8bd5c2da 100644 --- a/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-elasticsearch/src/main/java/cn/hippo4j/springboot/starter/monitor/elasticsearch/ElasticSearchMonitorAutoConfiguration.java +++ b/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-elasticsearch/src/main/java/cn/hippo4j/springboot/starter/monitor/elasticsearch/ElasticSearchMonitorAutoConfiguration.java @@ -17,14 +17,13 @@ package cn.hippo4j.springboot.starter.monitor.elasticsearch; -import cn.hippo4j.common.constant.Constants; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.enable.MarkerConfiguration; import cn.hippo4j.monitor.elasticsearch.AdapterThreadPoolElasticSearchMonitorHandler; import cn.hippo4j.monitor.elasticsearch.DynamicThreadPoolElasticSearchMonitorHandler; import cn.hippo4j.monitor.elasticsearch.WebThreadPoolElasticSearchMonitorHandler; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,24 +33,23 @@ @Configuration @ConditionalOnBean(MarkerConfiguration.Marker.class) @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.collect-types:}'.contains('elasticsearch')") -@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") public class ElasticSearchMonitorAutoConfiguration { @Bean @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')") - public DynamicThreadPoolElasticSearchMonitorHandler dynamicThreadPoolElasticSearchMonitorHandler() { - return new DynamicThreadPoolElasticSearchMonitorHandler(); + public DynamicThreadPoolElasticSearchMonitorHandler dynamicThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) { + return new DynamicThreadPoolElasticSearchMonitorHandler(handler); } @Bean @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('web')") - public WebThreadPoolElasticSearchMonitorHandler webThreadPoolElasticSearchMonitorHandler() { - return new WebThreadPoolElasticSearchMonitorHandler(); + public WebThreadPoolElasticSearchMonitorHandler webThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) { + return new WebThreadPoolElasticSearchMonitorHandler(handler); } @Bean @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('adapter')") - public AdapterThreadPoolElasticSearchMonitorHandler adapterThreadPoolElasticSearchMonitorHandler() { - return new AdapterThreadPoolElasticSearchMonitorHandler(); + public AdapterThreadPoolElasticSearchMonitorHandler adapterThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) { + return new AdapterThreadPoolElasticSearchMonitorHandler(handler); } } diff --git a/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-local-log/src/main/java/cn/hippo4j/springboot/starter/monitor/local/log/LocalLogMonitorAutoConfiguration.java b/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-local-log/src/main/java/cn/hippo4j/springboot/starter/monitor/local/log/LocalLogMonitorAutoConfiguration.java index 01394baa74..c9e8438a2d 100644 --- a/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-local-log/src/main/java/cn/hippo4j/springboot/starter/monitor/local/log/LocalLogMonitorAutoConfiguration.java +++ b/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-local-log/src/main/java/cn/hippo4j/springboot/starter/monitor/local/log/LocalLogMonitorAutoConfiguration.java @@ -18,14 +18,13 @@ package cn.hippo4j.springboot.starter.monitor.local.log; import cn.hippo4j.adapter.web.WebThreadPoolService; -import cn.hippo4j.common.constant.Constants; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.enable.MarkerConfiguration; import cn.hippo4j.monitor.local.log.AdapterThreadPoolLocalLogMonitorHandler; import cn.hippo4j.monitor.local.log.DynamicThreadPoolLocalLogMonitorHandler; import cn.hippo4j.monitor.local.log.WebThreadPoolLocalLogMonitorHandler; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,13 +34,12 @@ @Configuration @ConditionalOnBean(MarkerConfiguration.Marker.class) @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.collect-types:}'.contains('log')") -@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") public class LocalLogMonitorAutoConfiguration { @Bean @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')") - public DynamicThreadPoolLocalLogMonitorHandler dynamicThreadPoolLocalLogMonitorHandler() { - return new DynamicThreadPoolLocalLogMonitorHandler(); + public DynamicThreadPoolLocalLogMonitorHandler dynamicThreadPoolLocalLogMonitorHandler(ThreadPoolRunStateHandler handler) { + return new DynamicThreadPoolLocalLogMonitorHandler(handler); } @Bean diff --git a/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-micrometer/src/main/java/cn/hippo4j/springboot/starter/monitor/micrometer/MicrometerMonitorAutoConfiguration.java b/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-micrometer/src/main/java/cn/hippo4j/springboot/starter/monitor/micrometer/MicrometerMonitorAutoConfiguration.java index 5946a2c121..1eb7b70b1b 100644 --- a/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-micrometer/src/main/java/cn/hippo4j/springboot/starter/monitor/micrometer/MicrometerMonitorAutoConfiguration.java +++ b/starters/threadpool/monitor/hippo4j-spring-boot-starter-monitor-micrometer/src/main/java/cn/hippo4j/springboot/starter/monitor/micrometer/MicrometerMonitorAutoConfiguration.java @@ -18,16 +18,16 @@ package cn.hippo4j.springboot.starter.monitor.micrometer; import cn.hippo4j.adapter.web.WebThreadPoolService; -import cn.hippo4j.common.constant.Constants; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.enable.MarkerConfiguration; import cn.hippo4j.monitor.micrometer.AdapterThreadPoolMicrometerMonitorHandler; import cn.hippo4j.monitor.micrometer.DynamicThreadPoolMicrometerMonitorHandler; import cn.hippo4j.monitor.micrometer.WebThreadPoolMicrometerMonitorHandler; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; /** * Micrometer monitor auto configuration. @@ -35,14 +35,12 @@ @Configuration @ConditionalOnBean(MarkerConfiguration.Marker.class) @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.collect-types:}'.contains('micrometer')") -@ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") public class MicrometerMonitorAutoConfiguration { @Bean @ConditionalOnExpression("'${spring.dynamic.thread-pool.monitor.thread-pool-types:}'.contains('dynamic')") - @ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") - public DynamicThreadPoolMicrometerMonitorHandler dynamicThreadPoolMicrometerMonitorHandler() { - return new DynamicThreadPoolMicrometerMonitorHandler(); + public DynamicThreadPoolMicrometerMonitorHandler dynamicThreadPoolMicrometerMonitorHandler(ThreadPoolRunStateHandler handler) { + return new DynamicThreadPoolMicrometerMonitorHandler(handler); } @Bean diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index 8e901da79e..50d59116e8 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -138,6 +138,7 @@ public AdaptedThreadPoolDestroyPostProcessor adaptedThreadPoolDestroyPostProcess } @Bean + @ConditionalOnProperty(prefix = Constants.CONFIGURATION_PROPERTIES_PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @SuppressWarnings("all") public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent, ApplicationContextHolder hippo4jApplicationContextHolder, diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/MonitorProperties.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/MonitorProperties.java index 9a72c96b64..cee9336cdd 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/MonitorProperties.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/config/MonitorProperties.java @@ -17,8 +17,8 @@ package cn.hippo4j.springboot.starter.config; -import cn.hippo4j.monitor.base.MonitorThreadPoolTypeEnum; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorThreadPoolTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import lombok.Data; /** diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/controller/ThreadPoolAdapterController.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/controller/ThreadPoolAdapterController.java index 7529630f34..25addd96f8 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/controller/ThreadPoolAdapterController.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/controller/ThreadPoolAdapterController.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.model.Result; import cn.hippo4j.core.api.ClientNetworkService; import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry; diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java index 82f67457ad..852ce85d26 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java @@ -20,7 +20,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig; import cn.hippo4j.adapter.base.ThreadPoolAdapterRegisterAction; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.model.Result; import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.common.toolkit.CollectionUtil; diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java index 795521d791..0038c62d26 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java @@ -25,13 +25,13 @@ import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.ThreadUtil; import cn.hippo4j.core.config.ApplicationContextHolder; -import cn.hippo4j.monitor.base.MonitorTypeEnum; -import cn.hippo4j.monitor.base.ThreadPoolMonitor; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import cn.hippo4j.springboot.starter.config.BootstrapProperties; import cn.hippo4j.springboot.starter.config.MonitorProperties; import cn.hippo4j.springboot.starter.monitor.collect.Collector; import cn.hippo4j.springboot.starter.monitor.send.MessageSender; import cn.hippo4j.springboot.starter.remote.ServerHealthCheck; +import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/RunTimeInfoCollector.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/RunTimeInfoCollector.java index c8b85771b6..393e2ba07a 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/RunTimeInfoCollector.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/collect/RunTimeInfoCollector.java @@ -24,7 +24,7 @@ import cn.hippo4j.common.monitor.MessageTypeEnum; import cn.hippo4j.common.monitor.RuntimeMessage; import cn.hippo4j.common.toolkit.BeanUtil; -import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime; +import cn.hippo4j.common.support.AbstractThreadPoolRuntime; import cn.hippo4j.springboot.starter.config.BootstrapProperties; import lombok.AllArgsConstructor; diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/support/AdaptedThreadPoolDestroyPostProcessor.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/support/AdaptedThreadPoolDestroyPostProcessor.java index bad47f90be..0490b32b59 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/support/AdaptedThreadPoolDestroyPostProcessor.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/support/AdaptedThreadPoolDestroyPostProcessor.java @@ -20,7 +20,7 @@ import cn.hippo4j.common.executor.ThreadPoolExecutorHolder; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; -import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapter; +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/threadpool/adapter/alibaba-dubbo/src/main/java/cn/hippo4j/adapter/alibaba/dubbo/AlibabaDubboThreadPoolAdapter.java b/threadpool/adapter/alibaba-dubbo/src/main/java/cn/hippo4j/adapter/alibaba/dubbo/AlibabaDubboThreadPoolAdapter.java index 2209089e2f..c110624a99 100644 --- a/threadpool/adapter/alibaba-dubbo/src/main/java/cn/hippo4j/adapter/alibaba/dubbo/AlibabaDubboThreadPoolAdapter.java +++ b/threadpool/adapter/alibaba-dubbo/src/main/java/cn/hippo4j/adapter/alibaba/dubbo/AlibabaDubboThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import com.alibaba.dubbo.common.extension.ExtensionLoader; import com.alibaba.dubbo.common.store.DataStore; diff --git a/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java b/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java index 20b39602a3..23f98cf84e 100644 --- a/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java +++ b/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapter.java @@ -17,6 +17,8 @@ package cn.hippo4j.adapter.base; +import cn.hippo4j.common.model.ThreadPoolAdapterState; + import java.util.List; /** diff --git a/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterCacheConfig.java b/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterCacheConfig.java index 07b2c73c4b..6117d803f7 100644 --- a/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterCacheConfig.java +++ b/threadpool/adapter/base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterCacheConfig.java @@ -17,6 +17,7 @@ package cn.hippo4j.adapter.base; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import lombok.Data; import java.util.List; diff --git a/threadpool/adapter/dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java b/threadpool/adapter/dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java index ffc618317d..cca28fb0fd 100644 --- a/threadpool/adapter/dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java +++ b/threadpool/adapter/dubbo/src/main/java/cn/hippo4j/adapter/dubbo/DubboThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import lombok.extern.slf4j.Slf4j; diff --git a/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/AbstractHystrixThreadPoolAdapter.java b/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/AbstractHystrixThreadPoolAdapter.java index 36771408f3..9108680cd8 100644 --- a/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/AbstractHystrixThreadPoolAdapter.java +++ b/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/AbstractHystrixThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import com.netflix.hystrix.HystrixThreadPool; diff --git a/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter4Server.java b/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter4Server.java index fbd5b94a5c..92e6b43e3e 100644 --- a/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter4Server.java +++ b/threadpool/adapter/hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter4Server.java @@ -20,7 +20,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig; import cn.hippo4j.adapter.base.ThreadPoolAdapterRegisterAction; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.core.config.ApplicationContextHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationStartedEvent; diff --git a/threadpool/adapter/kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java b/threadpool/adapter/kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java index 44c8cacee5..b87d9b8968 100644 --- a/threadpool/adapter/kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java +++ b/threadpool/adapter/kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.core.config.ApplicationContextHolder; import lombok.SneakyThrows; diff --git a/threadpool/adapter/rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java b/threadpool/adapter/rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java index b8b5ae1e00..09de9206a7 100644 --- a/threadpool/adapter/rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java +++ b/threadpool/adapter/rabbitmq/src/main/java/cn/hippo4j/adapter/rabbitmq/RabbitMQThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import lombok.RequiredArgsConstructor; diff --git a/threadpool/adapter/rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java b/threadpool/adapter/rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java index 2334f0e3d3..bd2599e78a 100644 --- a/threadpool/adapter/rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java +++ b/threadpool/adapter/rocketmq/src/main/java/cn/hippo4j/adapter/rocketmq/RocketMQThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import cn.hippo4j.core.config.ApplicationContextHolder; diff --git a/threadpool/adapter/stream-rabbitmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rabbitmq/SpringCloudStreamRabbitMQThreadPoolAdapter.java b/threadpool/adapter/stream-rabbitmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rabbitmq/SpringCloudStreamRabbitMQThreadPoolAdapter.java index 144dcfb2f4..eeebaa5a3e 100644 --- a/threadpool/adapter/stream-rabbitmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rabbitmq/SpringCloudStreamRabbitMQThreadPoolAdapter.java +++ b/threadpool/adapter/stream-rabbitmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rabbitmq/SpringCloudStreamRabbitMQThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.core.config.ApplicationContextHolder; diff --git a/threadpool/adapter/stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java b/threadpool/adapter/stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java index 10b11eab21..3438dc2d5d 100644 --- a/threadpool/adapter/stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java +++ b/threadpool/adapter/stream-rocketmq/src/main/java/cn/hippo4j/adapter/springcloud/stream/rocketmq/SpringCloudStreamRocketMQThreadPoolAdapter.java @@ -19,7 +19,7 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; diff --git a/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java b/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java index a30c16c899..b42b9db95a 100644 --- a/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java +++ b/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/WebThreadPoolRunStateHandler.java @@ -21,7 +21,7 @@ import cn.hippo4j.common.toolkit.ByteConvertUtil; import cn.hippo4j.common.toolkit.MemoryUtil; import cn.hippo4j.common.toolkit.StringUtil; -import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime; +import cn.hippo4j.common.support.AbstractThreadPoolRuntime; import lombok.extern.slf4j.Slf4j; /** diff --git a/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/DefaultTomcatWebThreadPoolHandler.java b/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/DefaultTomcatWebThreadPoolHandler.java index b246199088..756536825e 100644 --- a/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/DefaultTomcatWebThreadPoolHandler.java +++ b/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/DefaultTomcatWebThreadPoolHandler.java @@ -18,7 +18,7 @@ package cn.hippo4j.adapter.web.tomcat; import cn.hippo4j.adapter.web.DefaultAbstractWebThreadPoolService; -import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime; +import cn.hippo4j.common.support.AbstractThreadPoolRuntime; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; import org.springframework.boot.web.server.WebServer; diff --git a/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/TomcatWebThreadPoolHandlerSupport.java b/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/TomcatWebThreadPoolHandlerSupport.java index d04d2af331..20701e0687 100644 --- a/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/TomcatWebThreadPoolHandlerSupport.java +++ b/threadpool/adapter/web/src/main/java/cn/hippo4j/adapter/web/tomcat/TomcatWebThreadPoolHandlerSupport.java @@ -25,7 +25,7 @@ import cn.hippo4j.common.model.ThreadPoolParameterInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.CalculateUtil; -import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime; +import cn.hippo4j.common.support.AbstractThreadPoolRuntime; import lombok.extern.slf4j.Slf4j; import java.time.LocalDateTime; diff --git a/threadpool/core/pom.xml b/threadpool/core/pom.xml index 1df9e3a9e3..903c73deef 100644 --- a/threadpool/core/pom.xml +++ b/threadpool/core/pom.xml @@ -29,6 +29,11 @@ hippo4j-threadpool-kernel-alarm ${project.version} + + cn.hippo4j + hippo4j-threadpool-kernel-monitor + ${project.version} + org.springframework.boot spring-boot-starter-test diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandler.java b/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandler.java index 8d27ef3f3f..8f77e0c61d 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandler.java +++ b/threadpool/core/src/main/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandler.java @@ -19,8 +19,10 @@ import cn.hippo4j.common.executor.ThreadPoolExecutorHolder; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; +import cn.hippo4j.common.handler.ThreadPoolStatusHandler; import cn.hippo4j.common.model.ManyThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; +import cn.hippo4j.common.support.AbstractThreadPoolRuntime; import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.ByteConvertUtil; import cn.hippo4j.common.toolkit.MemoryUtil; @@ -66,7 +68,8 @@ public ThreadPoolRunStateInfo supplement(ThreadPoolRunStateInfo poolRunStateInfo String rejectedName; rejectedName = pool.getRejectedExecutionHandler().getClass().getSimpleName(); poolRunStateInfo.setRejectedName(rejectedName); - ManyThreadPoolRunStateInfo manyThreadPoolRunStateInfo = BeanUtil.convert(poolRunStateInfo, ManyThreadPoolRunStateInfo.class); + + ManyThreadPoolRunStateInfo manyThreadPoolRunStateInfo = convert(poolRunStateInfo); manyThreadPoolRunStateInfo.setIdentify(CLIENT_IDENTIFICATION_VALUE); String active = environment.getProperty("spring.profiles.active", "UNKNOWN"); manyThreadPoolRunStateInfo.setActive(active.toUpperCase()); @@ -74,4 +77,31 @@ public ThreadPoolRunStateInfo supplement(ThreadPoolRunStateInfo poolRunStateInfo manyThreadPoolRunStateInfo.setState(threadPoolState); return manyThreadPoolRunStateInfo; } + + private ManyThreadPoolRunStateInfo convert(ThreadPoolRunStateInfo poolRunStateInfo) { + ManyThreadPoolRunStateInfo manyThreadPoolRunStateInfo = new ManyThreadPoolRunStateInfo(); + manyThreadPoolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad()); + manyThreadPoolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad()); + manyThreadPoolRunStateInfo.setTpId(poolRunStateInfo.getTpId()); + manyThreadPoolRunStateInfo.setActiveCount(poolRunStateInfo.getActiveCount()); + manyThreadPoolRunStateInfo.setPoolSize(poolRunStateInfo.getPoolSize()); + manyThreadPoolRunStateInfo.setActiveSize(poolRunStateInfo.getActiveSize()); + manyThreadPoolRunStateInfo.setLargestPoolSize(poolRunStateInfo.getLargestPoolSize()); + manyThreadPoolRunStateInfo.setQueueSize(poolRunStateInfo.getQueueSize()); + manyThreadPoolRunStateInfo.setQueueRemainingCapacity(poolRunStateInfo.getQueueRemainingCapacity()); + manyThreadPoolRunStateInfo.setCompletedTaskCount(poolRunStateInfo.getCompletedTaskCount()); + manyThreadPoolRunStateInfo.setRejectCount(poolRunStateInfo.getRejectCount()); + manyThreadPoolRunStateInfo.setHost(poolRunStateInfo.getHost()); + manyThreadPoolRunStateInfo.setMemoryProportion(poolRunStateInfo.getMemoryProportion()); + manyThreadPoolRunStateInfo.setFreeMemory(poolRunStateInfo.getFreeMemory()); + manyThreadPoolRunStateInfo.setClientLastRefreshTime(poolRunStateInfo.getClientLastRefreshTime()); + manyThreadPoolRunStateInfo.setTimestamp(poolRunStateInfo.getTimestamp()); + manyThreadPoolRunStateInfo.setCoreSize(poolRunStateInfo.getCoreSize()); + manyThreadPoolRunStateInfo.setMaximumSize(poolRunStateInfo.getMaximumSize()); + manyThreadPoolRunStateInfo.setQueueType(poolRunStateInfo.getQueueType()); + manyThreadPoolRunStateInfo.setQueueCapacity(poolRunStateInfo.getQueueCapacity()); + manyThreadPoolRunStateInfo.setRejectedName(poolRunStateInfo.getRejectedName()); + manyThreadPoolRunStateInfo.setKeepAliveTime(poolRunStateInfo.getKeepAliveTime()); + return manyThreadPoolRunStateInfo; + } } diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java index cce70f3609..b4f757166b 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java +++ b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/DynamicThreadPoolAdapterChoose.java @@ -17,6 +17,7 @@ package cn.hippo4j.core.executor.support.adpter; +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry; import cn.hippo4j.common.toolkit.CollectionUtil; diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ThreadPoolTaskExecutorAdapter.java b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ThreadPoolTaskExecutorAdapter.java index 69e0ec8d6f..5d043596a7 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ThreadPoolTaskExecutorAdapter.java +++ b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ThreadPoolTaskExecutorAdapter.java @@ -17,6 +17,7 @@ package cn.hippo4j.core.executor.support.adpter; +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.support.ThreadPoolBuilder; diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorAdapter.java b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorAdapter.java index b848a8eda5..a99bf1c94a 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorAdapter.java +++ b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorAdapter.java @@ -17,6 +17,7 @@ package cn.hippo4j.core.executor.support.adpter; +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorServiceAdapter.java b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorServiceAdapter.java index 2597a0e625..4ed600741f 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorServiceAdapter.java +++ b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/TransmittableThreadLocalExecutorServiceAdapter.java @@ -17,6 +17,7 @@ package cn.hippo4j.core.executor.support.adpter; +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ZipkinExecutorAdapter.java b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ZipkinExecutorAdapter.java index f064e8f7eb..7f1cab3a9d 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ZipkinExecutorAdapter.java +++ b/threadpool/core/src/main/java/cn/hippo4j/core/executor/support/adpter/ZipkinExecutorAdapter.java @@ -17,6 +17,7 @@ package cn.hippo4j.core.executor.support.adpter; +import cn.hippo4j.common.api.DynamicThreadPoolAdapter; import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java index 39ce899f38..274249790c 100644 --- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java +++ b/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java @@ -19,6 +19,7 @@ import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; +import cn.hippo4j.common.support.AbstractThreadPoolRuntime; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import org.junit.Test; import org.junit.jupiter.api.Assertions; diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandlerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandlerTest.java index 0251b6bcaa..de54d21339 100644 --- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandlerTest.java +++ b/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandlerTest.java @@ -19,6 +19,7 @@ import cn.hippo4j.common.executor.ThreadPoolExecutorHolder; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; +import cn.hippo4j.common.handler.ThreadPoolStatusHandler; import cn.hippo4j.common.model.ManyThreadPoolRunStateInfo; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.BeanUtil; diff --git a/threadpool/message/src/main/java/cn/hippo4j/message/config/MessageConfiguration.java b/threadpool/message/src/main/java/cn/hippo4j/message/config/MessageConfiguration.java index 1deda548d0..221ba350e2 100644 --- a/threadpool/message/src/main/java/cn/hippo4j/message/config/MessageConfiguration.java +++ b/threadpool/message/src/main/java/cn/hippo4j/message/config/MessageConfiguration.java @@ -24,11 +24,13 @@ import cn.hippo4j.threadpool.message.core.service.AlarmControlHandler; import cn.hippo4j.threadpool.message.core.service.SendMessageHandler; import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; /** * Message configuration. */ +@ConditionalOnProperty(prefix = "spring.dynamic.thread-pool", value = "enable", matchIfMissing = true, havingValue = "true") public class MessageConfiguration { @Bean diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractAdapterThreadPoolMonitor.java b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractAdapterThreadPoolMonitor.java index ec5918c9b0..a2a7564750 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractAdapterThreadPoolMonitor.java +++ b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractAdapterThreadPoolMonitor.java @@ -18,8 +18,9 @@ package cn.hippo4j.monitor.base; import cn.hippo4j.adapter.base.ThreadPoolAdapter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.core.config.ApplicationContextHolder; +import cn.hippo4j.threadpool.monitor.api.AdapterThreadPoolMonitor; import java.util.Map; diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java index 7b55f1552d..c8dfe781d3 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java +++ b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java @@ -20,6 +20,7 @@ import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; +import cn.hippo4j.threadpool.monitor.api.DynamicThreadPoolMonitor; import javax.annotation.Resource; import java.util.List; @@ -29,9 +30,12 @@ */ public abstract class AbstractDynamicThreadPoolMonitor implements DynamicThreadPoolMonitor { - @Resource private ThreadPoolRunStateHandler threadPoolRunStateHandler; + public AbstractDynamicThreadPoolMonitor(ThreadPoolRunStateHandler handler) { + this.threadPoolRunStateHandler = handler; + } + /** * Execute collection thread pool running data. * diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java index ad0cb2dad8..f6b84ee45c 100644 --- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java +++ b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java @@ -19,6 +19,7 @@ import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; +import cn.hippo4j.threadpool.monitor.api.WebThreadPoolMonitor; import javax.annotation.Resource; diff --git a/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/AdapterThreadPoolElasticSearchMonitorHandler.java b/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/AdapterThreadPoolElasticSearchMonitorHandler.java index d20140c8cf..b0585a06b6 100644 --- a/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/AdapterThreadPoolElasticSearchMonitorHandler.java +++ b/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/AdapterThreadPoolElasticSearchMonitorHandler.java @@ -18,8 +18,9 @@ package cn.hippo4j.monitor.elasticsearch; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import lombok.extern.slf4j.Slf4j; /** @@ -28,6 +29,10 @@ @Slf4j public class AdapterThreadPoolElasticSearchMonitorHandler extends AbstractDynamicThreadPoolMonitor { + public AdapterThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) { + super(handler); + } + @Override protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { // TODO diff --git a/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/DynamicThreadPoolElasticSearchMonitorHandler.java b/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/DynamicThreadPoolElasticSearchMonitorHandler.java index e45f3d15c4..1d0efd4eea 100644 --- a/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/DynamicThreadPoolElasticSearchMonitorHandler.java +++ b/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/DynamicThreadPoolElasticSearchMonitorHandler.java @@ -21,9 +21,10 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.JSONUtil; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.toolkit.FileUtil; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import cn.hippo4j.monitor.elasticsearch.model.ElasticSearchThreadPoolRunStateInfo; import lombok.Builder; import lombok.Getter; @@ -55,6 +56,10 @@ public class DynamicThreadPoolElasticSearchMonitorHandler extends AbstractDynami private AtomicBoolean isIndexExist = null; + public DynamicThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) { + super(handler); + } + @Override protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { ElasticSearchThreadPoolRunStateInfo esThreadPoolRunStateInfo = BeanUtil.convert(poolRunStateInfo, ElasticSearchThreadPoolRunStateInfo.class); diff --git a/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/WebThreadPoolElasticSearchMonitorHandler.java b/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/WebThreadPoolElasticSearchMonitorHandler.java index 83bdcfe8b0..415a9a52c3 100644 --- a/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/WebThreadPoolElasticSearchMonitorHandler.java +++ b/threadpool/monitor/elasticsearch/src/main/java/cn/hippo4j/monitor/elasticsearch/WebThreadPoolElasticSearchMonitorHandler.java @@ -18,8 +18,9 @@ package cn.hippo4j.monitor.elasticsearch; import cn.hippo4j.common.model.ThreadPoolRunStateInfo; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import lombok.extern.slf4j.Slf4j; /** @@ -28,6 +29,10 @@ @Slf4j public class WebThreadPoolElasticSearchMonitorHandler extends AbstractDynamicThreadPoolMonitor { + public WebThreadPoolElasticSearchMonitorHandler(ThreadPoolRunStateHandler handler) { + super(handler); + } + @Override protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { // TODO diff --git a/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/AdapterThreadPoolLocalLogMonitorHandler.java b/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/AdapterThreadPoolLocalLogMonitorHandler.java index b7a8113c01..35080655a1 100644 --- a/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/AdapterThreadPoolLocalLogMonitorHandler.java +++ b/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/AdapterThreadPoolLocalLogMonitorHandler.java @@ -17,10 +17,10 @@ package cn.hippo4j.monitor.local.log; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.monitor.base.AbstractAdapterThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import lombok.extern.slf4j.Slf4j; /** diff --git a/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/DynamicThreadPoolLocalLogMonitorHandler.java b/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/DynamicThreadPoolLocalLogMonitorHandler.java index 71e6ea19ef..37ad73f3fd 100644 --- a/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/DynamicThreadPoolLocalLogMonitorHandler.java +++ b/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/DynamicThreadPoolLocalLogMonitorHandler.java @@ -19,8 +19,9 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.JSONUtil; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import lombok.extern.slf4j.Slf4j; /** @@ -29,6 +30,10 @@ @Slf4j public class DynamicThreadPoolLocalLogMonitorHandler extends AbstractDynamicThreadPoolMonitor { + public DynamicThreadPoolLocalLogMonitorHandler(ThreadPoolRunStateHandler handler) { + super(handler); + } + @Override protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { log.info("{}", JSONUtil.toJSONString(poolRunStateInfo)); diff --git a/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/WebThreadPoolLocalLogMonitorHandler.java b/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/WebThreadPoolLocalLogMonitorHandler.java index 4141eab140..af0cdf3e5f 100644 --- a/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/WebThreadPoolLocalLogMonitorHandler.java +++ b/threadpool/monitor/local-log/src/main/java/cn/hippo4j/monitor/local/log/WebThreadPoolLocalLogMonitorHandler.java @@ -20,7 +20,7 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.monitor.base.AbstractWebThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import lombok.extern.slf4j.Slf4j; /** diff --git a/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/AdapterThreadPoolMicrometerMonitorHandler.java b/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/AdapterThreadPoolMicrometerMonitorHandler.java index aeaa4f225d..ea99366355 100644 --- a/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/AdapterThreadPoolMicrometerMonitorHandler.java +++ b/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/AdapterThreadPoolMicrometerMonitorHandler.java @@ -17,12 +17,12 @@ package cn.hippo4j.monitor.micrometer; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.monitor.base.AbstractAdapterThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Tag; import org.springframework.core.env.Environment; diff --git a/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/DynamicThreadPoolMicrometerMonitorHandler.java b/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/DynamicThreadPoolMicrometerMonitorHandler.java index 748f8068bc..5bfe747cae 100644 --- a/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/DynamicThreadPoolMicrometerMonitorHandler.java +++ b/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/DynamicThreadPoolMicrometerMonitorHandler.java @@ -21,8 +21,9 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo; import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.CollectionUtil; +import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Tag; import org.springframework.core.env.Environment; @@ -43,6 +44,10 @@ public class DynamicThreadPoolMicrometerMonitorHandler extends AbstractDynamicTh private final Map runStateCache = new ConcurrentHashMap<>(); + public DynamicThreadPoolMicrometerMonitorHandler(ThreadPoolRunStateHandler handler) { + super(handler); + } + @Override protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) { ThreadPoolRunStateInfo stateInfo = runStateCache.get(poolRunStateInfo.getTpId()); diff --git a/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/WebThreadPoolMicrometerMonitorHandler.java b/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/WebThreadPoolMicrometerMonitorHandler.java index f61eda61d7..c60fb9548e 100644 --- a/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/WebThreadPoolMicrometerMonitorHandler.java +++ b/threadpool/monitor/micrometer/src/main/java/cn/hippo4j/monitor/micrometer/WebThreadPoolMicrometerMonitorHandler.java @@ -22,7 +22,7 @@ import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.monitor.base.AbstractWebThreadPoolMonitor; -import cn.hippo4j.monitor.base.MonitorTypeEnum; +import cn.hippo4j.threadpool.monitor.support.MonitorTypeEnum; import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Tag; import org.springframework.core.env.Environment; diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java index 3d69cd5692..0f9e51720d 100644 --- a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java +++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java @@ -18,7 +18,7 @@ package cn.hippo4j.config.service; import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig; -import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import cn.hippo4j.common.model.ThreadPoolAdapterState; import cn.hippo4j.common.extension.design.AbstractSubjectCenter; import cn.hippo4j.common.extension.design.Observer; import cn.hippo4j.common.extension.design.ObserverMessage;