hippo4j-adapter CheckStyle ERROR (#915)

* style:hippo4j-adapter CheckStyle ERROR

* style:hippo4j-adapter CheckStyle ERROR
pull/924/head
WuLang 3 years ago committed by GitHub
parent 429c2d0643
commit 59cb0b28c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,4 +25,6 @@
<suppress checks="StaticVariableName" files="ApplicationContextHolder.java"/> <suppress checks="StaticVariableName" files="ApplicationContextHolder.java"/>
<suppress checks="StaticVariableName" files="JacksonHandler.java"/> <suppress checks="StaticVariableName" files="JacksonHandler.java"/>
<suppress checks="MagicNumber" files="ByteConvertUtil.java"/> <suppress checks="MagicNumber" files="ByteConvertUtil.java"/>
<suppress checks="MagicNumber" files="DubboThreadPoolAdapter.java"/>
<suppress checks="MagicNumber" files="UndertowWebThreadPoolHandler.java"/>
</suppressions> </suppressions>

@ -17,7 +17,11 @@
package cn.hippo4j.adapter.hystrix; package cn.hippo4j.adapter.hystrix;
import cn.hippo4j.adapter.base.*; import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterRegisterAction;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import com.netflix.hystrix.HystrixThreadPool; import com.netflix.hystrix.HystrixThreadPool;
@ -48,9 +52,9 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
private static final String THREAD_POOLS_FIELD = "threadPools"; private static final String THREAD_POOLS_FIELD = "threadPools";
private final Map<String, ThreadPoolExecutor> HYSTRIX_CONSUME_EXECUTOR = new HashMap<>(); private final Map<String, ThreadPoolExecutor> hystrixConsumeExecutor = new HashMap<>();
private ThreadPoolAdapterScheduler threadPoolAdapterScheduler; private final ThreadPoolAdapterScheduler threadPoolAdapterScheduler;
public HystrixThreadPoolAdapter(ThreadPoolAdapterScheduler threadPoolAdapterScheduler) { public HystrixThreadPoolAdapter(ThreadPoolAdapterScheduler threadPoolAdapterScheduler) {
this.threadPoolAdapterScheduler = threadPoolAdapterScheduler; this.threadPoolAdapterScheduler = threadPoolAdapterScheduler;
@ -64,7 +68,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
@Override @Override
public ThreadPoolAdapterState getThreadPoolState(String identify) { public ThreadPoolAdapterState getThreadPoolState(String identify) {
ThreadPoolAdapterState result = new ThreadPoolAdapterState(); ThreadPoolAdapterState result = new ThreadPoolAdapterState();
ThreadPoolExecutor threadPoolExecutor = HYSTRIX_CONSUME_EXECUTOR.get(identify); ThreadPoolExecutor threadPoolExecutor = hystrixConsumeExecutor.get(identify);
if (threadPoolExecutor != null) { if (threadPoolExecutor != null) {
result.setThreadPoolKey(identify); result.setThreadPoolKey(identify);
result.setCoreSize(threadPoolExecutor.getCorePoolSize()); result.setCoreSize(threadPoolExecutor.getCorePoolSize());
@ -78,14 +82,14 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
@Override @Override
public List<ThreadPoolAdapterState> getThreadPoolStates() { public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> threadPoolAdapterStates = new ArrayList<>(); List<ThreadPoolAdapterState> threadPoolAdapterStates = new ArrayList<>();
HYSTRIX_CONSUME_EXECUTOR.forEach((kel, val) -> threadPoolAdapterStates.add(getThreadPoolState(kel))); hystrixConsumeExecutor.forEach((kel, val) -> threadPoolAdapterStates.add(getThreadPoolState(kel)));
return threadPoolAdapterStates; return threadPoolAdapterStates;
} }
@Override @Override
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) { public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) {
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey(); String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
ThreadPoolExecutor threadPoolExecutor = HYSTRIX_CONSUME_EXECUTOR.get(threadPoolKey); ThreadPoolExecutor threadPoolExecutor = hystrixConsumeExecutor.get(threadPoolKey);
if (threadPoolExecutor == null) { if (threadPoolExecutor == null) {
log.warn("[{}] Hystrix thread pool not found.", threadPoolKey); log.warn("[{}] Hystrix thread pool not found.", threadPoolKey);
return false; return false;
@ -135,7 +139,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
threadPoolField.setAccessible(true); threadPoolField.setAccessible(true);
ThreadPoolExecutor threadPoolExecutor = ThreadPoolExecutor threadPoolExecutor =
(ThreadPoolExecutor) threadPoolField.get(hystrixThreadPoolDefault); (ThreadPoolExecutor) threadPoolField.get(hystrixThreadPoolDefault);
HYSTRIX_CONSUME_EXECUTOR.put(key, threadPoolExecutor); hystrixConsumeExecutor.put(key, threadPoolExecutor);
} }
} }
} }
@ -179,7 +183,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
private int taskIntervalSeconds; private int taskIntervalSeconds;
public HystrixThreadPoolRefreshTask(ScheduledExecutorService scheduler, int taskIntervalSeconds) { HystrixThreadPoolRefreshTask(ScheduledExecutorService scheduler, int taskIntervalSeconds) {
this.scheduler = scheduler; this.scheduler = scheduler;
this.taskIntervalSeconds = taskIntervalSeconds; this.taskIntervalSeconds = taskIntervalSeconds;
} }
@ -196,6 +200,9 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
} }
} }
/**
* Thread Pool Adapter Register Task
*/
class ThreadPoolAdapterRegisterTask implements Runnable { class ThreadPoolAdapterRegisterTask implements Runnable {
private ScheduledExecutorService scheduler; private ScheduledExecutorService scheduler;
@ -208,7 +215,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
private List<ThreadPoolAdapterCacheConfig> cacheConfigList = new ArrayList<>(); private List<ThreadPoolAdapterCacheConfig> cacheConfigList = new ArrayList<>();
public ThreadPoolAdapterRegisterTask(ScheduledExecutorService scheduler, int taskIntervalSeconds, ThreadPoolAdapterRegisterTask(ScheduledExecutorService scheduler, int taskIntervalSeconds,
Map<String, ThreadPoolAdapter> threadPoolAdapterMap, Map<String, ThreadPoolAdapter> threadPoolAdapterMap,
ThreadPoolAdapterRegisterAction threadPoolAdapterRegisterAction) { ThreadPoolAdapterRegisterAction threadPoolAdapterRegisterAction) {
this.scheduler = scheduler; this.scheduler = scheduler;

@ -27,7 +27,11 @@ import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -42,11 +46,11 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
private static final String RABBITMQ = "RabbitMQ"; private static final String RABBITMQ = "RabbitMQ";
private static final String FiledName = "executorService"; private static final String FILED_NAME = "executorService";
private final Map<String, AbstractConnectionFactory> abstractConnectionFactoryMap; private final Map<String, AbstractConnectionFactory> abstractConnectionFactoryMap;
private final Map<String, ThreadPoolExecutor> RABBITMQ_THREAD_POOL_TASK_EXECUTOR = new HashMap<>(); private final Map<String, ThreadPoolExecutor> rabbitmqThreadPoolTaskExecutor = new HashMap<>();
@Override @Override
public String mark() { public String mark() {
@ -56,7 +60,7 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public ThreadPoolAdapterState getThreadPoolState(String identify) { public ThreadPoolAdapterState getThreadPoolState(String identify) {
ThreadPoolAdapterState threadPoolAdapterState = new ThreadPoolAdapterState(); ThreadPoolAdapterState threadPoolAdapterState = new ThreadPoolAdapterState();
ThreadPoolExecutor threadPoolTaskExecutor = RABBITMQ_THREAD_POOL_TASK_EXECUTOR.get(identify); ThreadPoolExecutor threadPoolTaskExecutor = rabbitmqThreadPoolTaskExecutor.get(identify);
threadPoolAdapterState.setThreadPoolKey(identify); threadPoolAdapterState.setThreadPoolKey(identify);
if (Objects.nonNull(threadPoolTaskExecutor)) { if (Objects.nonNull(threadPoolTaskExecutor)) {
threadPoolAdapterState.setCoreSize(threadPoolTaskExecutor.getCorePoolSize()); threadPoolAdapterState.setCoreSize(threadPoolTaskExecutor.getCorePoolSize());
@ -68,7 +72,7 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public List<ThreadPoolAdapterState> getThreadPoolStates() { public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>(); List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
RABBITMQ_THREAD_POOL_TASK_EXECUTOR.forEach( rabbitmqThreadPoolTaskExecutor.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key))); (key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList; return adapterStateList;
} }
@ -76,7 +80,7 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) { public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) {
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey(); String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
ThreadPoolExecutor threadPoolTaskExecutor = RABBITMQ_THREAD_POOL_TASK_EXECUTOR.get(threadPoolKey); ThreadPoolExecutor threadPoolTaskExecutor = rabbitmqThreadPoolTaskExecutor.get(threadPoolKey);
if (Objects.nonNull(threadPoolTaskExecutor)) { if (Objects.nonNull(threadPoolTaskExecutor)) {
int originalCoreSize = threadPoolTaskExecutor.getCorePoolSize(); int originalCoreSize = threadPoolTaskExecutor.getCorePoolSize();
int originalMaximumPoolSize = threadPoolTaskExecutor.getMaximumPoolSize(); int originalMaximumPoolSize = threadPoolTaskExecutor.getMaximumPoolSize();
@ -95,11 +99,11 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public void onApplicationEvent(ApplicationStartedEvent event) { public void onApplicationEvent(ApplicationStartedEvent event) {
abstractConnectionFactoryMap.forEach((beanName, abstractConnectionFactor) -> { abstractConnectionFactoryMap.forEach((beanName, abstractConnectionFactor) -> {
ExecutorService executor = (ExecutorService) ReflectUtil.getFieldValue(abstractConnectionFactor, FiledName); ExecutorService executor = (ExecutorService) ReflectUtil.getFieldValue(abstractConnectionFactor, FILED_NAME);
if (Objects.nonNull(executor)) { if (Objects.nonNull(executor)) {
if (executor instanceof ThreadPoolExecutor) { if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPoolTaskExecutor = (ThreadPoolExecutor) executor; ThreadPoolExecutor threadPoolTaskExecutor = (ThreadPoolExecutor) executor;
RABBITMQ_THREAD_POOL_TASK_EXECUTOR.put(beanName, threadPoolTaskExecutor); rabbitmqThreadPoolTaskExecutor.put(beanName, threadPoolTaskExecutor);
log.info("Rabbitmq executor name {}", beanName); log.info("Rabbitmq executor name {}", beanName);
} else { } else {
log.warn("Custom thread pools only support ThreadPoolExecutor"); log.warn("Custom thread pools only support ThreadPoolExecutor");

@ -43,7 +43,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j @Slf4j
public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> { public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, ThreadPoolExecutor> ROCKET_MQ_CONSUME_EXECUTOR = new HashMap<>(); private final Map<String, ThreadPoolExecutor> rocketmqConsumeExecutor = new HashMap<>();
@Override @Override
public String mark() { public String mark() {
@ -53,7 +53,7 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public ThreadPoolAdapterState getThreadPoolState(String identify) { public ThreadPoolAdapterState getThreadPoolState(String identify) {
ThreadPoolAdapterState result = new ThreadPoolAdapterState(); ThreadPoolAdapterState result = new ThreadPoolAdapterState();
ThreadPoolExecutor rocketMQConsumeExecutor = ROCKET_MQ_CONSUME_EXECUTOR.get(identify); ThreadPoolExecutor rocketMQConsumeExecutor = rocketmqConsumeExecutor.get(identify);
if (rocketMQConsumeExecutor != null) { if (rocketMQConsumeExecutor != null) {
result.setThreadPoolKey(identify); result.setThreadPoolKey(identify);
result.setCoreSize(rocketMQConsumeExecutor.getCorePoolSize()); result.setCoreSize(rocketMQConsumeExecutor.getCorePoolSize());
@ -67,7 +67,7 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public List<ThreadPoolAdapterState> getThreadPoolStates() { public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>(); List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
ROCKET_MQ_CONSUME_EXECUTOR.forEach( rocketmqConsumeExecutor.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key))); (key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList; return adapterStateList;
} }
@ -75,7 +75,7 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) { public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) {
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey(); String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
ThreadPoolExecutor rocketMQConsumeExecutor = ROCKET_MQ_CONSUME_EXECUTOR.get(threadPoolKey); ThreadPoolExecutor rocketMQConsumeExecutor = rocketmqConsumeExecutor.get(threadPoolKey);
if (rocketMQConsumeExecutor != null) { if (rocketMQConsumeExecutor != null) {
int originalCoreSize = rocketMQConsumeExecutor.getCorePoolSize(); int originalCoreSize = rocketMQConsumeExecutor.getCorePoolSize();
int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize(); int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize();
@ -101,7 +101,7 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
if (defaultMQPushConsumer != null) { if (defaultMQPushConsumer != null) {
ConsumeMessageService consumeMessageService = defaultMQPushConsumer.getDefaultMQPushConsumerImpl().getConsumeMessageService(); ConsumeMessageService consumeMessageService = defaultMQPushConsumer.getDefaultMQPushConsumerImpl().getConsumeMessageService();
ThreadPoolExecutor consumeExecutor = (ThreadPoolExecutor) ReflectUtil.getFieldValue(consumeMessageService, "consumeExecutor"); ThreadPoolExecutor consumeExecutor = (ThreadPoolExecutor) ReflectUtil.getFieldValue(consumeMessageService, "consumeExecutor");
ROCKET_MQ_CONSUME_EXECUTOR.put(container.getConsumerGroup(), consumeExecutor); rocketmqConsumeExecutor.put(container.getConsumerGroup(), consumeExecutor);
} }
} }
} catch (Exception ex) { } catch (Exception ex) {

@ -34,7 +34,12 @@ import org.springframework.cloud.stream.binding.InputBindingLifecycle;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter; import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER; import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
@ -44,7 +49,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j @Slf4j
public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> { public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, AbstractMessageListenerContainer> ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR = new HashMap<>(); private final Map<String, AbstractMessageListenerContainer> rocketMqSpringCloudStreamConsumeExecutor = new HashMap<>();
@Override @Override
public String mark() { public String mark() {
@ -54,7 +59,7 @@ public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAda
@Override @Override
public ThreadPoolAdapterState getThreadPoolState(String identify) { public ThreadPoolAdapterState getThreadPoolState(String identify) {
ThreadPoolAdapterState result = new ThreadPoolAdapterState(); ThreadPoolAdapterState result = new ThreadPoolAdapterState();
AbstractMessageListenerContainer messageListenerContainer = ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.get(identify); AbstractMessageListenerContainer messageListenerContainer = rocketMqSpringCloudStreamConsumeExecutor.get(identify);
if (messageListenerContainer != null) { if (messageListenerContainer != null) {
result.setThreadPoolKey(identify); result.setThreadPoolKey(identify);
if (messageListenerContainer instanceof SimpleMessageListenerContainer) { if (messageListenerContainer instanceof SimpleMessageListenerContainer) {
@ -80,7 +85,7 @@ public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAda
@Override @Override
public List<ThreadPoolAdapterState> getThreadPoolStates() { public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>(); List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.forEach( rocketMqSpringCloudStreamConsumeExecutor.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key))); (key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList; return adapterStateList;
} }
@ -88,9 +93,9 @@ public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAda
@Override @Override
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) { public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) {
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey(); String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
AbstractMessageListenerContainer messageListenerContainer = ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.get(threadPoolKey); AbstractMessageListenerContainer messageListenerContainer = rocketMqSpringCloudStreamConsumeExecutor.get(threadPoolKey);
if (messageListenerContainer != null) { if (messageListenerContainer != null) {
synchronized (ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR) { synchronized (rocketMqSpringCloudStreamConsumeExecutor) {
Integer corePoolSize = threadPoolAdapterParameter.getCorePoolSize(); Integer corePoolSize = threadPoolAdapterParameter.getCorePoolSize();
Integer maximumPoolSize = threadPoolAdapterParameter.getMaximumPoolSize(); Integer maximumPoolSize = threadPoolAdapterParameter.getMaximumPoolSize();
if (messageListenerContainer instanceof SimpleMessageListenerContainer) { if (messageListenerContainer instanceof SimpleMessageListenerContainer) {
@ -148,7 +153,7 @@ public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAda
Object lifecycle = ReflectUtil.getFieldValue(defaultBinding, "lifecycle"); Object lifecycle = ReflectUtil.getFieldValue(defaultBinding, "lifecycle");
if (lifecycle instanceof AmqpInboundChannelAdapter) { if (lifecycle instanceof AmqpInboundChannelAdapter) {
AbstractMessageListenerContainer rabbitMQListenerContainer = (AbstractMessageListenerContainer) ReflectUtil.getFieldValue(lifecycle, "messageListenerContainer"); AbstractMessageListenerContainer rabbitMQListenerContainer = (AbstractMessageListenerContainer) ReflectUtil.getFieldValue(lifecycle, "messageListenerContainer");
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.put(bindingName, rabbitMQListenerContainer); rocketMqSpringCloudStreamConsumeExecutor.put(bindingName, rabbitMQListenerContainer);
} }
} }
} catch (Exception ex) { } catch (Exception ex) {

@ -35,7 +35,12 @@ import org.springframework.cloud.stream.binder.DefaultBinding;
import org.springframework.cloud.stream.binding.InputBindingLifecycle; import org.springframework.cloud.stream.binding.InputBindingLifecycle;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER; import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
@ -46,7 +51,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j @Slf4j
public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> { public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, ThreadPoolExecutor> ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR = new HashMap<>(); private final Map<String, ThreadPoolExecutor> rocketMqSpringCloudStreamConsumeExecutor = new HashMap<>();
@Override @Override
public String mark() { public String mark() {
@ -56,7 +61,7 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda
@Override @Override
public ThreadPoolAdapterState getThreadPoolState(String identify) { public ThreadPoolAdapterState getThreadPoolState(String identify) {
ThreadPoolAdapterState result = new ThreadPoolAdapterState(); ThreadPoolAdapterState result = new ThreadPoolAdapterState();
ThreadPoolExecutor rocketMQConsumeExecutor = ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.get(identify); ThreadPoolExecutor rocketMQConsumeExecutor = rocketMqSpringCloudStreamConsumeExecutor.get(identify);
if (rocketMQConsumeExecutor != null) { if (rocketMQConsumeExecutor != null) {
result.setThreadPoolKey(identify); result.setThreadPoolKey(identify);
result.setCoreSize(rocketMQConsumeExecutor.getCorePoolSize()); result.setCoreSize(rocketMQConsumeExecutor.getCorePoolSize());
@ -70,7 +75,7 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda
@Override @Override
public List<ThreadPoolAdapterState> getThreadPoolStates() { public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>(); List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.forEach( rocketMqSpringCloudStreamConsumeExecutor.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key))); (key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList; return adapterStateList;
} }
@ -78,7 +83,7 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda
@Override @Override
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) { public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) {
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey(); String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
ThreadPoolExecutor rocketMQConsumeExecutor = ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.get(threadPoolKey); ThreadPoolExecutor rocketMQConsumeExecutor = rocketMqSpringCloudStreamConsumeExecutor.get(threadPoolKey);
if (rocketMQConsumeExecutor != null) { if (rocketMQConsumeExecutor != null) {
int originalCoreSize = rocketMQConsumeExecutor.getCorePoolSize(); int originalCoreSize = rocketMQConsumeExecutor.getCorePoolSize();
int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize(); int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize();
@ -111,7 +116,7 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda
DefaultMQPushConsumerImpl defaultMQPushConsumerImpl = consumer.getDefaultMQPushConsumerImpl(); DefaultMQPushConsumerImpl defaultMQPushConsumerImpl = consumer.getDefaultMQPushConsumerImpl();
ConsumeMessageConcurrentlyService consumeMessageService = (ConsumeMessageConcurrentlyService) defaultMQPushConsumerImpl.getConsumeMessageService(); ConsumeMessageConcurrentlyService consumeMessageService = (ConsumeMessageConcurrentlyService) defaultMQPushConsumerImpl.getConsumeMessageService();
ThreadPoolExecutor consumeExecutor = (ThreadPoolExecutor) ReflectUtil.getFieldValue(consumeMessageService, "consumeExecutor"); ThreadPoolExecutor consumeExecutor = (ThreadPoolExecutor) ReflectUtil.getFieldValue(consumeMessageService, "consumeExecutor");
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.put(bindingName, consumeExecutor); rocketMqSpringCloudStreamConsumeExecutor.put(bindingName, consumeExecutor);
} }
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to get input-bindings thread pool.", ex); log.error("Failed to get input-bindings thread pool.", ex);

@ -31,7 +31,6 @@ import org.springframework.boot.web.server.WebServer;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -47,14 +46,14 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
private final AtomicBoolean cacheFlag = new AtomicBoolean(Boolean.FALSE); private final AtomicBoolean cacheFlag = new AtomicBoolean(Boolean.FALSE);
private static String EXCEPTION_MESSAGE; private static String exceptionMessage;
private final AbstractThreadPoolRuntime webThreadPoolRunStateHandler; private final AbstractThreadPoolRuntime webThreadPoolRunStateHandler;
@Override @Override
protected Executor getWebThreadPoolByServer(WebServer webServer) { protected Executor getWebThreadPoolByServer(WebServer webServer) {
if (cacheFlag.get()) { if (cacheFlag.get()) {
log.warn("Exception getting Tomcat thread pool. Exception message: {}", EXCEPTION_MESSAGE); log.warn("Exception getting Tomcat thread pool. Exception message: {}", exceptionMessage);
return null; return null;
} }
Executor tomcatExecutor = null; Executor tomcatExecutor = null;
@ -62,8 +61,8 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
tomcatExecutor = ((TomcatWebServer) webServer).getTomcat().getConnector().getProtocolHandler().getExecutor(); tomcatExecutor = ((TomcatWebServer) webServer).getTomcat().getConnector().getProtocolHandler().getExecutor();
} catch (Exception ex) { } catch (Exception ex) {
cacheFlag.set(Boolean.TRUE); cacheFlag.set(Boolean.TRUE);
EXCEPTION_MESSAGE = ex.getMessage(); exceptionMessage = ex.getMessage();
log.error("Failed to get Tomcat thread pool. Message: {}", EXCEPTION_MESSAGE); log.error("Failed to get Tomcat thread pool. Message: {}", exceptionMessage);
} }
return tomcatExecutor; return tomcatExecutor;
} }

@ -35,12 +35,12 @@ import java.util.concurrent.atomic.AtomicReference;
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE) @NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public class WebIpAndPortHolder { public class WebIpAndPortHolder {
private static boolean SUPPORT_VERSION = false; private static boolean supportVersion = false;
static { static {
try { try {
Class.forName("org.springframework.boot.web.server.WebServer"); Class.forName("org.springframework.boot.web.server.WebServer");
SUPPORT_VERSION = true; supportVersion = true;
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
@ -48,17 +48,17 @@ public class WebIpAndPortHolder {
/** /**
* Application ip and application post * Application ip and application post
*/ */
protected static AtomicReference<WebIpAndPortInfo> WEB_IP_AND_PORT = new AtomicReference<>(); protected static AtomicReference<WebIpAndPortInfo> webIpAndPort = new AtomicReference<>();
public static final String ALL = "*"; public static final String ALL = "*";
protected static final String SEPARATOR = ","; protected static final String SEPARATOR = ",";
protected static void initIpAndPort() { protected static void initIpAndPort() {
if (!SUPPORT_VERSION) { if (!supportVersion) {
return; return;
} }
WEB_IP_AND_PORT.compareAndSet(null, getWebIpAndPortInfo()); webIpAndPort.compareAndSet(null, getWebIpAndPortInfo());
} }
private static WebIpAndPortInfo getWebIpAndPortInfo() { private static WebIpAndPortInfo getWebIpAndPortInfo() {
@ -80,10 +80,10 @@ public class WebIpAndPortHolder {
* @return Web ip and port info * @return Web ip and port info
*/ */
public static WebIpAndPortInfo getWebIpAndPort() { public static WebIpAndPortInfo getWebIpAndPort() {
if (WEB_IP_AND_PORT.get() == null) { if (webIpAndPort.get() == null) {
initIpAndPort(); initIpAndPort();
} }
return WebIpAndPortHolder.WEB_IP_AND_PORT.get(); return WebIpAndPortHolder.webIpAndPort.get();
} }
/** /**

Loading…
Cancel
Save