Merge branch 'opengoofy:develop' into develop

pull/1363/head
时间邮递员 2 years ago committed by GitHub
commit 7e1a2a6cb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,29 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hippo4j-agent-adapter-plugins</artifactId>
<groupId>cn.hippo4j</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

@ -0,0 +1,87 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.agent.adapter.dubbo;
import cn.hippo4j.common.executor.ThreadPoolRegistry;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.model.executor.ExecutorProperties;
import cn.hippo4j.common.toolkit.BooleanUtil;
import cn.hippo4j.common.toolkit.ReflectUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.store.DataStore;
import org.apache.dubbo.common.threadpool.manager.ExecutorRepository;
/**
* Dubbo thread-pool adapter.
*/
public class DubboThreadPoolAdapter {
public static void registerExecutors() {
boolean isLegacyVersion = true;
String poolKey = ExecutorService.class.getName();
// Since 2.7.5, Dubbo has changed the way thread pools are used
// fixed https://github.com/opengoofy/hippo4j/issues/708
try {
if (Version.getIntVersion(Version.getVersion()) < 2070500) {
isLegacyVersion = false;
}
} catch (Exception ex) {
}
try {
if (isLegacyVersion) {
DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
Map<String, Object> executors = dataStore.get(poolKey);
executors.forEach((key, value) -> putHolder(mark() + key, (ThreadPoolExecutor) value));
return;
}
ExecutorRepository executorRepository = ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension();
ConcurrentMap<String, ConcurrentMap<Integer, ExecutorService>> data =
(ConcurrentMap<String, ConcurrentMap<Integer, ExecutorService>>) ReflectUtil.getFieldValue(executorRepository, "data");
ConcurrentMap<Integer, ExecutorService> executorServiceMap = data.get(poolKey);
executorServiceMap.forEach((key, value) -> putHolder(mark() + key, (ThreadPoolExecutor) value));
} catch (Exception ex) {
}
}
private static void putHolder(String executorName, ThreadPoolExecutor executor) {
if (executor == null) {
return;
}
ExecutorProperties executorProperties = ExecutorProperties.builder()
.threadPoolId(executorName)
.corePoolSize(executor.getCorePoolSize())
.maximumPoolSize(executor.getMaximumPoolSize())
.allowCoreThreadTimeOut(BooleanUtil.toBoolean(String.valueOf(executor.allowsCoreThreadTimeOut())))
.blockingQueue(BlockingQueueTypeEnum.getBlockingQueueTypeEnumByName(executor.getQueue().getClass().getSimpleName()).getName())
.queueCapacity(executor.getQueue().remainingCapacity())
.rejectedHandler(RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(executor.getRejectedExecutionHandler().getClass().getSimpleName()).getName())
.build();
ThreadPoolRegistry.putHolder(executorName, executor, executorProperties);
}
public static String mark() {
return "Dubbo";
}
}

@ -10,6 +10,7 @@
</parent> </parent>
<artifactId>hippo4j-agent-adapter-plugins</artifactId> <artifactId>hippo4j-agent-adapter-plugins</artifactId>
<packaging>pom</packaging>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
@ -17,4 +18,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<modules>
<module>dubbo-plugin</module>
</modules>
</project> </project>

@ -49,6 +49,12 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>dubbo-plugin</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -17,6 +17,7 @@
package cn.hippo4j.agent.plugin.spring.boot.v1.interceptor; package cn.hippo4j.agent.plugin.spring.boot.v1.interceptor;
import cn.hippo4j.agent.adapter.dubbo.DubboThreadPoolAdapter;
import cn.hippo4j.agent.core.logging.api.ILog; import cn.hippo4j.agent.core.logging.api.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;
@ -56,6 +57,7 @@ public class EventPublishingFinishedInterceptor implements InstanceMethodsAround
SpringPropertiesLoader.loadSpringProperties(context.getEnvironment()); SpringPropertiesLoader.loadSpringProperties(context.getEnvironment());
ThreadPoolDynamicRefresh dynamicRefreshSpring1x = new DynamicThreadPoolChangeHandlerSpring1x(context); ThreadPoolDynamicRefresh dynamicRefreshSpring1x = new DynamicThreadPoolChangeHandlerSpring1x(context);
dynamicRefreshSpring1x.registerListener(); dynamicRefreshSpring1x.registerListener();
DubboThreadPoolAdapter.registerExecutors();
return ret; return ret;
} }

