mirror of https://github.com/longtai-cn/hippo4j
prototype version of dubbo threadpool agent. (#1357)
* prototype version of dubbo threadpool agent. * rename to optimze & fix ci errors. * rename to optimze & fix ci errors.pull/1359/head
parent
5e2e3a3be3
commit
08cc67c07e
@ -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";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue