Abstract alarm and notification kernel modules and refactor existing code (#1376)

pull/1377/head
magestack 1 year ago committed by GitHub
parent 8474026758
commit 4248512d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@
package cn.hippo4j.agent.adapter.dubbo; package cn.hippo4j.agent.adapter.dubbo;
import cn.hippo4j.common.executor.ThreadPoolRegistry; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.model.executor.ExecutorProperties; import cn.hippo4j.common.model.executor.ExecutorProperties;
@ -78,7 +78,7 @@ public class DubboThreadPoolAdapter {
.queueCapacity(executor.getQueue().remainingCapacity()) .queueCapacity(executor.getQueue().remainingCapacity())
.rejectedHandler(RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(executor.getRejectedExecutionHandler().getClass().getSimpleName()).getName()) .rejectedHandler(RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(executor.getRejectedExecutionHandler().getClass().getSimpleName()).getName())
.build(); .build();
ThreadPoolRegistry.putHolder(executorName, executor, executorProperties); ThreadPoolExecutorRegistry.putHolder(executorName, executor, executorProperties);
} }
public static String mark() { public static String mark() {

@ -18,7 +18,7 @@
package cn.hippo4j.agent.plugin.spring.common.support; package cn.hippo4j.agent.plugin.spring.common.support;
import cn.hippo4j.agent.core.util.ReflectUtil; import cn.hippo4j.agent.core.util.ReflectUtil;
import cn.hippo4j.common.executor.ThreadPoolRegistry; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.model.executor.ExecutorProperties; import cn.hippo4j.common.model.executor.ExecutorProperties;
@ -41,7 +41,7 @@ public class SpringThreadPoolRegisterSupport {
private static final Logger LOGGER = LoggerFactory.getLogger(SpringThreadPoolRegisterSupport.class); private static final Logger LOGGER = LoggerFactory.getLogger(SpringThreadPoolRegisterSupport.class);
public static void registerThreadPoolInstances(ApplicationContext context) { public static void registerThreadPoolInstances(ApplicationContext context) {
Map<ThreadPoolExecutor, Class<?>> referencedClassMap = ThreadPoolRegistry.REFERENCED_CLASS_MAP; Map<ThreadPoolExecutor, Class<?>> referencedClassMap = ThreadPoolExecutorRegistry.REFERENCED_CLASS_MAP;
for (Map.Entry<ThreadPoolExecutor, Class<?>> entry : referencedClassMap.entrySet()) { for (Map.Entry<ThreadPoolExecutor, Class<?>> entry : referencedClassMap.entrySet()) {
ThreadPoolExecutor enhancedInstance = entry.getKey(); ThreadPoolExecutor enhancedInstance = entry.getKey();
Class<?> declaredClass = entry.getValue(); Class<?> declaredClass = entry.getValue();
@ -93,6 +93,6 @@ public class SpringThreadPoolRegisterSupport {
.queueCapacity(executor.getQueue().remainingCapacity()) .queueCapacity(executor.getQueue().remainingCapacity())
.rejectedHandler(RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(executor.getRejectedExecutionHandler().getClass().getSimpleName()).getName()) .rejectedHandler(RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(executor.getRejectedExecutionHandler().getClass().getSimpleName()).getName())
.build(); .build();
ThreadPoolRegistry.putHolder(threadPoolId, executor, executorProperties); ThreadPoolExecutorRegistry.putHolder(threadPoolId, executor, executorProperties);
} }
} }

@ -22,7 +22,7 @@ import cn.hippo4j.agent.core.logging.api.ILog;
import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.logging.api.LogManager;
import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance; import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
import cn.hippo4j.common.executor.ThreadPoolRegistry; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.agent.core.util.CollectionUtil; import cn.hippo4j.agent.core.util.CollectionUtil;
import cn.hippo4j.agent.core.util.StringUtil; import cn.hippo4j.agent.core.util.StringUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -52,7 +52,7 @@ public class ThreadPoolExecutorConstructorMethodInterceptor implements InstanceC
StackTraceElement declaredClassStackTraceElement = stackTraceElements.get(0); StackTraceElement declaredClassStackTraceElement = stackTraceElements.get(0);
String declaredClassName = declaredClassStackTraceElement.getClassName(); String declaredClassName = declaredClassStackTraceElement.getClassName();
Class<?> declaredClass = Thread.currentThread().getContextClassLoader().loadClass(declaredClassName); Class<?> declaredClass = Thread.currentThread().getContextClassLoader().loadClass(declaredClassName);
ThreadPoolRegistry.REFERENCED_CLASS_MAP.put((ThreadPoolExecutor) objInst, declaredClass); ThreadPoolExecutorRegistry.REFERENCED_CLASS_MAP.put((ThreadPoolExecutor) objInst, declaredClass);
} }
private List<StackTraceElement> getStackTraceElements() { private List<StackTraceElement> getStackTraceElements() {

@ -25,11 +25,11 @@ spring.dynamic.thread-pool.monitor.initial-delay=10000
spring.dynamic.thread-pool.monitor.collect-interval=5000 spring.dynamic.thread-pool.monitor.collect-interval=5000
spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
spring.dynamic.thread-pool.notify-platforms[0].token=ac0426a5-c712-474c-9bff-72b8b8f5caff spring.dynamic.thread-pool.notify-platforms[0].token=ec3be378-6c99-45d2-a147-b400c7e94a08
spring.dynamic.thread-pool.notify-platforms[1].platform=DING # spring.dynamic.thread-pool.notify-platforms[1].platform=DING
spring.dynamic.thread-pool.notify-platforms[1].token=56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55 # spring.dynamic.thread-pool.notify-platforms[1].token=56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55
spring.dynamic.thread-pool.notify-platforms[2].platform=LARK # spring.dynamic.thread-pool.notify-platforms[2].platform=LARK
spring.dynamic.thread-pool.notify-platforms[2].token=2cbf2808-3839-4c26-a04d-fd201dd51f9e # spring.dynamic.thread-pool.notify-platforms[2].token=2cbf2808-3839-4c26-a04d-fd201dd51f9e
spring.dynamic.thread-pool.nacos.data-id=hippo4j-nacos.yaml spring.dynamic.thread-pool.nacos.data-id=hippo4j-nacos.yaml
spring.dynamic.thread-pool.nacos.group=DEFAULT_GROUP spring.dynamic.thread-pool.nacos.group=DEFAULT_GROUP

@ -18,7 +18,7 @@
package cn.hippo4j.example.core.handler; package cn.hippo4j.example.core.handler;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.toolkit.ExecutorTraceContextUtil; import cn.hippo4j.threadpool.alarm.toolkit.ExecutorTraceContextUtil;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskDecorator;

@ -17,9 +17,9 @@
package cn.hippo4j.example.core.inittest; package cn.hippo4j.example.core.inittest;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.example.core.constant.GlobalTestConstant; import cn.hippo4j.example.core.constant.GlobalTestConstant;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -47,8 +47,8 @@ public class AlarmSendMessageTest {
public void alarmSendMessageTest() { public void alarmSendMessageTest() {
ScheduledExecutorService scheduledThreadPool = Executors.newSingleThreadScheduledExecutor(); ScheduledExecutorService scheduledThreadPool = Executors.newSingleThreadScheduledExecutor();
scheduledThreadPool.scheduleWithFixedDelay(() -> { scheduledThreadPool.scheduleWithFixedDelay(() -> {
DynamicThreadPoolWrapper poolWrapper = GlobalThreadPoolManage.getExecutorService(GlobalTestConstant.MESSAGE_PRODUCE); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(GlobalTestConstant.MESSAGE_PRODUCE);
ThreadPoolExecutor poolExecutor = poolWrapper.getExecutor(); ThreadPoolExecutor poolExecutor = executorHolder.getExecutor();
try { try {
poolExecutor.execute(() -> { poolExecutor.execute(() -> {
try { try {

@ -24,7 +24,7 @@ import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper;
import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterCoreNotifyParameter; import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterCoreNotifyParameter;
import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterServerNotifyParameter; import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterServerNotifyParameter;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.message.enums.NotifyPlatformEnum; import cn.hippo4j.threadpool.message.api.NotifyPlatformEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;

@ -17,9 +17,9 @@
package cn.hippo4j.example.core.inittest; package cn.hippo4j.example.core.inittest;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.example.core.constant.GlobalTestConstant; import cn.hippo4j.example.core.constant.GlobalTestConstant;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskDecorator;
@ -63,8 +63,8 @@ public class TaskDecoratorTest {
MDC.put(PLACEHOLDER, "View the official website: https://www.hippo4j.cn"); MDC.put(PLACEHOLDER, "View the official website: https://www.hippo4j.cn");
try { try {
Thread.sleep(SLEEP_TIME); Thread.sleep(SLEEP_TIME);
DynamicThreadPoolWrapper poolWrapper = GlobalThreadPoolManage.getExecutorService(GlobalTestConstant.MESSAGE_PRODUCE); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(GlobalTestConstant.MESSAGE_PRODUCE);
ThreadPoolExecutor threadPoolExecutor = poolWrapper.getExecutor(); ThreadPoolExecutor threadPoolExecutor = executorHolder.getExecutor();
threadPoolExecutor.execute(() -> log.info("Pass context via taskDecorator MDC: {}", MDC.get(PLACEHOLDER))); threadPoolExecutor.execute(() -> log.info("Pass context via taskDecorator MDC: {}", MDC.get(PLACEHOLDER)));
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

@ -33,7 +33,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-server-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>

@ -33,7 +33,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-server-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>

@ -33,7 +33,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-server-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>

@ -33,7 +33,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-server-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>

@ -37,7 +37,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-server-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>

@ -22,7 +22,7 @@
<dependency> <dependency>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-server-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>

@ -17,6 +17,7 @@
package cn.hippo4j.common.executor; package cn.hippo4j.common.executor;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.model.executor.ExecutorProperties; import cn.hippo4j.common.model.executor.ExecutorProperties;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -35,6 +36,12 @@ public class ThreadPoolExecutorHolder {
private ExecutorProperties executorProperties; private ExecutorProperties executorProperties;
/**
* The Server mode is used to compare whether the parameters have changed,
* and consider refactoring later
*/
private ThreadPoolParameterInfo parameterInfo;
public ThreadPoolExecutorHolder(String threadPoolId, ThreadPoolExecutor executor, ExecutorProperties executorProperties) { public ThreadPoolExecutorHolder(String threadPoolId, ThreadPoolExecutor executor, ExecutorProperties executorProperties) {
this.threadPoolId = threadPoolId; this.threadPoolId = threadPoolId;
this.executor = executor; this.executor = executor;

@ -21,13 +21,15 @@ import cn.hippo4j.common.model.executor.ExecutorProperties;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ThreadPoolRegistry { public class ThreadPoolExecutorRegistry {
private static final Map<String, ThreadPoolExecutorHolder> HOLDER_MAP = new ConcurrentHashMap<>(); private static final Map<String, ThreadPoolExecutorHolder> HOLDER_MAP = new ConcurrentHashMap<>();
@ -38,8 +40,12 @@ public class ThreadPoolRegistry {
} }
public static void putHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties executorProperties) { public static void putHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties executorProperties) {
ThreadPoolExecutorHolder holder = new ThreadPoolExecutorHolder(executorName, executor, executorProperties); ThreadPoolExecutorHolder executorHolder = new ThreadPoolExecutorHolder(executorName, executor, executorProperties);
HOLDER_MAP.put(executorName, holder); HOLDER_MAP.put(executorHolder.getThreadPoolId(), executorHolder);
}
public static void putHolder(ThreadPoolExecutorHolder executorHolder) {
HOLDER_MAP.put(executorHolder.getThreadPoolId(), executorHolder);
} }
public static ThreadPoolExecutorHolder getHolder(String executorName) { public static ThreadPoolExecutorHolder getHolder(String executorName) {
@ -49,4 +55,19 @@ public class ThreadPoolRegistry {
public static Map<ThreadPoolExecutor, Class<?>> getReferencedClassMap() { public static Map<ThreadPoolExecutor, Class<?>> getReferencedClassMap() {
return REFERENCED_CLASS_MAP; return REFERENCED_CLASS_MAP;
} }
public static List<String> listThreadPoolExecutorId() {
return new ArrayList<>(HOLDER_MAP.keySet());
}
/**
* Get the number of dynamic thread pools.
* <p> The data may be inaccurate when the project is initially
* launched because registration is done asynchronously.
*
* @return thread-pool size
*/
public static Integer getThreadPoolExecutorSize() {
return listThreadPoolExecutorId().size();
}
} }

@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.propertie;
/**
* Configurable environment properties.
*/
public final class EnvironmentProperties {
/**
* spring.profiles.active
*/
public static String active = "UNKNOWN";
/**
* spring.dynamic.thread-pool.item-id
*/
public static String itemId;
/**
* spring.application.name
*/
public static String applicationName;
/**
* spring.dynamic.thread-pool.check-state-interval
*/
public static Long checkStateInterval;
}

@ -0,0 +1,32 @@
/*
* 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.propertie;
import lombok.Setter;
/**
* Identify properties.
*/
public class IdentifyProperties {
/**
* The unique identifier of the client, initialized when the project starts
*/
@Setter
public static String IDENTIFY;
}

@ -24,22 +24,18 @@ import java.util.Map;
import cn.hippo4j.common.monitor.AbstractMessage; import cn.hippo4j.common.monitor.AbstractMessage;
import cn.hippo4j.common.monitor.Message; import cn.hippo4j.common.monitor.Message;
import cn.hippo4j.common.monitor.MessageWrapper; import cn.hippo4j.common.monitor.MessageWrapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
/** /**
* Message convert. * Message convert.
*/ */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MessageConvert { public class MessageConvert {
private MessageConvert(){
}
/** /**
* {@link Message} to {@link MessageWrapper}. * {@link Message} to {@link MessageWrapper}.
*
* @param message
* @return
*/ */
public static MessageWrapper convert(Message message) { public static MessageWrapper convert(Message message) {
MessageWrapper wrapper = new MessageWrapper(); MessageWrapper wrapper = new MessageWrapper();
@ -58,9 +54,6 @@ public class MessageConvert {
/** /**
* {@link MessageWrapper} to {@link Message}. * {@link MessageWrapper} to {@link Message}.
*
* @param messageWrapper
* @return
*/ */
@SneakyThrows @SneakyThrows
public static Message convert(MessageWrapper messageWrapper) { public static Message convert(MessageWrapper messageWrapper) {

@ -49,6 +49,7 @@ import java.util.zip.GZIPOutputStream;
* test for {@link IoUtil} * test for {@link IoUtil}
*/ */
public class IoUtilTest { public class IoUtilTest {
private Path tempDir; private Path tempDir;
private File sourceFile; private File sourceFile;

@ -87,8 +87,7 @@ public class JacksonHandlerTest {
Assertions.assertEquals( Assertions.assertEquals(
EXPECTED_ENTITY, EXPECTED_ENTITY,
JACKSON_HANDLER.parseObject(EXPECTED_ENTITY_JSON, new TypeReference<Entity>() { JACKSON_HANDLER.parseObject(EXPECTED_ENTITY_JSON, new TypeReference<Entity>() {
}) }));
);
// illegal json // illegal json
Assertions.assertThrows(MismatchedInputException.class, Assertions.assertThrows(MismatchedInputException.class,
() -> JACKSON_HANDLER.parseObject(" ", Entity.class)); () -> JACKSON_HANDLER.parseObject(" ", Entity.class));

@ -93,7 +93,7 @@ public class MessageConvertTest {
@Test @Test
public void testMessageWrapperConvertException() { public void testMessageWrapperConvertException() {
Assertions.assertThrows(Exception.class, ()->{ Assertions.assertThrows(Exception.class, () -> {
Map<String, Object> data1 = new HashMap<>(); Map<String, Object> data1 = new HashMap<>();
data1.put("key1", "value1"); data1.put("key1", "value1");
data1.put("key2", 123); data1.put("key2", 123);

@ -10,4 +10,17 @@
</parent> </parent>
<artifactId>hippo4j-threadpool-kernel-alarm</artifactId> <artifactId>hippo4j-threadpool-kernel-alarm</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-message-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project> </project>

@ -15,12 +15,11 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.core.api; package cn.hippo4j.threadpool.alarm.api;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -30,7 +29,7 @@ import java.util.concurrent.ThreadPoolExecutor;
* <p>Dynamic thread pool check and send logic wait for refactoring, * <p>Dynamic thread pool check and send logic wait for refactoring,
* Try not to rely on this component for custom extensions, because it is undefined. * Try not to rely on this component for custom extensions, because it is undefined.
*/ */
public interface ThreadPoolCheckAlarm extends CommandLineRunner { public interface ThreadPoolCheckAlarm {
/** /**
* Get a none thread pool check alarm. * Get a none thread pool check alarm.
@ -42,6 +41,12 @@ public interface ThreadPoolCheckAlarm extends CommandLineRunner {
return NoneThreadPoolCheckAlarm.INSTANCE; return NoneThreadPoolCheckAlarm.INSTANCE;
} }
/**
* Execute scheduled tasks to scan the running status of the thread pool.
*/
default void scheduleExecute() {
}
/** /**
* Check pool capacity alarm. * Check pool capacity alarm.
* *
@ -133,10 +138,5 @@ public interface ThreadPoolCheckAlarm extends CommandLineRunner {
public void asyncSendExecuteTimeOutAlarm(String threadPoolId, long executeTime, long executeTimeOut, ThreadPoolExecutor threadPoolExecutor) { public void asyncSendExecuteTimeOutAlarm(String threadPoolId, long executeTime, long executeTimeOut, ThreadPoolExecutor threadPoolExecutor) {
log.debug("Ignore async send execute time out alarm for ExecuteService '{}'", threadPoolId); log.debug("Ignore async send execute time out alarm for ExecuteService '{}'", threadPoolId);
} }
@Override
public void run(String... args) throws Exception {
// do nothing
}
} }
} }

@ -15,22 +15,22 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.alarm.handler;
import cn.hippo4j.core.api.ThreadPoolCheckAlarm; import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.toolkit.CalculateUtil; import cn.hippo4j.common.toolkit.CalculateUtil;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.threadpool.alarm.api.ThreadPoolCheckAlarm;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hippo4j.threadpool.alarm.toolkit.ExecutorTraceContextUtil;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.threadpool.message.core.request.AlarmNotifyRequest;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
import cn.hippo4j.core.toolkit.ExecutorTraceContextUtil; import cn.hippo4j.threadpool.message.core.service.GlobalNotifyAlarmManage;
import cn.hippo4j.core.toolkit.IdentifyUtil; import cn.hippo4j.threadpool.message.core.service.ThreadPoolNotifyAlarm;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.core.service.ThreadPoolSendMessageService;
import cn.hippo4j.message.request.AlarmNotifyRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -40,8 +40,16 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static cn.hippo4j.common.propertie.EnvironmentProperties.active;
import static cn.hippo4j.common.propertie.EnvironmentProperties.applicationName;
import static cn.hippo4j.common.propertie.EnvironmentProperties.checkStateInterval;
import static cn.hippo4j.common.propertie.EnvironmentProperties.itemId;
import static cn.hippo4j.common.propertie.IdentifyProperties.IDENTIFY;
/** /**
* Default thread-pool check alarm handler. * Default thread-pool check alarm handler.
@ -50,46 +58,42 @@ import java.util.concurrent.TimeUnit;
@RequiredArgsConstructor @RequiredArgsConstructor
public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolCheckAlarm { public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolCheckAlarm {
private final Hippo4jSendMessageService hippo4jSendMessageService; private final ThreadPoolSendMessageService threadPoolSendMessageService;
@Value("${spring.profiles.active:UNKNOWN}")
private String active;
@Value("${spring.dynamic.thread-pool.item-id:}")
private String itemId;
@Value("${spring.application.name:UNKNOWN}")
private String applicationName;
@Value("${spring.dynamic.thread-pool.check-state-interval:5}")
private Integer checkStateInterval;
private final ScheduledExecutorService alarmNotifyExecutor = new ScheduledThreadPoolExecutor( private final ScheduledExecutorService alarmNotifyExecutor = new ScheduledThreadPoolExecutor(
1, 1,
r -> new Thread(r, "client.alarm.notify")); r -> new Thread(r, "client.alarm.notify"));
private final ExecutorService asyncAlarmNotifyExecutor = ThreadPoolBuilder.builder() private final ExecutorService asyncAlarmNotifyExecutor = new ThreadPoolExecutor(
.poolThreadSize(2, 4) 2,
.threadFactory("client.execute.timeout.alarm") 4,
.allowCoreThreadTimeOut(true) 60L,
.keepAliveTime(60L, TimeUnit.SECONDS) TimeUnit.SECONDS,
.workQueue(new LinkedBlockingQueue(4096)) new LinkedBlockingQueue<>(4096),
.rejected(new ThreadPoolExecutor.AbortPolicy()) new ThreadFactory() {
.build();
private final AtomicInteger count = new AtomicInteger();
@Override @Override
public void run(String... args) throws Exception { public Thread newThread(Runnable r) {
return new Thread("client.execute.timeout.alarm_" + count.incrementAndGet());
}
},
new ThreadPoolExecutor.AbortPolicy());
@Override
public void scheduleExecute() {
alarmNotifyExecutor.scheduleWithFixedDelay(this, 0, checkStateInterval, TimeUnit.SECONDS); alarmNotifyExecutor.scheduleWithFixedDelay(this, 0, checkStateInterval, TimeUnit.SECONDS);
} }
@Override @Override
public void run() { public void run() {
List<String> listThreadPoolId = GlobalThreadPoolManage.listThreadPoolId(); List<String> listThreadPoolId = ThreadPoolExecutorRegistry.listThreadPoolExecutorId();
listThreadPoolId.forEach(threadPoolId -> { listThreadPoolId.forEach(threadPoolId -> {
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(threadPoolId); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(threadPoolId);
if (threadPoolNotifyAlarm != null && threadPoolNotifyAlarm.getAlarm()) { if (threadPoolNotifyAlarm != null && threadPoolNotifyAlarm.getAlarm()) {
DynamicThreadPoolWrapper wrapper = GlobalThreadPoolManage.getExecutorService(threadPoolId); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(threadPoolId);
ThreadPoolExecutor executor = wrapper.getExecutor(); ThreadPoolExecutor executor = executorHolder.getExecutor();
checkPoolCapacityAlarm(threadPoolId, executor); checkPoolCapacityAlarm(threadPoolId, executor);
checkPoolActivityAlarm(threadPoolId, executor); checkPoolActivityAlarm(threadPoolId, executor);
} }
@ -116,7 +120,7 @@ public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolC
if (isSend) { if (isSend) {
AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor); AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor);
alarmNotifyRequest.setThreadPoolId(threadPoolId); alarmNotifyRequest.setThreadPoolId(threadPoolId);
hippo4jSendMessageService.sendAlarmMessage(NotifyTypeEnum.CAPACITY, alarmNotifyRequest); threadPoolSendMessageService.sendAlarmMessage(NotifyTypeEnum.CAPACITY, alarmNotifyRequest);
} }
} }
@ -139,7 +143,7 @@ public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolC
if (isSend) { if (isSend) {
AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor); AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor);
alarmNotifyRequest.setThreadPoolId(threadPoolId); alarmNotifyRequest.setThreadPoolId(threadPoolId);
hippo4jSendMessageService.sendAlarmMessage(NotifyTypeEnum.ACTIVITY, alarmNotifyRequest); threadPoolSendMessageService.sendAlarmMessage(NotifyTypeEnum.ACTIVITY, alarmNotifyRequest);
} }
} }
@ -155,11 +159,11 @@ public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolC
if (Objects.isNull(alarmConfig) || !alarmConfig.getAlarm()) { if (Objects.isNull(alarmConfig) || !alarmConfig.getAlarm()) {
return; return;
} }
ThreadPoolExecutor threadPoolExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor(); ThreadPoolExecutor threadPoolExecutor = ThreadPoolExecutorRegistry.getHolder(threadPoolId).getExecutor();
if (threadPoolExecutor instanceof DynamicThreadPoolExecutor) { if (Objects.equals(threadPoolExecutor.getClass().getName(), "cn.hippo4j.core.executor.DynamicThreadPoolExecutor")) {
AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor); AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor);
alarmNotifyRequest.setThreadPoolId(threadPoolId); alarmNotifyRequest.setThreadPoolId(threadPoolId);
hippo4jSendMessageService.sendAlarmMessage(NotifyTypeEnum.REJECT, alarmNotifyRequest); threadPoolSendMessageService.sendAlarmMessage(NotifyTypeEnum.REJECT, alarmNotifyRequest);
} }
}; };
asyncAlarmNotifyExecutor.execute(checkPoolRejectedAlarmTask); asyncAlarmNotifyExecutor.execute(checkPoolRejectedAlarmTask);
@ -179,7 +183,6 @@ public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolC
if (Objects.isNull(alarmConfig) || !alarmConfig.getAlarm()) { if (Objects.isNull(alarmConfig) || !alarmConfig.getAlarm()) {
return; return;
} }
if (threadPoolExecutor instanceof DynamicThreadPoolExecutor) {
try { try {
AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor); AlarmNotifyRequest alarmNotifyRequest = buildAlarmNotifyRequest(threadPoolExecutor);
alarmNotifyRequest.setThreadPoolId(threadPoolId); alarmNotifyRequest.setThreadPoolId(threadPoolId);
@ -189,13 +192,12 @@ public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolC
if (StringUtil.isNotBlank(executeTimeoutTrace)) { if (StringUtil.isNotBlank(executeTimeoutTrace)) {
alarmNotifyRequest.setExecuteTimeoutTrace(executeTimeoutTrace); alarmNotifyRequest.setExecuteTimeoutTrace(executeTimeoutTrace);
} }
Runnable task = () -> hippo4jSendMessageService.sendAlarmMessage(NotifyTypeEnum.TIMEOUT, alarmNotifyRequest); Runnable task = () -> threadPoolSendMessageService.sendAlarmMessage(NotifyTypeEnum.TIMEOUT, alarmNotifyRequest);
asyncAlarmNotifyExecutor.execute(task); asyncAlarmNotifyExecutor.execute(task);
} catch (Throwable ex) { } catch (Throwable ex) {
log.error("Send thread pool execution timeout alarm error.", ex); log.error("Send thread pool execution timeout alarm error.", ex);
} }
} }
}
/** /**
* Build alarm notify request. * Build alarm notify request.
@ -206,13 +208,17 @@ public class DefaultThreadPoolCheckAlarmHandler implements Runnable, ThreadPoolC
public AlarmNotifyRequest buildAlarmNotifyRequest(ThreadPoolExecutor threadPoolExecutor) { public AlarmNotifyRequest buildAlarmNotifyRequest(ThreadPoolExecutor threadPoolExecutor) {
BlockingQueue<Runnable> blockingQueue = threadPoolExecutor.getQueue(); BlockingQueue<Runnable> blockingQueue = threadPoolExecutor.getQueue();
RejectedExecutionHandler rejectedExecutionHandler = threadPoolExecutor.getRejectedExecutionHandler(); RejectedExecutionHandler rejectedExecutionHandler = threadPoolExecutor.getRejectedExecutionHandler();
long rejectCount = threadPoolExecutor instanceof DynamicThreadPoolExecutor long rejectCount = -1L;
? ((DynamicThreadPoolExecutor) threadPoolExecutor).getRejectCountNum() if (Objects.equals(threadPoolExecutor.getClass().getName(), "cn.hippo4j.core.executor.DynamicThreadPoolExecutor")) {
: -1L; Object actualRejectCountNum = ReflectUtil.invoke(threadPoolExecutor, "getRejectCountNum");
if (actualRejectCountNum != null) {
rejectCount = (long) actualRejectCountNum;
}
}
return AlarmNotifyRequest.builder() return AlarmNotifyRequest.builder()
.appName(StringUtil.isBlank(itemId) ? applicationName : itemId) .appName(StringUtil.isBlank(itemId) ? applicationName : itemId)
.active(active.toUpperCase()) .active(active.toUpperCase())
.identify(IdentifyUtil.getIdentify()) .identify(IDENTIFY)
.corePoolSize(threadPoolExecutor.getCorePoolSize()) .corePoolSize(threadPoolExecutor.getCorePoolSize())
.maximumPoolSize(threadPoolExecutor.getMaximumPoolSize()) .maximumPoolSize(threadPoolExecutor.getMaximumPoolSize())
.poolSize(threadPoolExecutor.getPoolSize()) .poolSize(threadPoolExecutor.getPoolSize())

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.core.toolkit; package cn.hippo4j.threadpool.alarm.toolkit;
import org.slf4j.MDC; import org.slf4j.MDC;

@ -1,62 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.threadpool.dynamic.core.executor.manage;
import cn.hippo4j.common.model.executor.ExecutorProperties;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Global core thread-pool manage.
* TODO
*/
public class GlobalConfigThreadPoolManage {
private static final Map<String, ExecutorProperties> EXECUTOR_PROPERTIES = new ConcurrentHashMap<>();
/**
* Get properties.
*
* @param threadPoolId
* @return
*/
public static ExecutorProperties getProperties(String threadPoolId) {
return EXECUTOR_PROPERTIES.get(threadPoolId);
}
/**
* Register.
*
* @param threadPoolId
* @param executorProperties
*/
public static void register(String threadPoolId, ExecutorProperties executorProperties) {
EXECUTOR_PROPERTIES.put(threadPoolId, executorProperties);
}
/**
* Refresh.
*
* @param threadPoolId
* @param executorProperties
*/
public static void refresh(String threadPoolId, ExecutorProperties executorProperties) {
EXECUTOR_PROPERTIES.put(threadPoolId, executorProperties);
}
}

@ -1,70 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.threadpool.dynamic.core.executor.manage;
import cn.hippo4j.common.model.ThreadPoolParameter;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Global thread-pool manage.
*/
public class GlobalThreadPoolManage {
/**
* Dynamic thread pool parameter container.
*/
private static final Map<String, ThreadPoolParameter> POOL_PARAMETER = new ConcurrentHashMap();
/**
* Dynamic thread pool wrapper.
*/
private static final Map<String, ThreadPoolExecutor> EXECUTOR_MAP = new ConcurrentHashMap();
/**
* Get the dynamic thread pool class.
*
* @param threadPoolId thread-pool id
* @return dynamic thread-pool
*/
public static ThreadPoolExecutor getExecutorService(String threadPoolId) {
return EXECUTOR_MAP.get(threadPoolId);
}
/**
* Get dynamic thread pool parameters.
*
* @param threadPoolId thread-pool id
* @return thread-pool parameter
*/
public static ThreadPoolParameter getPoolParameter(String threadPoolId) {
return POOL_PARAMETER.get(threadPoolId);
}
/**
* Register dynamic thread pool parameters.
*
* @param threadPoolId thread-pool id
* @param threadPoolParameter thread-pool parameter
*/
public static void registerPoolParameter(String threadPoolId, ThreadPoolParameter threadPoolParameter) {
POOL_PARAMETER.put(threadPoolId, threadPoolParameter);
}
}

@ -22,5 +22,9 @@
<artifactId>hippo4j-threadpool-dynamic-core</artifactId> <artifactId>hippo4j-threadpool-dynamic-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -18,7 +18,11 @@
package cn.hippo4j.threadpool.dynamic.mode.config.parser; package cn.hippo4j.threadpool.dynamic.mode.config.parser;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ByteArrayResource;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -29,12 +33,12 @@ public class YamlConfigParser extends AbstractConfigParser {
@Override @Override
public Map<Object, Object> doParse(String content) { public Map<Object, Object> doParse(String content) {
// TODO if (StringUtils.isEmpty(content)) {
/* return new HashMap<>(1);
* if (StringUtils.isEmpty(content)) { return new HashMap<>(1); } YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean(); }
* yamlPropertiesFactoryBean.setResources(new ByteArrayResource(content.getBytes())); return yamlPropertiesFactoryBean.getObject(); YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
*/ yamlPropertiesFactoryBean.setResources(new ByteArrayResource(content.getBytes()));
return null; return yamlPropertiesFactoryBean.getObject();
} }
@Override @Override

@ -18,7 +18,7 @@
package cn.hippo4j.threadpool.dynamic.mode.config.refresher.event; package cn.hippo4j.threadpool.dynamic.mode.config.refresher.event;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder; import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolRegistry; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue; import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue;
@ -55,7 +55,7 @@ public class DynamicThreadPoolRefreshListener implements Observer<BootstrapConfi
for (ExecutorProperties properties : executors) { for (ExecutorProperties properties : executors) {
String threadPoolId = properties.getThreadPoolId(); String threadPoolId = properties.getThreadPoolId();
// Check whether the thread pool configuration is empty and whether the parameters have changed // Check whether the thread pool configuration is empty and whether the parameters have changed
ThreadPoolExecutorHolder executorHolder = ThreadPoolRegistry.getHolder(threadPoolId); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(threadPoolId);
if (executorHolder.isEmpty() || !checkPropertiesConsistency(executorHolder, properties)) { if (executorHolder.isEmpty() || !checkPropertiesConsistency(executorHolder, properties)) {
continue; continue;
} }

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-kernel-message</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-threadpool-message-api</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.dto; package cn.hippo4j.threadpool.message.api;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;

@ -15,9 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.api; package cn.hippo4j.threadpool.message.api;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

@ -15,9 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.dto; package cn.hippo4j.threadpool.message.api;
import cn.hippo4j.message.enums.NotifyTypeEnum;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.enums; package cn.hippo4j.threadpool.message.api;
/** /**
* Notify platform enum. * Notify platform enum.

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.enums; package cn.hippo4j.threadpool.message.api;
/** /**
* Notify type enum. * Notify type enum.

@ -15,8 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.dto; package cn.hippo4j.threadpool.message.api;
import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-kernel-message</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-threadpool-message-core</artifactId>
<dependencies>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-message-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.txt</include>
<include>**/*.json</include>
</includes>
</resource>
</resources>
</build>
</project>

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform.constant; package cn.hippo4j.threadpool.message.core.constant;
/** /**
* Ding alarm constants. * Ding alarm constants.

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform.constant; package cn.hippo4j.threadpool.message.core.constant;
/** /**
* Lark alarm constants. * Lark alarm constants.

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform.constant; package cn.hippo4j.threadpool.message.core.constant;
/** /**
* We chat alarm constants. * We chat alarm constants.

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform; package cn.hippo4j.threadpool.message.core.platform;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
@ -23,13 +23,12 @@ import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Singleton; import cn.hippo4j.common.toolkit.Singleton;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.http.HttpUtil; import cn.hippo4j.common.toolkit.http.HttpUtil;
import cn.hippo4j.core.toolkit.FileUtil; import cn.hippo4j.threadpool.message.core.platform.base.AbstractRobotSendMessageHandler;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.core.platform.base.RobotMessageActualContent;
import cn.hippo4j.message.enums.NotifyPlatformEnum; import cn.hippo4j.threadpool.message.core.platform.base.RobotMessageExecuteDTO;
import cn.hippo4j.message.platform.base.AbstractRobotSendMessageHandler; import cn.hippo4j.threadpool.message.core.constant.DingAlarmConstants;
import cn.hippo4j.message.platform.base.RobotMessageActualContent; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO; import cn.hippo4j.threadpool.message.api.NotifyPlatformEnum;
import cn.hippo4j.message.platform.constant.DingAlarmConstants;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
@ -42,13 +41,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import static cn.hippo4j.message.platform.constant.DingAlarmConstants.DING_ALARM_TIMEOUT_REPLACE_TXT;
import static cn.hippo4j.message.platform.constant.DingAlarmConstants.DING_ALARM_TIMEOUT_TRACE_REPLACE_TXT;
import static cn.hippo4j.message.platform.constant.DingAlarmConstants.DING_ALARM_TITLE;
import static cn.hippo4j.message.platform.constant.DingAlarmConstants.DING_NOTICE_TITLE;
/** /**
* doc:<a href="https://open.dingtalk.com/document/robots/custom-robot-access"></a>
* Send ding notification message. * Send ding notification message.
*/ */
@Slf4j @Slf4j
@ -66,10 +59,10 @@ public class DingSendMessageHandler extends AbstractRobotSendMessageHandler {
RobotMessageActualContent robotMessageActualContent = RobotMessageActualContent.builder() RobotMessageActualContent robotMessageActualContent = RobotMessageActualContent.builder()
.receiveSeparator(", @") .receiveSeparator(", @")
.changeSeparator(" -> ") .changeSeparator(" -> ")
.replaceTxt(DING_ALARM_TIMEOUT_REPLACE_TXT) .replaceTxt(DingAlarmConstants.DING_ALARM_TIMEOUT_REPLACE_TXT)
.traceReplaceTxt(DING_ALARM_TIMEOUT_TRACE_REPLACE_TXT) .traceReplaceTxt(DingAlarmConstants.DING_ALARM_TIMEOUT_TRACE_REPLACE_TXT)
.alarmMessageContent(Singleton.get(dingAlarmTxtKey, () -> FileUtil.readUtf8String(dingAlarmTxtKey))) .alarmMessageContent(Singleton.get(dingAlarmTxtKey, () -> readUtf8String(dingAlarmTxtKey)))
.configMessageContent(Singleton.get(dingConfigTxtKey, () -> FileUtil.readUtf8String(dingConfigTxtKey))) .configMessageContent(Singleton.get(dingConfigTxtKey, () -> readUtf8String(dingConfigTxtKey)))
.build(); .build();
return robotMessageActualContent; return robotMessageActualContent;
} }
@ -92,7 +85,7 @@ public class DingSendMessageHandler extends AbstractRobotSendMessageHandler {
log.error("Failed to sign the message sent by nailing.", ex); log.error("Failed to sign the message sent by nailing.", ex);
} }
} }
String title = Objects.equals(notifyConfig.getType(), "CONFIG") ? DING_NOTICE_TITLE : DING_ALARM_TITLE; String title = Objects.equals(notifyConfig.getType(), "CONFIG") ? DingAlarmConstants.DING_NOTICE_TITLE : DingAlarmConstants.DING_ALARM_TITLE;
String text = robotMessageExecuteDTO.getText(); String text = robotMessageExecuteDTO.getText();
ArrayList<String> atMobiles = CollectionUtil.newArrayList(notifyConfig.getReceives().split(",")); ArrayList<String> atMobiles = CollectionUtil.newArrayList(notifyConfig.getReceives().split(","));
HashMap<String, Object> markdown = new HashMap<>(); HashMap<String, Object> markdown = new HashMap<>();

@ -15,20 +15,20 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform; package cn.hippo4j.threadpool.message.core.platform;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Singleton; import cn.hippo4j.common.toolkit.Singleton;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.http.HttpUtil; import cn.hippo4j.common.toolkit.http.HttpUtil;
import cn.hippo4j.core.toolkit.FileUtil; import cn.hippo4j.threadpool.message.core.request.AlarmNotifyRequest;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.enums.NotifyPlatformEnum; import cn.hippo4j.threadpool.message.core.service.SendMessageHandler;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import cn.hippo4j.message.request.AlarmNotifyRequest; import cn.hippo4j.threadpool.message.api.NotifyPlatformEnum;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
import cn.hippo4j.message.service.SendMessageHandler; import cn.hippo4j.threadpool.message.core.constant.LarkAlarmConstants;
import lombok.Data; import lombok.Data;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
@ -46,11 +46,6 @@ import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.hippo4j.message.platform.constant.LarkAlarmConstants.LARK_AT_FORMAT_OPENID;
import static cn.hippo4j.message.platform.constant.LarkAlarmConstants.LARK_AT_FORMAT_USERNAME;
import static cn.hippo4j.message.platform.constant.LarkAlarmConstants.LARK_BOT_URL;
import static cn.hippo4j.message.platform.constant.LarkAlarmConstants.LARK_OPENID_PREFIX;
/** /**
* Send lark notification message. * Send lark notification message.
*/ */
@ -69,13 +64,13 @@ public class LarkSendMessageHandler implements SendMessageHandler {
String afterReceives = getReceives(notifyConfig.getReceives()); String afterReceives = getReceives(notifyConfig.getReceives());
String larkAlarmTimeoutReplaceTxt; String larkAlarmTimeoutReplaceTxt;
String larkAlarmTxtKey = "message/robot/dynamic-thread-pool/lark-alarm.json"; String larkAlarmTxtKey = "message/robot/dynamic-thread-pool/lark-alarm.json";
String larkAlarmTxt = Singleton.get(larkAlarmTxtKey, () -> FileUtil.readUtf8String(larkAlarmTxtKey)); String larkAlarmTxt = Singleton.get(larkAlarmTxtKey, () -> readUtf8String(larkAlarmTxtKey));
String larkAlarmTimeoutReplaceJsonKey = "message/robot/dynamic-thread-pool/lark-alarm-timeout-replace.json"; String larkAlarmTimeoutReplaceJsonKey = "message/robot/dynamic-thread-pool/lark-alarm-timeout-replace.json";
String larkAlarmTimeoutReplaceJson = Singleton.get(larkAlarmTimeoutReplaceJsonKey, () -> FileUtil.readUtf8String(larkAlarmTimeoutReplaceJsonKey)); String larkAlarmTimeoutReplaceJson = Singleton.get(larkAlarmTimeoutReplaceJsonKey, () -> readUtf8String(larkAlarmTimeoutReplaceJsonKey));
if (Objects.equals(alarmNotifyRequest.getNotifyTypeEnum(), NotifyTypeEnum.TIMEOUT)) { if (Objects.equals(alarmNotifyRequest.getNotifyTypeEnum(), NotifyTypeEnum.TIMEOUT)) {
String executeTimeoutTrace = alarmNotifyRequest.getExecuteTimeoutTrace(); String executeTimeoutTrace = alarmNotifyRequest.getExecuteTimeoutTrace();
String larkAlarmTimoutTraceReplaceJsonKey = "message/robot/dynamic-thread-pool/lark-alarm-trace-replace.json"; String larkAlarmTimoutTraceReplaceJsonKey = "message/robot/dynamic-thread-pool/lark-alarm-trace-replace.json";
String larkAlarmTimoutTraceReplaceJson = Singleton.get(larkAlarmTimoutTraceReplaceJsonKey, () -> FileUtil.readUtf8String(larkAlarmTimoutTraceReplaceJsonKey)); String larkAlarmTimoutTraceReplaceJson = Singleton.get(larkAlarmTimoutTraceReplaceJsonKey, () -> readUtf8String(larkAlarmTimoutTraceReplaceJsonKey));
if (StringUtil.isNotBlank(executeTimeoutTrace)) { if (StringUtil.isNotBlank(executeTimeoutTrace)) {
String larkAlarmTimoutTraceReplaceTxt = String.format(larkAlarmTimoutTraceReplaceJson, executeTimeoutTrace); String larkAlarmTimoutTraceReplaceTxt = String.format(larkAlarmTimoutTraceReplaceJson, executeTimeoutTrace);
larkAlarmTimeoutReplaceTxt = StringUtil.replace(larkAlarmTimeoutReplaceJson, larkAlarmTimoutTraceReplaceJson, larkAlarmTimoutTraceReplaceTxt); larkAlarmTimeoutReplaceTxt = StringUtil.replace(larkAlarmTimeoutReplaceJson, larkAlarmTimoutTraceReplaceJson, larkAlarmTimoutTraceReplaceTxt);
@ -126,7 +121,7 @@ public class LarkSendMessageHandler implements SendMessageHandler {
String threadPoolId = changeParameterNotifyRequest.getThreadPoolId(); String threadPoolId = changeParameterNotifyRequest.getThreadPoolId();
String afterReceives = getReceives(notifyConfig.getReceives()); String afterReceives = getReceives(notifyConfig.getReceives());
String larkNoticeJsonKey = "message/robot/dynamic-thread-pool/lark-config.json"; String larkNoticeJsonKey = "message/robot/dynamic-thread-pool/lark-config.json";
String larkNoticeJson = Singleton.get(larkNoticeJsonKey, () -> FileUtil.readUtf8String(larkNoticeJsonKey)); String larkNoticeJson = Singleton.get(larkNoticeJsonKey, () -> readUtf8String(larkNoticeJsonKey));
String text = String.format(larkNoticeJson, String text = String.format(larkNoticeJson,
changeParameterNotifyRequest.getActive(), changeParameterNotifyRequest.getActive(),
threadPoolId, threadPoolId,
@ -151,12 +146,13 @@ public class LarkSendMessageHandler implements SendMessageHandler {
return ""; return "";
} }
return Arrays.stream(receives.split(",")) return Arrays.stream(receives.split(","))
.map(receive -> StringUtil.startWith(receive, LARK_OPENID_PREFIX) ? String.format(LARK_AT_FORMAT_OPENID, receive) : String.format(LARK_AT_FORMAT_USERNAME, receive)) .map(receive -> StringUtil.startWith(receive, LarkAlarmConstants.LARK_OPENID_PREFIX) ? String.format(LarkAlarmConstants.LARK_AT_FORMAT_OPENID, receive)
: String.format(LarkAlarmConstants.LARK_AT_FORMAT_USERNAME, receive))
.collect(Collectors.joining(" ")); .collect(Collectors.joining(" "));
} }
private void execute(String secretKey, String text) { private void execute(String secretKey, String text) {
String serverUrl = LARK_BOT_URL + secretKey; String serverUrl = LarkAlarmConstants.LARK_BOT_URL + secretKey;
try { try {
String responseBody = HttpUtil.postJson(serverUrl, text); String responseBody = HttpUtil.postJson(serverUrl, text);
LarkRobotResponse response = JSONUtil.parseObject(responseBody, LarkRobotResponse.class); LarkRobotResponse response = JSONUtil.parseObject(responseBody, LarkRobotResponse.class);
@ -173,10 +169,7 @@ public class LarkSendMessageHandler implements SendMessageHandler {
* generate Signature * generate Signature
*/ */
private String genSign(String secret, String timestamp) throws NoSuchAlgorithmException, InvalidKeyException { private String genSign(String secret, String timestamp) throws NoSuchAlgorithmException, InvalidKeyException {
// geneSign
String stringToSign = timestamp + "\n" + secret; String stringToSign = timestamp + "\n" + secret;
// encode
Mac mac = Mac.getInstance("HmacSHA256"); Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(stringToSign.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); mac.init(new SecretKeySpec(stringToSign.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(new byte[]{}); byte[] signData = mac.doFinal(new byte[]{});

@ -15,25 +15,21 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform; package cn.hippo4j.threadpool.message.core.platform;
import cn.hippo4j.common.toolkit.Assert; import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Singleton; import cn.hippo4j.common.toolkit.Singleton;
import cn.hippo4j.common.toolkit.http.HttpUtil; import cn.hippo4j.common.toolkit.http.HttpUtil;
import cn.hippo4j.core.toolkit.FileUtil; import cn.hippo4j.threadpool.message.core.platform.base.AbstractRobotSendMessageHandler;
import cn.hippo4j.message.enums.NotifyPlatformEnum; import cn.hippo4j.threadpool.message.core.platform.base.RobotMessageActualContent;
import cn.hippo4j.message.platform.base.AbstractRobotSendMessageHandler; import cn.hippo4j.threadpool.message.core.platform.base.RobotMessageExecuteDTO;
import cn.hippo4j.message.platform.base.RobotMessageActualContent; import cn.hippo4j.threadpool.message.api.NotifyPlatformEnum;
import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO; import cn.hippo4j.threadpool.message.core.constant.WeChatAlarmConstants;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import static cn.hippo4j.message.platform.constant.WeChatAlarmConstants.WE_CHAT_ALARM_TIMOUT_REPLACE_TXT;
import static cn.hippo4j.message.platform.constant.WeChatAlarmConstants.WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT;
import static cn.hippo4j.message.platform.constant.WeChatAlarmConstants.WE_CHAT_SERVER_URL;
/** /**
* WeChat send message handler. * WeChat send message handler.
*/ */
@ -52,16 +48,16 @@ public class WeChatSendMessageHandler extends AbstractRobotSendMessageHandler {
return RobotMessageActualContent.builder() return RobotMessageActualContent.builder()
.receiveSeparator("><@") .receiveSeparator("><@")
.changeSeparator(" ➲ ") .changeSeparator(" ➲ ")
.replaceTxt(WE_CHAT_ALARM_TIMOUT_REPLACE_TXT) .replaceTxt(WeChatAlarmConstants.WE_CHAT_ALARM_TIMOUT_REPLACE_TXT)
.traceReplaceTxt(WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT) .traceReplaceTxt(WeChatAlarmConstants.WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT)
.alarmMessageContent(Singleton.get(weChatAlarmTxtKey, () -> FileUtil.readUtf8String(weChatAlarmTxtKey))) .alarmMessageContent(Singleton.get(weChatAlarmTxtKey, () -> readUtf8String(weChatAlarmTxtKey)))
.configMessageContent(Singleton.get(weChatConfigTxtKey, () -> FileUtil.readUtf8String(weChatConfigTxtKey))) .configMessageContent(Singleton.get(weChatConfigTxtKey, () -> readUtf8String(weChatConfigTxtKey)))
.build(); .build();
} }
@Override @Override
protected void execute(RobotMessageExecuteDTO robotMessageExecuteDTO) { protected void execute(RobotMessageExecuteDTO robotMessageExecuteDTO) {
String serverUrl = WE_CHAT_SERVER_URL + robotMessageExecuteDTO.getNotifyConfig().getSecretKey(); String serverUrl = WeChatAlarmConstants.WE_CHAT_SERVER_URL + robotMessageExecuteDTO.getNotifyConfig().getSecretKey();
try { try {
WeChatReqDTO weChatReq = new WeChatReqDTO(); WeChatReqDTO weChatReq = new WeChatReqDTO();
weChatReq.setMsgtype("markdown"); weChatReq.setMsgtype("markdown");

@ -15,15 +15,15 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform.base; package cn.hippo4j.threadpool.message.core.platform.base;
import cn.hippo4j.common.toolkit.Joiner; import cn.hippo4j.common.toolkit.Joiner;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
import cn.hippo4j.message.request.AlarmNotifyRequest; import cn.hippo4j.threadpool.message.core.request.AlarmNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.service.SendMessageHandler; import cn.hippo4j.threadpool.message.core.service.SendMessageHandler;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform.base; package cn.hippo4j.threadpool.message.core.platform.base;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.platform.base; package cn.hippo4j.threadpool.message.core.platform.base;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;

@ -15,10 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.request; package cn.hippo4j.threadpool.message.core.request;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.core.request.base.BaseNotifyRequest;
import cn.hippo4j.message.request.base.BaseNotifyRequest; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.request; package cn.hippo4j.threadpool.message.core.request;
import cn.hippo4j.message.request.base.BaseNotifyRequest; import cn.hippo4j.threadpool.message.core.request.base.BaseNotifyRequest;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.request; package cn.hippo4j.threadpool.message.core.request;
import lombok.Data; import lombok.Data;

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.request; package cn.hippo4j.threadpool.message.core.request;
import lombok.Data; import lombok.Data;

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.request; package cn.hippo4j.threadpool.message.core.request;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.request; package cn.hippo4j.threadpool.message.core.request;
import cn.hippo4j.message.request.base.BaseNotifyRequest; import cn.hippo4j.threadpool.message.core.request.base.BaseNotifyRequest;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -49,5 +49,4 @@ public class WebChangeParameterNotifyRequest extends BaseNotifyRequest {
private Long beforeKeepAliveTime; private Long beforeKeepAliveTime;
private Long nowKeepAliveTime; private Long nowKeepAliveTime;
} }

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.request.base; package cn.hippo4j.threadpool.message.core.request.base;
import cn.hippo4j.common.api.NotifyRequest; import cn.hippo4j.common.api.NotifyRequest;
import lombok.Data; import lombok.Data;

@ -15,11 +15,11 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.message.dto.AlarmControlDTO; import cn.hippo4j.threadpool.message.api.AlarmControlDTO;
import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;

@ -15,14 +15,17 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import cn.hippo4j.common.api.ThreadPoolConfigChange; import cn.hippo4j.common.api.ThreadPoolConfigChange;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.toolkit.IdentifyUtil; import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import static cn.hippo4j.common.propertie.EnvironmentProperties.active;
import static cn.hippo4j.common.propertie.EnvironmentProperties.applicationName;
import static cn.hippo4j.common.propertie.EnvironmentProperties.itemId;
import static cn.hippo4j.common.propertie.IdentifyProperties.IDENTIFY;
/** /**
* Default thread-pool config change handler. * Default thread-pool config change handler.
@ -30,16 +33,7 @@ import org.springframework.beans.factory.annotation.Value;
@RequiredArgsConstructor @RequiredArgsConstructor
public class DefaultThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<ChangeParameterNotifyRequest> { public class DefaultThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<ChangeParameterNotifyRequest> {
@Value("${spring.profiles.active:UNKNOWN}") private final ThreadPoolSendMessageService hippo4jSendMessageService;
private String active;
@Value("${spring.dynamic.thread-pool.item-id:}")
private String itemId;
@Value("${spring.application.name:UNKNOWN}")
private String applicationName;
private final Hippo4jSendMessageService hippo4jSendMessageService;
/** /**
* Send pool config change. * Send pool config change.
@ -51,7 +45,7 @@ public class DefaultThreadPoolConfigChangeHandler implements ThreadPoolConfigCha
requestParam.setActive(active.toUpperCase()); requestParam.setActive(active.toUpperCase());
String appName = StringUtil.isBlank(itemId) ? applicationName : itemId; String appName = StringUtil.isBlank(itemId) ? applicationName : itemId;
requestParam.setAppName(appName); requestParam.setAppName(appName);
requestParam.setIdentify(IdentifyUtil.getIdentify()); requestParam.setIdentify(IDENTIFY);
hippo4jSendMessageService.sendChangeMessage(requestParam); hippo4jSendMessageService.sendChangeMessage(requestParam);
} }
} }

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

@ -15,12 +15,18 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.core.request.AlarmNotifyRequest;
import cn.hippo4j.message.request.AlarmNotifyRequest; import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.core.request.WebChangeParameterNotifyRequest;
import cn.hippo4j.message.request.WebChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import lombok.SneakyThrows;
import org.springframework.core.io.ClassPathResource;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/** /**
* Send message handler. * Send message handler.
@ -59,4 +65,23 @@ public interface SendMessageHandler {
default void sendWebChangeMessage(NotifyConfigDTO notifyConfig, WebChangeParameterNotifyRequest changeParameterNotifyRequest) throws IllegalAccessException { default void sendWebChangeMessage(NotifyConfigDTO notifyConfig, WebChangeParameterNotifyRequest changeParameterNotifyRequest) throws IllegalAccessException {
throw new IllegalAccessException("Please implement this method before using it."); throw new IllegalAccessException("Please implement this method before using it.");
} }
@SneakyThrows
default String readUtf8String(String path) {
int endFlagCode = -1;
String resultReadStr;
ClassPathResource classPathResource = new ClassPathResource(path);
try (
InputStream inputStream = classPathResource.getInputStream();
BufferedInputStream bis = new BufferedInputStream(inputStream);
ByteArrayOutputStream buf = new ByteArrayOutputStream()) {
int result = bis.read();
while (result != endFlagCode) {
buf.write((byte) result);
result = bis.read();
}
resultReadStr = buf.toString("UTF-8");
}
return resultReadStr;
}
} }

@ -15,21 +15,18 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.message.api.NotifyConfigBuilder; import cn.hippo4j.threadpool.message.api.AlarmControlDTO;
import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import cn.hippo4j.message.dto.AlarmControlDTO; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.core.request.AlarmNotifyRequest;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.request.AlarmNotifyRequest; import cn.hippo4j.threadpool.message.core.request.WebChangeParameterNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.request.WebChangeParameterNotifyRequest;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -40,15 +37,14 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public class Hippo4jBaseSendMessageService implements Hippo4jSendMessageService, CommandLineRunner { public class ThreadPoolBaseSendMessageService implements ThreadPoolSendMessageService {
private final NotifyConfigBuilder notifyConfigBuilder;
private final AlarmControlHandler alarmControlHandler; private final AlarmControlHandler alarmControlHandler;
@Getter @Getter
private final Map<String, List<NotifyConfigDTO>> notifyConfigs = new HashMap<>(); private final Map<String, List<NotifyConfigDTO>> notifyConfigs = new HashMap<>();
@Getter
private final Map<String, SendMessageHandler> sendMessageHandlers = new HashMap<>(); private final Map<String, SendMessageHandler> sendMessageHandlers = new HashMap<>();
@Override @Override
@ -165,13 +161,4 @@ public class Hippo4jBaseSendMessageService implements Hippo4jSendMessageService,
public synchronized void putPlatform(Map<String, List<NotifyConfigDTO>> notifyConfigs) { public synchronized void putPlatform(Map<String, List<NotifyConfigDTO>> notifyConfigs) {
this.notifyConfigs.putAll(notifyConfigs); this.notifyConfigs.putAll(notifyConfigs);
} }
@Override
public void run(String... args) throws Exception {
Map<String, SendMessageHandler> sendMessageHandlerMap =
ApplicationContextHolder.getBeansOfType(SendMessageHandler.class);
sendMessageHandlerMap.values().forEach(each -> sendMessageHandlers.put(each.getType(), each));
Map<String, List<NotifyConfigDTO>> buildNotify = notifyConfigBuilder.buildNotify();
notifyConfigs.putAll(buildNotify);
}
} }

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

@ -15,17 +15,17 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.core.request.AlarmNotifyRequest;
import cn.hippo4j.message.request.AlarmNotifyRequest; import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.core.request.WebChangeParameterNotifyRequest;
import cn.hippo4j.message.request.WebChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
/** /**
* Hippo-4j send message service. * Hippo-4j send message service.
*/ */
public interface Hippo4jSendMessageService { public interface ThreadPoolSendMessageService {
/** /**
* Send dynamic thread pool alert notifications. * Send dynamic thread pool alert notifications.

@ -15,15 +15,18 @@
* limitations under the License. * limitations under the License.
*/ */
package cn.hippo4j.message.service; package cn.hippo4j.threadpool.message.core.service;
import cn.hippo4j.common.api.ThreadPoolConfigChange; import cn.hippo4j.common.api.ThreadPoolConfigChange;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.toolkit.IdentifyUtil; import cn.hippo4j.threadpool.message.core.request.WebChangeParameterNotifyRequest;
import cn.hippo4j.message.request.WebChangeParameterNotifyRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import static cn.hippo4j.common.propertie.EnvironmentProperties.active;
import static cn.hippo4j.common.propertie.EnvironmentProperties.applicationName;
import static cn.hippo4j.common.propertie.EnvironmentProperties.itemId;
import static cn.hippo4j.common.propertie.IdentifyProperties.IDENTIFY;
/** /**
* Web thread-pool config change handler. * Web thread-pool config change handler.
@ -32,16 +35,7 @@ import org.springframework.beans.factory.annotation.Value;
@Slf4j @Slf4j
public class WebThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<WebChangeParameterNotifyRequest> { public class WebThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<WebChangeParameterNotifyRequest> {
@Value("${spring.profiles.active:UNKNOWN}") private final ThreadPoolSendMessageService hippo4jSendMessageService;
private String active;
@Value("${spring.dynamic.thread-pool.item-id:}")
private String itemId;
@Value("${spring.application.name:UNKNOWN}")
private String applicationName;
private final Hippo4jSendMessageService hippo4jSendMessageService;
/** /**
* Send pool config change message for web. * Send pool config change message for web.
@ -54,10 +48,10 @@ public class WebThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<
requestParam.setActive(active.toUpperCase()); requestParam.setActive(active.toUpperCase());
String appName = StringUtil.isBlank(itemId) ? applicationName : itemId; String appName = StringUtil.isBlank(itemId) ? applicationName : itemId;
requestParam.setAppName(appName); requestParam.setAppName(appName);
requestParam.setIdentify(IdentifyUtil.getIdentify()); requestParam.setIdentify(IDENTIFY);
hippo4jSendMessageService.sendChangeMessage(requestParam); hippo4jSendMessageService.sendChangeMessage(requestParam);
} catch (Throwable th) { } catch (Throwable th) {
log.error("send web thread pool config change message failed.", th); log.error("Send web thread pool config change message failed.", th);
} }
} }
} }

@ -17,8 +17,9 @@
package cn.hippo4j.message.service; package cn.hippo4j.message.service;
import cn.hippo4j.message.dto.AlarmControlDTO; import cn.hippo4j.threadpool.message.api.AlarmControlDTO;
import cn.hippo4j.message.enums.NotifyTypeEnum; import cn.hippo4j.threadpool.message.api.NotifyTypeEnum;
import cn.hippo4j.threadpool.message.core.service.AlarmControlHandler;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-message-mode</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-threadpool-message-mode-config</artifactId>
</project>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-kernel-message</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-threadpool-message-mode</artifactId>
<packaging>pom</packaging>
<modules>
<module>config</module>
<module>server</module>
</modules>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-message-mode</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-threadpool-message-mode-server</artifactId>
</project>

@ -10,4 +10,11 @@
</parent> </parent>
<artifactId>hippo4j-threadpool-kernel-message</artifactId> <artifactId>hippo4j-threadpool-kernel-message</artifactId>
<packaging>pom</packaging>
<modules>
<module>api</module>
<module>core</module>
<module>mode</module>
</modules>
</project> </project>

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-starters</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-threadpool-spring-boot-starter-adapter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter-adapter</artifactId>

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-starters</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-threadpool-config-spring-boot-1x-starter</artifactId> <artifactId>hippo4j-threadpool-config-spring-boot-1x-starter</artifactId>

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-starters</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-threadpool-config-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-config-spring-boot-starter</artifactId>

@ -18,8 +18,6 @@
package cn.hippo4j.config.springboot.starter.config; package cn.hippo4j.config.springboot.starter.config;
import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.core.api.ThreadPoolCheckAlarm;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.springboot.starter.monitor.ThreadPoolMonitorExecutor; import cn.hippo4j.config.springboot.starter.monitor.ThreadPoolMonitorExecutor;
import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder; import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder;
@ -30,19 +28,22 @@ import cn.hippo4j.config.springboot.starter.refresher.event.WebExecutorRefreshLi
import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolAdapterRegister; import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolAdapterRegister;
import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolConfigService; import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolConfigService;
import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolPostProcessor; import cn.hippo4j.config.springboot.starter.support.DynamicThreadPoolPostProcessor;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.core.config.UtilAutoConfiguration; import cn.hippo4j.core.config.UtilAutoConfiguration;
import cn.hippo4j.core.enable.MarkerConfiguration; import cn.hippo4j.core.enable.MarkerConfiguration;
import cn.hippo4j.core.executor.handler.DynamicThreadPoolBannerHandler; import cn.hippo4j.core.executor.handler.DynamicThreadPoolBannerHandler;
import cn.hippo4j.message.api.NotifyConfigBuilder; import cn.hippo4j.core.extension.initialize.Hippo4jDynamicThreadPoolInitializer;
import cn.hippo4j.message.config.MessageConfiguration; import cn.hippo4j.message.config.MessageConfiguration;
import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.message.service.DefaultThreadPoolCheckAlarmHandler;
import cn.hippo4j.message.service.DefaultThreadPoolConfigChangeHandler;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService;
import cn.hippo4j.message.service.Hippo4jSendMessageService;
import cn.hippo4j.message.service.WebThreadPoolConfigChangeHandler;
import cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration; 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; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.threadpool.message.api.NotifyConfigBuilder;
import cn.hippo4j.threadpool.message.core.service.AlarmControlHandler;
import cn.hippo4j.threadpool.message.core.service.DefaultThreadPoolConfigChangeHandler;
import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService;
import cn.hippo4j.threadpool.message.core.service.ThreadPoolSendMessageService;
import cn.hippo4j.threadpool.message.core.service.WebThreadPoolConfigChangeHandler;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@ -91,13 +92,13 @@ public class DynamicThreadPoolAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ThreadPoolCheckAlarm defaultThreadPoolCheckAlarmHandler(Hippo4jSendMessageService hippo4jSendMessageService) { public ThreadPoolCheckAlarm defaultThreadPoolCheckAlarmHandler(ThreadPoolSendMessageService hippo4jSendMessageService) {
return new DefaultThreadPoolCheckAlarmHandler(hippo4jSendMessageService); return new DefaultThreadPoolCheckAlarmHandler(hippo4jSendMessageService);
} }
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public DefaultThreadPoolConfigChangeHandler defaultThreadPoolConfigChangeHandler(Hippo4jSendMessageService hippo4jSendMessageService) { public DefaultThreadPoolConfigChangeHandler defaultThreadPoolConfigChangeHandler(ThreadPoolSendMessageService hippo4jSendMessageService) {
return new DefaultThreadPoolConfigChangeHandler(hippo4jSendMessageService); return new DefaultThreadPoolConfigChangeHandler(hippo4jSendMessageService);
} }
@ -105,7 +106,7 @@ public class DynamicThreadPoolAutoConfiguration {
@ConditionalOnMissingBean @ConditionalOnMissingBean
public WebThreadPoolConfigChangeHandler webThreadPoolConfigChangeHandler(BootstrapConfigProperties bootstrapConfigProperties, public WebThreadPoolConfigChangeHandler webThreadPoolConfigChangeHandler(BootstrapConfigProperties bootstrapConfigProperties,
WebThreadPoolService webThreadPoolService, WebThreadPoolService webThreadPoolService,
Hippo4jSendMessageService hippo4jSendMessageService) { ThreadPoolSendMessageService hippo4jSendMessageService) {
if (bootstrapConfigProperties.getWeb() != null && StringUtil.isBlank(bootstrapConfigProperties.getWeb().getThreadPoolId())) { if (bootstrapConfigProperties.getWeb() != null && StringUtil.isBlank(bootstrapConfigProperties.getWeb().getThreadPoolId())) {
bootstrapConfigProperties.getWeb().setThreadPoolId(webThreadPoolService.getWebContainerType().getName()); bootstrapConfigProperties.getWeb().setThreadPoolId(webThreadPoolService.getWebContainerType().getName());
} }
@ -126,8 +127,8 @@ public class DynamicThreadPoolAutoConfiguration {
@SuppressWarnings("all") @SuppressWarnings("all")
public DynamicThreadPoolRefreshListener hippo4jExecutorsListener(DefaultThreadPoolConfigChangeHandler threadPoolConfigChange, public DynamicThreadPoolRefreshListener hippo4jExecutorsListener(DefaultThreadPoolConfigChangeHandler threadPoolConfigChange,
ConfigModeNotifyConfigBuilder configModeNotifyConfigBuilder, ConfigModeNotifyConfigBuilder configModeNotifyConfigBuilder,
Hippo4jBaseSendMessageService hippoBaseSendMessageService) { ThreadPoolBaseSendMessageService threadPoolBaseSendMessageService) {
return new DynamicThreadPoolRefreshListener(threadPoolConfigChange, configModeNotifyConfigBuilder, hippoBaseSendMessageService); return new DynamicThreadPoolRefreshListener(threadPoolConfigChange, configModeNotifyConfigBuilder, threadPoolBaseSendMessageService);
} }
@Bean @Bean
@ -160,4 +161,9 @@ public class DynamicThreadPoolAutoConfiguration {
public DynamicThreadPoolConfigService dynamicThreadPoolConfigService() { public DynamicThreadPoolConfigService dynamicThreadPoolConfigService() {
return new DynamicThreadPoolConfigService(); return new DynamicThreadPoolConfigService();
} }
@Bean
public Hippo4jDynamicThreadPoolInitializer hippo4jDynamicThreadPoolInitializer() {
return new Hippo4jDynamicThreadPoolInitializer();
}
} }

@ -17,31 +17,28 @@
package cn.hippo4j.config.springboot.starter.monitor; package cn.hippo4j.config.springboot.starter.monitor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.executor.ThreadFactoryBuilder; import cn.hippo4j.common.executor.ThreadFactoryBuilder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry; import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.MonitorProperties;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.monitor.base.DynamicThreadPoolMonitor; import cn.hippo4j.monitor.base.DynamicThreadPoolMonitor;
import cn.hippo4j.monitor.base.ThreadPoolMonitor; 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 lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import static cn.hippo4j.core.executor.manage.GlobalThreadPoolManage.getThreadPoolNum; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* Thread-pool monitor executor. * Thread-pool monitor executor.
@ -82,8 +79,8 @@ public class ThreadPoolMonitorExecutor implements ApplicationRunner, DisposableB
monitor.getInitialDelay(), monitor.getInitialDelay(),
monitor.getCollectInterval(), monitor.getCollectInterval(),
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
if (GlobalThreadPoolManage.getThreadPoolNum() > 0) { if (ThreadPoolExecutorRegistry.getThreadPoolExecutorSize() > 0) {
log.info("Dynamic thread pool: [{}]. The dynamic thread pool starts data collection and reporting.", getThreadPoolNum()); log.info("Dynamic thread pool: [{}]. The dynamic thread pool starts data collection and reporting.", ThreadPoolExecutorRegistry.getThreadPoolExecutorSize());
} }
} }

@ -26,9 +26,9 @@ import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.NotifyPlatformProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.NotifyPlatformProperties;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.WebExecutorProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.WebExecutorProperties;
import cn.hippo4j.message.api.NotifyConfigBuilder; import cn.hippo4j.threadpool.message.api.NotifyConfigBuilder;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import cn.hippo4j.message.service.AlarmControlHandler; import cn.hippo4j.threadpool.message.core.service.AlarmControlHandler;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

@ -18,7 +18,7 @@
package cn.hippo4j.config.springboot.starter.refresher; package cn.hippo4j.config.springboot.starter.refresher;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEvent; import cn.hippo4j.config.springboot.starter.refresher.event.ThreadPoolConfigDynamicRefreshEvent;
import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.threadpool.dynamic.api.BootstrapPropertiesInterface; import cn.hippo4j.threadpool.dynamic.api.BootstrapPropertiesInterface;
@ -73,7 +73,7 @@ public abstract class AbstractConfigThreadPoolDynamicRefresh implements ThreadPo
} }
private void publishDynamicThreadPoolEvent(BootstrapConfigProperties configProperties) { private void publishDynamicThreadPoolEvent(BootstrapConfigProperties configProperties) {
ApplicationContextHolder.getInstance().publishEvent(new Hippo4jConfigDynamicRefreshEvent(this, configProperties)); ApplicationContextHolder.getInstance().publishEvent(new ThreadPoolConfigDynamicRefreshEvent(this, configProperties));
} }
@Override @Override

@ -18,8 +18,8 @@
package cn.hippo4j.config.springboot.starter.refresher; package cn.hippo4j.config.springboot.starter.refresher;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.message.service.GlobalNotifyAlarmManage; import cn.hippo4j.threadpool.message.core.service.GlobalNotifyAlarmManage;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.threadpool.message.core.service.ThreadPoolNotifyAlarm;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.CuratorFrameworkFactory;

@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
* Refresh listener abstract base class. * Refresh listener abstract base class.
*/ */
@Slf4j @Slf4j
public abstract class AbstractRefreshListener<M> implements RefreshListener<Hippo4jConfigDynamicRefreshEvent, M> { public abstract class AbstractRefreshListener<M> implements RefreshListener<ThreadPoolConfigDynamicRefreshEvent, M> {
/** /**
* Matching nodes<br> * Matching nodes<br>

@ -34,7 +34,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL; import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEventOrder.ADAPTER_EXECUTORS_LISTENER; import static cn.hippo4j.config.springboot.starter.refresher.event.ThreadPoolConfigDynamicRefreshEventOrder.ADAPTER_EXECUTORS_LISTENER;
/** /**
* Adapter executors refresh listener. * Adapter executors refresh listener.
@ -52,7 +52,7 @@ public class AdapterExecutorsRefreshListener extends AbstractRefreshListener<Ada
} }
@Override @Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent event) { public void onApplicationEvent(ThreadPoolConfigDynamicRefreshEvent event) {
List<AdapterExecutorProperties> adapterExecutors = event.getBootstrapConfigProperties().getAdapterExecutors(); List<AdapterExecutorProperties> adapterExecutors = event.getBootstrapConfigProperties().getAdapterExecutors();
Map<String, ThreadPoolAdapter> threadPoolAdapterMap = ApplicationContextHolder.getBeansOfType(ThreadPoolAdapter.class); Map<String, ThreadPoolAdapter> threadPoolAdapterMap = ApplicationContextHolder.getBeansOfType(ThreadPoolAdapter.class);
if (CollectionUtil.isEmpty(adapterExecutors) || CollectionUtil.isEmpty(threadPoolAdapterMap)) { if (CollectionUtil.isEmpty(adapterExecutors) || CollectionUtil.isEmpty(threadPoolAdapterMap)) {

@ -18,22 +18,22 @@
package cn.hippo4j.config.springboot.starter.refresher.event; package cn.hippo4j.config.springboot.starter.refresher.event;
import cn.hippo4j.common.api.ThreadPoolConfigChange; import cn.hippo4j.common.api.ThreadPoolConfigChange;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue; import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue;
import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder; import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder;
import cn.hippo4j.threadpool.dynamic.core.executor.manage.GlobalConfigThreadPoolManage;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.service.GlobalNotifyAlarmManage; import cn.hippo4j.threadpool.message.core.service.GlobalNotifyAlarmManage;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService; import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.threadpool.message.core.service.ThreadPoolNotifyAlarm;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
@ -49,7 +49,7 @@ import java.util.concurrent.TimeUnit;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER; import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD_POOL_TEXT; import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD_POOL_TEXT;
import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEventOrder.EXECUTORS_LISTENER; import static cn.hippo4j.config.springboot.starter.refresher.event.ThreadPoolConfigDynamicRefreshEventOrder.EXECUTORS_LISTENER;
/** /**
* Dynamic thread-pool refresh listener. * Dynamic thread-pool refresh listener.
@ -63,7 +63,7 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
private final ConfigModeNotifyConfigBuilder configModeNotifyConfigBuilder; private final ConfigModeNotifyConfigBuilder configModeNotifyConfigBuilder;
private final Hippo4jBaseSendMessageService hippo4jBaseSendMessageService; private final ThreadPoolBaseSendMessageService threadPoolBaseSendMessageService;
@Override @Override
public String getNodes(ExecutorProperties properties) { public String getNodes(ExecutorProperties properties) {
@ -71,7 +71,7 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
} }
@Override @Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent event) { public void onApplicationEvent(ThreadPoolConfigDynamicRefreshEvent event) {
BootstrapConfigProperties bindableConfigProperties = event.getBootstrapConfigProperties(); BootstrapConfigProperties bindableConfigProperties = event.getBootstrapConfigProperties();
List<ExecutorProperties> executors = bindableConfigProperties.getExecutors(); List<ExecutorProperties> executors = bindableConfigProperties.getExecutors();
for (ExecutorProperties properties : executors) { for (ExecutorProperties properties : executors) {
@ -87,8 +87,9 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
continue; continue;
} }
dynamicRefreshPool(threadPoolId, properties); dynamicRefreshPool(threadPoolId, properties);
ExecutorProperties beforeProperties = GlobalConfigThreadPoolManage.getProperties(properties.getThreadPoolId()); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(properties.getThreadPoolId());
GlobalConfigThreadPoolManage.refresh(threadPoolId, failDefaultExecutorProperties(beforeProperties, properties)); ExecutorProperties beforeProperties = executorHolder.getExecutorProperties();
executorHolder.setExecutorProperties(failDefaultExecutorProperties(beforeProperties, properties));
ChangeParameterNotifyRequest changeRequest = buildChangeRequest(beforeProperties, properties); ChangeParameterNotifyRequest changeRequest = buildChangeRequest(beforeProperties, properties);
log.info(CHANGE_THREAD_POOL_TEXT, log.info(CHANGE_THREAD_POOL_TEXT,
threadPoolId, threadPoolId,
@ -168,7 +169,7 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
List<String> changeKeys = new ArrayList<>(); List<String> changeKeys = new ArrayList<>();
Map<String, List<NotifyConfigDTO>> newDynamicThreadPoolNotifyMap = Map<String, List<NotifyConfigDTO>> newDynamicThreadPoolNotifyMap =
configModeNotifyConfigBuilder.buildSingleNotifyConfig(executorProperties); configModeNotifyConfigBuilder.buildSingleNotifyConfig(executorProperties);
Map<String, List<NotifyConfigDTO>> notifyConfigs = hippo4jBaseSendMessageService.getNotifyConfigs(); Map<String, List<NotifyConfigDTO>> notifyConfigs = threadPoolBaseSendMessageService.getNotifyConfigs();
if (CollectionUtil.isNotEmpty(notifyConfigs)) { if (CollectionUtil.isNotEmpty(notifyConfigs)) {
for (Map.Entry<String, List<NotifyConfigDTO>> each : newDynamicThreadPoolNotifyMap.entrySet()) { for (Map.Entry<String, List<NotifyConfigDTO>> each : newDynamicThreadPoolNotifyMap.entrySet()) {
if (checkNotifyConfig) { if (checkNotifyConfig) {
@ -186,7 +187,7 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
} }
if (checkNotifyConfig) { if (checkNotifyConfig) {
configModeNotifyConfigBuilder.initCacheAndLock(newDynamicThreadPoolNotifyMap); configModeNotifyConfigBuilder.initCacheAndLock(newDynamicThreadPoolNotifyMap);
hippo4jBaseSendMessageService.putPlatform(newDynamicThreadPoolNotifyMap); threadPoolBaseSendMessageService.putPlatform(newDynamicThreadPoolNotifyMap);
} }
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(executorProperties.getThreadPoolId()); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = GlobalNotifyAlarmManage.get(executorProperties.getThreadPoolId());
if (threadPoolNotifyAlarm != null) { if (threadPoolNotifyAlarm != null) {
@ -215,8 +216,9 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
* @param properties * @param properties
*/ */
private boolean checkConsistency(String threadPoolId, ExecutorProperties properties) { private boolean checkConsistency(String threadPoolId, ExecutorProperties properties) {
ExecutorProperties beforeProperties = GlobalConfigThreadPoolManage.getProperties(properties.getThreadPoolId()); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(threadPoolId);
ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutor(threadPoolId); ExecutorProperties beforeProperties = executorHolder.getExecutorProperties();
ThreadPoolExecutor executor = executorHolder.getExecutor();
if (executor == null) { if (executor == null) {
return false; return false;
} }
@ -239,8 +241,8 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
* @param properties * @param properties
*/ */
private void dynamicRefreshPool(String threadPoolId, ExecutorProperties properties) { private void dynamicRefreshPool(String threadPoolId, ExecutorProperties properties) {
ExecutorProperties beforeProperties = GlobalConfigThreadPoolManage.getProperties(properties.getThreadPoolId()); ExecutorProperties beforeProperties = ThreadPoolExecutorRegistry.getHolder(threadPoolId).getExecutorProperties();
ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor(); ThreadPoolExecutor executor = ThreadPoolExecutorRegistry.getHolder(threadPoolId).getExecutor();
if (properties.getMaximumPoolSize() != null && properties.getCorePoolSize() != null) { if (properties.getMaximumPoolSize() != null && properties.getCorePoolSize() != null) {
ThreadPoolExecutorUtil.safeSetPoolSize(executor, properties.getCorePoolSize(), properties.getMaximumPoolSize()); ThreadPoolExecutorUtil.safeSetPoolSize(executor, properties.getCorePoolSize(), properties.getMaximumPoolSize());
} else { } else {

@ -17,20 +17,21 @@
package cn.hippo4j.config.springboot.starter.refresher.event; package cn.hippo4j.config.springboot.starter.refresher.event;
import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.model.executor.ExecutorProperties; import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder; import cn.hippo4j.config.springboot.starter.notify.ConfigModeNotifyConfigBuilder;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.message.dto.NotifyConfigDTO; import cn.hippo4j.threadpool.message.api.NotifyConfigDTO;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService; import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEventOrder.PLATFORMS_LISTENER; import static cn.hippo4j.config.springboot.starter.refresher.event.ThreadPoolConfigDynamicRefreshEventOrder.PLATFORMS_LISTENER;
/** /**
* Platforms refresh listener. * Platforms refresh listener.
@ -39,18 +40,25 @@ import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfig
public class PlatformsRefreshListener extends AbstractRefreshListener<ExecutorProperties> { public class PlatformsRefreshListener extends AbstractRefreshListener<ExecutorProperties> {
@Override @Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(ThreadPoolConfigDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
BootstrapConfigProperties bindableConfigProperties = threadPoolDynamicRefreshEvent.getBootstrapConfigProperties(); BootstrapConfigProperties bindableConfigProperties = threadPoolDynamicRefreshEvent.getBootstrapConfigProperties();
List<ExecutorProperties> executors = bindableConfigProperties.getExecutors(); List<ExecutorProperties> executors = bindableConfigProperties.getExecutors();
for (ExecutorProperties executorProperties : executors) { for (ExecutorProperties executorProperties : executors) {
String threadPoolId = executorProperties.getThreadPoolId(); String threadPoolId = executorProperties.getThreadPoolId();
DynamicThreadPoolWrapper wrapper = GlobalThreadPoolManage.getExecutorService(threadPoolId); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(threadPoolId);
if (wrapper != null && !wrapper.isInitFlag()) { ThreadPoolBaseSendMessageService sendMessageService = ApplicationContextHolder.getBean(ThreadPoolBaseSendMessageService.class);
Hippo4jBaseSendMessageService sendMessageService = ApplicationContextHolder.getBean(Hippo4jBaseSendMessageService.class); /**
* TODO The logic here should be:
*
* 1. When the application starts, the thread pool parameters are not configured in the configuration center
* 2. After the application starts, put the relevant configuration into the configuration center
* 3. Use whether there is a thread pool notification as a judgment condition
*/
List<NotifyConfigDTO> notifyConfigList = sendMessageService.getNotifyConfigs().get(threadPoolId);
if (executorHolder != null && CollectionUtil.isEmpty(notifyConfigList)) {
ConfigModeNotifyConfigBuilder configBuilder = ApplicationContextHolder.getBean(ConfigModeNotifyConfigBuilder.class); ConfigModeNotifyConfigBuilder configBuilder = ApplicationContextHolder.getBean(ConfigModeNotifyConfigBuilder.class);
Map<String, List<NotifyConfigDTO>> notifyConfig = configBuilder.buildSingleNotifyConfig(executorProperties); Map<String, List<NotifyConfigDTO>> notifyConfig = configBuilder.buildSingleNotifyConfig(executorProperties);
sendMessageService.putPlatform(notifyConfig); sendMessageService.putPlatform(notifyConfig);
wrapper.setInitFlag(Boolean.TRUE);
} }
} }
} }

@ -25,13 +25,13 @@ import org.springframework.context.ApplicationEvent;
/** /**
* Hippo-4j config dynamic refresh event. * Hippo-4j config dynamic refresh event.
*/ */
public class Hippo4jConfigDynamicRefreshEvent extends ApplicationEvent { public class ThreadPoolConfigDynamicRefreshEvent extends ApplicationEvent {
@Getter @Getter
@Setter @Setter
private BootstrapConfigProperties bootstrapConfigProperties; private BootstrapConfigProperties bootstrapConfigProperties;
public Hippo4jConfigDynamicRefreshEvent(Object source, BootstrapConfigProperties bootstrapConfigProperties) { public ThreadPoolConfigDynamicRefreshEvent(Object source, BootstrapConfigProperties bootstrapConfigProperties) {
super(source); super(source);
this.bootstrapConfigProperties = bootstrapConfigProperties; this.bootstrapConfigProperties = bootstrapConfigProperties;
} }

@ -20,7 +20,7 @@ package cn.hippo4j.config.springboot.starter.refresher.event;
/** /**
* Hippo-4j config dynamic refresh event order. * Hippo-4j config dynamic refresh event order.
*/ */
public class Hippo4jConfigDynamicRefreshEventOrder { public class ThreadPoolConfigDynamicRefreshEventOrder {
public static final int WEB_EXECUTOR_LISTENER = 0; public static final int WEB_EXECUTOR_LISTENER = 0;

@ -20,18 +20,18 @@ package cn.hippo4j.config.springboot.starter.refresher.event;
import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose; import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose;
import cn.hippo4j.adapter.web.WebThreadPoolService; import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.api.ThreadPoolConfigChange; import cn.hippo4j.common.api.ThreadPoolConfigChange;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.model.ThreadPoolParameter; import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo; import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.WebExecutorProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.WebExecutorProperties;
import cn.hippo4j.message.request.WebChangeParameterNotifyRequest; import cn.hippo4j.threadpool.message.core.request.WebChangeParameterNotifyRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import java.util.Objects; import java.util.Objects;
import static cn.hippo4j.config.springboot.starter.refresher.event.Hippo4jConfigDynamicRefreshEventOrder.WEB_EXECUTOR_LISTENER; import static cn.hippo4j.config.springboot.starter.refresher.event.ThreadPoolConfigDynamicRefreshEventOrder.WEB_EXECUTOR_LISTENER;
/** /**
* Web executor refresh listener. * Web executor refresh listener.
@ -53,7 +53,7 @@ public class WebExecutorRefreshListener extends AbstractRefreshListener<WebExecu
} }
@Override @Override
public void onApplicationEvent(Hippo4jConfigDynamicRefreshEvent threadPoolDynamicRefreshEvent) { public void onApplicationEvent(ThreadPoolConfigDynamicRefreshEvent threadPoolDynamicRefreshEvent) {
BootstrapConfigProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapConfigProperties(); BootstrapConfigProperties bindableCoreProperties = threadPoolDynamicRefreshEvent.getBootstrapConfigProperties();
if (bindableCoreProperties.getWeb() == null) { if (bindableCoreProperties.getWeb() == null) {
return; return;
@ -89,6 +89,7 @@ public class WebExecutorRefreshListener extends AbstractRefreshListener<WebExecu
/** /**
* Constructing a request for web thread pool parameter change notification * Constructing a request for web thread pool parameter change notification
*
* @param before * @param before
* @param now * @param now
* @return * @return

@ -17,19 +17,17 @@
package cn.hippo4j.config.springboot.starter.support; package cn.hippo4j.config.springboot.starter.support;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterParameter; import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterParameter;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper; import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper;
import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterCoreNotifyParameter; import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterCoreNotifyParameter;
import cn.hippo4j.common.toolkit.BooleanUtil; import cn.hippo4j.common.toolkit.BooleanUtil;
import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.support.service.AbstractDynamicThreadPoolService; import cn.hippo4j.core.executor.support.service.AbstractDynamicThreadPoolService;
import cn.hippo4j.message.service.GlobalNotifyAlarmManage; import cn.hippo4j.threadpool.message.core.service.GlobalNotifyAlarmManage;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.threadpool.message.core.service.ThreadPoolNotifyAlarm;
import cn.hippo4j.threadpool.dynamic.core.executor.manage.GlobalConfigThreadPoolManage;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -43,13 +41,8 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer
DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getParameter(); DynamicThreadPoolRegisterParameter registerParameter = registerWrapper.getParameter();
String threadPoolId = registerParameter.getThreadPoolId(); String threadPoolId = registerParameter.getThreadPoolId();
ThreadPoolExecutor dynamicThreadPoolExecutor = buildDynamicThreadPoolExecutor(registerParameter); ThreadPoolExecutor dynamicThreadPoolExecutor = buildDynamicThreadPoolExecutor(registerParameter);
DynamicThreadPoolWrapper dynamicThreadPoolWrapper = DynamicThreadPoolWrapper.builder()
.threadPoolId(threadPoolId)
.executor(dynamicThreadPoolExecutor)
.build();
GlobalThreadPoolManage.registerPool(threadPoolId, dynamicThreadPoolWrapper);
ExecutorProperties executorProperties = buildExecutorProperties(registerWrapper); ExecutorProperties executorProperties = buildExecutorProperties(registerWrapper);
GlobalConfigThreadPoolManage.register(threadPoolId, executorProperties); ThreadPoolExecutorRegistry.putHolder(threadPoolId, dynamicThreadPoolExecutor, executorProperties);
DynamicThreadPoolRegisterCoreNotifyParameter notifyParameter = registerWrapper.getConfigNotify(); DynamicThreadPoolRegisterCoreNotifyParameter notifyParameter = registerWrapper.getConfigNotify();
ThreadPoolNotifyAlarm notifyAlarm = new ThreadPoolNotifyAlarm(true, registerParameter.getActiveAlarm(), registerParameter.getCapacityAlarm()); ThreadPoolNotifyAlarm notifyAlarm = new ThreadPoolNotifyAlarm(true, registerParameter.getActiveAlarm(), registerParameter.getCapacityAlarm());
notifyAlarm.setReceives(notifyParameter.getReceives()); notifyAlarm.setReceives(notifyParameter.getReceives());

@ -17,25 +17,23 @@
package cn.hippo4j.config.springboot.starter.support; package cn.hippo4j.config.springboot.starter.support;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.common.model.executor.ExecutorNotifyProperties; import cn.hippo4j.common.model.executor.ExecutorNotifyProperties;
import cn.hippo4j.common.model.executor.ExecutorProperties; import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.core.executor.DynamicThreadPool; import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose; import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose;
import cn.hippo4j.core.toolkit.DynamicThreadPoolAnnotationUtil; import cn.hippo4j.core.toolkit.DynamicThreadPoolAnnotationUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
import cn.hippo4j.message.service.GlobalNotifyAlarmManage; import cn.hippo4j.threadpool.message.core.service.GlobalNotifyAlarmManage;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.threadpool.message.core.service.ThreadPoolNotifyAlarm;
import cn.hippo4j.threadpool.dynamic.core.executor.manage.GlobalConfigThreadPoolManage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
@ -90,27 +88,20 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
if (dynamicThreadPoolExecutor == null) { if (dynamicThreadPoolExecutor == null) {
dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) bean; dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) bean;
} }
// TODO ThreadPoolExecutor remoteThreadPoolExecutor = fillPoolAndRegister(((DynamicThreadPoolExecutor) dynamicThreadPoolExecutor).getThreadPoolId(), dynamicThreadPoolExecutor);
DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(((DynamicThreadPoolExecutor) dynamicThreadPoolExecutor).getThreadPoolId(), dynamicThreadPoolExecutor);
ThreadPoolExecutor remoteThreadPoolExecutor = fillPoolAndRegister(wrap);
DynamicThreadPoolAdapterChoose.replace(bean, remoteThreadPoolExecutor); DynamicThreadPoolAdapterChoose.replace(bean, remoteThreadPoolExecutor);
return DynamicThreadPoolAdapterChoose.match(bean) ? bean : remoteThreadPoolExecutor; return DynamicThreadPoolAdapterChoose.match(bean) ? bean : remoteThreadPoolExecutor;
} }
if (bean instanceof DynamicThreadPoolWrapper) {
DynamicThreadPoolWrapper wrap = (DynamicThreadPoolWrapper) bean;
fillPoolAndRegister(wrap);
}
return bean; return bean;
} }
/** /**
* Fill the thread pool and register. * Fill the thread pool and register.
* *
* @param dynamicThreadPoolWrapper dynamic thread-pool wrapper * @param threadPoolId dynamic thread-pool id
* @param executor dynamic thread-pool executor
*/ */
protected ThreadPoolExecutor fillPoolAndRegister(DynamicThreadPoolWrapper dynamicThreadPoolWrapper) { protected ThreadPoolExecutor fillPoolAndRegister(String threadPoolId, ThreadPoolExecutor executor) {
String threadPoolId = dynamicThreadPoolWrapper.getThreadPoolId();
ThreadPoolExecutor executor = dynamicThreadPoolWrapper.getExecutor();
ExecutorProperties executorProperties = null; ExecutorProperties executorProperties = null;
if (configProperties.getExecutors() != null) { if (configProperties.getExecutors() != null) {
executorProperties = configProperties.getExecutors() executorProperties = configProperties.getExecutors()
@ -123,18 +114,20 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
threadPoolParamReplace(executor, executorProperties); threadPoolParamReplace(executor, executorProperties);
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to initialize thread pool configuration.", ex); log.error("Failed to initialize thread pool configuration.", ex);
} finally {
dynamicThreadPoolWrapper.setInitFlag(Boolean.TRUE);
} }
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = buildThreadPoolNotifyAlarm(executorProperties); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = buildThreadPoolNotifyAlarm(executorProperties);
GlobalNotifyAlarmManage.put(threadPoolId, threadPoolNotifyAlarm); GlobalNotifyAlarmManage.put(threadPoolId, threadPoolNotifyAlarm);
} }
GlobalThreadPoolManage.registerPool(dynamicThreadPoolWrapper.getThreadPoolId(), dynamicThreadPoolWrapper); ThreadPoolExecutorRegistry.putHolder(threadPoolId, executor,
GlobalConfigThreadPoolManage.register(
threadPoolId,
executorProperties == null executorProperties == null
? buildDefaultExecutorProperties(threadPoolId, executor) ? buildDefaultExecutorProperties(threadPoolId, executor)
: executorProperties); : executorProperties);
// GlobalThreadPoolManage.registerPool(dynamicThreadPoolWrapper.getThreadPoolId(), dynamicThreadPoolWrapper);
// GlobalConfigThreadPoolManage.register(
// threadPoolId,
// executorProperties == null
// ? buildDefaultExecutorProperties(threadPoolId, executor)
// : executorProperties);
return executor; return executor;
} }

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-starters</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-threadpool-spring-boot-starter-monitor</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter-monitor</artifactId>

@ -7,7 +7,7 @@
<artifactId>hippo4j-starters</artifactId> <artifactId>hippo4j-starters</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-threadpool-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-starters</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>

@ -4,10 +4,10 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-starters</artifactId>
<version>${revision}</version> <version>${revision}</version>
</parent> </parent>
<artifactId>hippo4j-threadpool-server-spring-boot-starter</artifactId> <artifactId>hippo4j-threadpool-spring-boot-starter</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
@ -81,5 +81,10 @@
<artifactId>hippo4j-threadpool-dynamic-api</artifactId> <artifactId>hippo4j-threadpool-dynamic-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-kernel-alarm</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -20,7 +20,6 @@ package cn.hippo4j.springboot.starter.config;
import cn.hippo4j.adapter.base.ThreadPoolAdapterBeanContainer; import cn.hippo4j.adapter.base.ThreadPoolAdapterBeanContainer;
import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose; import cn.hippo4j.adapter.web.WebThreadPoolHandlerChoose;
import cn.hippo4j.common.api.ThreadDetailState; import cn.hippo4j.common.api.ThreadDetailState;
import cn.hippo4j.core.api.ThreadPoolCheckAlarm;
import cn.hippo4j.common.api.ThreadPoolConfigChange; import cn.hippo4j.common.api.ThreadPoolConfigChange;
import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.core.config.ApplicationContextHolder;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
@ -29,15 +28,10 @@ import cn.hippo4j.core.enable.MarkerConfiguration;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler; import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.executor.support.service.DynamicThreadPoolService; import cn.hippo4j.core.executor.support.service.DynamicThreadPoolService;
import cn.hippo4j.core.executor.handler.DynamicThreadPoolBannerHandler; import cn.hippo4j.core.executor.handler.DynamicThreadPoolBannerHandler;
import cn.hippo4j.core.extension.initialize.Hippo4jDynamicThreadPoolInitializer;
import cn.hippo4j.core.toolkit.IdentifyUtil; import cn.hippo4j.core.toolkit.IdentifyUtil;
import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.core.toolkit.inet.InetUtils;
import cn.hippo4j.message.api.NotifyConfigBuilder;
import cn.hippo4j.message.config.MessageConfiguration; import cn.hippo4j.message.config.MessageConfiguration;
import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.message.service.DefaultThreadPoolCheckAlarmHandler;
import cn.hippo4j.message.service.DefaultThreadPoolConfigChangeHandler;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService;
import cn.hippo4j.message.service.Hippo4jSendMessageService;
import cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration; import cn.hippo4j.springboot.starter.adapter.web.WebAdapterConfiguration;
import cn.hippo4j.springboot.starter.controller.ThreadPoolAdapterController; import cn.hippo4j.springboot.starter.controller.ThreadPoolAdapterController;
import cn.hippo4j.springboot.starter.controller.WebThreadPoolController; import cn.hippo4j.springboot.starter.controller.WebThreadPoolController;
@ -62,7 +56,14 @@ import cn.hippo4j.springboot.starter.support.AdaptedThreadPoolDestroyPostProcess
import cn.hippo4j.springboot.starter.support.DynamicThreadPoolConfigService; import cn.hippo4j.springboot.starter.support.DynamicThreadPoolConfigService;
import cn.hippo4j.springboot.starter.support.DynamicThreadPoolPostProcessor; import cn.hippo4j.springboot.starter.support.DynamicThreadPoolPostProcessor;
import cn.hippo4j.springboot.starter.support.ThreadPoolPluginRegisterPostProcessor; import cn.hippo4j.springboot.starter.support.ThreadPoolPluginRegisterPostProcessor;
import cn.hippo4j.threadpool.alarm.api.ThreadPoolCheckAlarm;
import cn.hippo4j.threadpool.alarm.handler.DefaultThreadPoolCheckAlarmHandler;
import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh; import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh;
import cn.hippo4j.threadpool.message.api.NotifyConfigBuilder;
import cn.hippo4j.threadpool.message.core.service.AlarmControlHandler;
import cn.hippo4j.threadpool.message.core.service.DefaultThreadPoolConfigChangeHandler;
import cn.hippo4j.threadpool.message.core.service.ThreadPoolBaseSendMessageService;
import cn.hippo4j.threadpool.message.core.service.ThreadPoolSendMessageService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@ -126,9 +127,9 @@ public class DynamicThreadPoolAutoConfiguration {
public DynamicThreadPoolService dynamicThreadPoolConfigService(HttpAgent httpAgent, public DynamicThreadPoolService dynamicThreadPoolConfigService(HttpAgent httpAgent,
ServerHealthCheck serverHealthCheck, ServerHealthCheck serverHealthCheck,
ServerModeNotifyConfigBuilder serverModeNotifyConfigBuilder, ServerModeNotifyConfigBuilder serverModeNotifyConfigBuilder,
Hippo4jBaseSendMessageService hippo4jBaseSendMessageService, ThreadPoolBaseSendMessageService threadPoolBaseSendMessageService,
DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig) { DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig) {
return new DynamicThreadPoolConfigService(httpAgent, properties, serverModeNotifyConfigBuilder, hippo4jBaseSendMessageService, dynamicThreadPoolSubscribeConfig); return new DynamicThreadPoolConfigService(httpAgent, properties, serverModeNotifyConfigBuilder, threadPoolBaseSendMessageService, dynamicThreadPoolSubscribeConfig);
} }
@Bean @Bean
@ -219,13 +220,13 @@ public class DynamicThreadPoolAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ThreadPoolCheckAlarm defaultThreadPoolCheckAlarmHandler(Hippo4jSendMessageService hippo4jSendMessageService) { public ThreadPoolCheckAlarm defaultThreadPoolCheckAlarmHandler(ThreadPoolSendMessageService hippo4jSendMessageService) {
return new DefaultThreadPoolCheckAlarmHandler(hippo4jSendMessageService); return new DefaultThreadPoolCheckAlarmHandler(hippo4jSendMessageService);
} }
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ThreadPoolConfigChange defaultThreadPoolConfigChangeHandler(Hippo4jSendMessageService hippo4jSendMessageService) { public ThreadPoolConfigChange defaultThreadPoolConfigChangeHandler(ThreadPoolSendMessageService hippo4jSendMessageService) {
return new DefaultThreadPoolConfigChangeHandler(hippo4jSendMessageService); return new DefaultThreadPoolConfigChangeHandler(hippo4jSendMessageService);
} }
@ -249,4 +250,9 @@ public class DynamicThreadPoolAutoConfiguration {
public ThreadPoolPluginRegisterPostProcessor threadPoolPluginRegisterPostProcessor() { public ThreadPoolPluginRegisterPostProcessor threadPoolPluginRegisterPostProcessor() {
return new ThreadPoolPluginRegisterPostProcessor(); return new ThreadPoolPluginRegisterPostProcessor();
} }
@Bean
public Hippo4jDynamicThreadPoolInitializer hippo4jDynamicThreadPoolInitializer() {
return new Hippo4jDynamicThreadPoolInitializer();
}
} }

@ -18,11 +18,11 @@
package cn.hippo4j.springboot.starter.core; package cn.hippo4j.springboot.starter.core;
import cn.hippo4j.common.api.ThreadDetailState; import cn.hippo4j.common.api.ThreadDetailState;
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.model.ThreadDetailStateInfo; import cn.hippo4j.common.model.ThreadDetailStateInfo;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.ReflectUtil; import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,8 +44,8 @@ public class BaseThreadDetailStateHandler implements ThreadDetailState {
@Override @Override
public List<ThreadDetailStateInfo> getThreadDetailStateInfo(String threadPoolId) { public List<ThreadDetailStateInfo> getThreadDetailStateInfo(String threadPoolId) {
DynamicThreadPoolWrapper dynamicThreadPoolWrapper = GlobalThreadPoolManage.getExecutorService(threadPoolId); ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(threadPoolId);
ThreadPoolExecutor threadPoolExecutor = dynamicThreadPoolWrapper.getExecutor(); ThreadPoolExecutor threadPoolExecutor = executorHolder.getExecutor();
return getThreadDetailStateInfo(threadPoolExecutor); return getThreadDetailStateInfo(threadPoolExecutor);
} }

@ -17,6 +17,7 @@
package cn.hippo4j.springboot.starter.core; package cn.hippo4j.springboot.starter.core;
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.springboot.starter.wrapper.ManagerListenerWrapper; import cn.hippo4j.springboot.starter.wrapper.ManagerListenerWrapper;
import cn.hippo4j.common.toolkit.ContentUtil; import cn.hippo4j.common.toolkit.ContentUtil;
@ -57,7 +58,7 @@ public class CacheData {
this.tenantId = tenantId; this.tenantId = tenantId;
this.itemId = itemId; this.itemId = itemId;
this.threadPoolId = threadPoolId; this.threadPoolId = threadPoolId;
this.content = ContentUtil.getPoolContent(GlobalThreadPoolManage.getPoolParameter(threadPoolId)); this.content = ContentUtil.getPoolContent(ThreadPoolExecutorRegistry.getHolder(threadPoolId).getParameterInfo());
this.md5 = getMd5String(content); this.md5 = getMd5String(content);
this.listeners = new CopyOnWriteArrayList<>(); this.listeners = new CopyOnWriteArrayList<>();
} }

@ -18,18 +18,18 @@
package cn.hippo4j.springboot.starter.core; package cn.hippo4j.springboot.starter.core;
import cn.hippo4j.common.api.ThreadPoolConfigChange; import cn.hippo4j.common.api.ThreadPoolConfigChange;
import cn.hippo4j.common.extension.enums.EnableEnum; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue; import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue;
import cn.hippo4j.common.extension.enums.EnableEnum;
import cn.hippo4j.common.model.ThreadPoolParameter; import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo; import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil; import cn.hippo4j.common.toolkit.ThreadPoolExecutorUtil;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh; import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh;
import cn.hippo4j.threadpool.message.core.request.ChangeParameterNotifyRequest;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -55,7 +55,7 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
public void dynamicRefresh(String content) { public void dynamicRefresh(String content) {
ThreadPoolParameterInfo parameter = JSONUtil.parseObject(content, ThreadPoolParameterInfo.class); ThreadPoolParameterInfo parameter = JSONUtil.parseObject(content, ThreadPoolParameterInfo.class);
String threadPoolId = parameter.getTpId(); String threadPoolId = parameter.getTpId();
ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor(); ThreadPoolExecutor executor = ThreadPoolExecutorRegistry.getHolder(threadPoolId).getExecutor();
refreshDynamicPool(parameter, executor); refreshDynamicPool(parameter, executor);
} }
@ -75,7 +75,7 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
originalExecuteTimeOut = dynamicExecutor.getExecuteTimeOut(); originalExecuteTimeOut = dynamicExecutor.getExecuteTimeOut();
} }
changePoolInfo(executor, parameter); changePoolInfo(executor, parameter);
ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor(); ThreadPoolExecutor afterExecutor = ThreadPoolExecutorRegistry.getHolder(threadPoolId).getExecutor();
String originalRejected = rejectedExecutionHandler.getClass().getSimpleName(); String originalRejected = rejectedExecutionHandler.getClass().getSimpleName();
Long executeTimeOut = Optional.ofNullable(parameter.getExecuteTimeOut()).orElse(0L); Long executeTimeOut = Optional.ofNullable(parameter.getExecuteTimeOut()).orElse(0L);
ChangeParameterNotifyRequest changeNotifyRequest = ChangeParameterNotifyRequest.builder() ChangeParameterNotifyRequest changeNotifyRequest = ChangeParameterNotifyRequest.builder()

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save