@ -154,6 +154,11 @@
<version>${jmh.version}</version> <version>${jmh.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>dubbo-plugin</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

@ -5,7 +5,7 @@ title: 采用公司
## 谁在使用 Hippo4j ## 谁在使用 Hippo4j
共计 38+ 家公司生产接入 Hippo4j按照公司登记时间排序。 共计 39+ 家公司生产接入 Hippo4j按照公司登记时间排序。
- [身边云](https://serviceshare.com) - [身边云](https://serviceshare.com)
- [思派健康科技](https://www.medbanks.cn) - [思派健康科技](https://www.medbanks.cn)
@ -45,6 +45,7 @@ title: 采用公司
- [神州数码(西安)](https://www.digitalchina.com) - [神州数码(西安)](https://www.digitalchina.com)
- [广联达科技股份有限公司](https://www.glodon.com) - [广联达科技股份有限公司](https://www.glodon.com)
- [天健联创控股集团有限公司](https://www.tjlc.com.cn) - [天健联创控股集团有限公司](https://www.tjlc.com.cn)
- [知乎](https://www.zhihu.com/)
## 登记 ## 登记

@ -5,7 +5,7 @@ title: 采用公司
## 谁在使用 Hippo4j ## 谁在使用 Hippo4j
共计 38+ 家公司生产接入 Hippo4j按照公司登记时间排序。 共计 39+ 家公司生产接入 Hippo4j按照公司登记时间排序。
- [身边云](https://serviceshare.com) - [身边云](https://serviceshare.com)
- [思派健康科技](https://www.medbanks.cn) - [思派健康科技](https://www.medbanks.cn)
@ -45,6 +45,7 @@ title: 采用公司
- [神州数码(西安)](https://www.digitalchina.com) - [神州数码(西安)](https://www.digitalchina.com)
- [广联达科技股份有限公司](https://www.glodon.com) - [广联达科技股份有限公司](https://www.glodon.com)
- [天健联创控股集团有限公司](https://www.tjlc.com.cn) - [天健联创控股集团有限公司](https://www.tjlc.com.cn)
- [知乎](https://www.zhihu.com/)
## 登记 ## 登记

@ -31,6 +31,10 @@ import lombok.SneakyThrows;
*/ */
public class MessageConvert { public class MessageConvert {
private MessageConvert(){
}
/** /**
* {@link Message} to {@link MessageWrapper}. * {@link Message} to {@link MessageWrapper}.
* *

@ -0,0 +1,110 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.monitor.*;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/***
* @description : Todo
* @author : DDDreame
* @date : 2023/5/27 23:24
*/
public class MessageConvertTest {
@Test
public void testConvert() {
AbstractMessage message = new RuntimeMessage();
List<Message> runtimeMessages = new ArrayList<>();
ThreadPoolRunStateInfo poolRunState = ThreadPoolRunStateInfo.builder()
.tpId("testTPid")
.activeSize(4)
.poolSize(12)
.completedTaskCount(8L)
.largestPoolSize(12)
.currentLoad("6")
.clientLastRefreshTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.peakLoad("20")
.queueSize(0)
.queueRemainingCapacity(512)
.rejectCount(0L)
.timestamp(System.currentTimeMillis())
.build();
RuntimeMessage runtimeMessage = BeanUtil.convert(poolRunState, RuntimeMessage.class);
runtimeMessage.setGroupKey("test-groupKeys");
runtimeMessages.add(runtimeMessage);
message.setMessageType(MessageTypeEnum.RUNTIME);
message.setMessages(runtimeMessages);
MessageWrapper messageWrapper = MessageConvert.convert(message);
Assertions.assertNotNull(messageWrapper);
}
@Test
public void testMessageWrapperConvert() {
AbstractMessage message = new RuntimeMessage();
List<Message> runtimeMessages = new ArrayList<>();
ThreadPoolRunStateInfo poolRunState = ThreadPoolRunStateInfo.builder()
.tpId("testTPid")
.activeSize(4)
.poolSize(12)
.completedTaskCount(8L)
.largestPoolSize(12)
.currentLoad("6")
.clientLastRefreshTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.peakLoad("20")
.queueSize(0)
.queueRemainingCapacity(512)
.rejectCount(0L)
.timestamp(System.currentTimeMillis())
.build();
RuntimeMessage runtimeMessage = BeanUtil.convert(poolRunState, RuntimeMessage.class);
runtimeMessage.setGroupKey("test-groupKeys");
runtimeMessages.add(runtimeMessage);
message.setMessageType(MessageTypeEnum.RUNTIME);
message.setMessages(runtimeMessages);
MessageWrapper messageWrapper = MessageConvert.convert(message);
Message messageResult = MessageConvert.convert(messageWrapper);
Assertions.assertNotNull(messageResult);
Assertions.assertEquals(message, messageResult);
}
@Test
public void testMessageWrapperConvertException() {
Assertions.assertThrows(Exception.class, ()->{
Map<String, Object> data1 = new HashMap<>();
data1.put("key1", "value1");
data1.put("key2", 123);
Map<String, Object> data2 = new HashMap<>();
data2.put("key3", true);
data2.put("key4", 3.14);
List<Map<String, Object>> contentParams = Arrays.asList(data1, data2);
Class responseClass = String.class;
MessageTypeEnum messageType = MessageTypeEnum.DEFAULT;
MessageWrapper messageWrapper = new MessageWrapper(contentParams, responseClass, messageType);
MessageConvert.convert(messageWrapper);
});
}
}
Loading…
Cancel
Save