-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Alibaba Dubbo Thread Pool support. (#531)
- Loading branch information
Showing
7 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?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-adapter</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>hippo4j-adapter-alibaba-dubbo</artifactId> | ||
<version>1.4.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<dubbo.version>3.0.5</dubbo.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>cn.hippo4j</groupId> | ||
<artifactId>hippo4j-adapter-base</artifactId> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/com.alibaba/dubbo --> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>dubbo</artifactId> | ||
<version>2.6.12</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Implementation-Title>${project.artifactId}</Implementation-Title> | ||
<Implementation-Version>${project.version}</Implementation-Version> | ||
<Build-Time>${maven.build.timestamp}</Build-Time> | ||
<Built-By>chen.ma</Built-By> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.10.3</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
102 changes: 102 additions & 0 deletions
102
...a-dubbo/src/main/java/cn/hippo4j/adapter/alibaba/dubbo/AlibabaDubboThreadPoolAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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.adapter.alibaba.dubbo; | ||
|
||
import cn.hippo4j.adapter.base.ThreadPoolAdapter; | ||
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; | ||
import cn.hippo4j.adapter.base.ThreadPoolAdapterState; | ||
import com.alibaba.dubbo.common.extension.ExtensionLoader; | ||
import com.alibaba.dubbo.common.store.DataStore; | ||
import com.google.common.collect.Maps; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.event.ApplicationStartedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER; | ||
|
||
/** | ||
* Alibaba Dubbo thread-pool adapter. | ||
*/ | ||
@Slf4j | ||
public class AlibabaDubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> { | ||
|
||
private final Map<String, ThreadPoolExecutor> DUBBO_PROTOCOL_EXECUTOR = Maps.newHashMap(); | ||
|
||
@Override | ||
public String mark() { | ||
return "Dubbo"; | ||
} | ||
|
||
@Override | ||
public ThreadPoolAdapterState getThreadPoolState(String identify) { | ||
ThreadPoolAdapterState threadPoolAdapterState = new ThreadPoolAdapterState(); | ||
ThreadPoolExecutor executor = DUBBO_PROTOCOL_EXECUTOR.get(identify); | ||
if (executor == null) { | ||
log.warn("[{}] Alibaba Dubbo consuming thread pool not found.", identify); | ||
return threadPoolAdapterState; | ||
} | ||
threadPoolAdapterState.setThreadPoolKey(identify); | ||
threadPoolAdapterState.setCoreSize(executor.getCorePoolSize()); | ||
threadPoolAdapterState.setMaximumSize(executor.getMaximumPoolSize()); | ||
return threadPoolAdapterState; | ||
} | ||
|
||
@Override | ||
public List<ThreadPoolAdapterState> getThreadPoolStates() { | ||
List<ThreadPoolAdapterState> threadPoolAdapterStates = new ArrayList<>(); | ||
DUBBO_PROTOCOL_EXECUTOR.forEach((kel, val) -> threadPoolAdapterStates.add(getThreadPoolState(String.valueOf(val)))); | ||
return threadPoolAdapterStates; | ||
} | ||
|
||
@Override | ||
public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) { | ||
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey(); | ||
ThreadPoolExecutor executor = DUBBO_PROTOCOL_EXECUTOR.get(threadPoolAdapterParameter.getThreadPoolKey()); | ||
if (executor == null) { | ||
log.warn("[{}] Alibaba Dubbo consuming thread pool not found.", threadPoolKey); | ||
return false; | ||
} | ||
int originalCoreSize = executor.getCorePoolSize(); | ||
int originalMaximumPoolSize = executor.getMaximumPoolSize(); | ||
executor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize()); | ||
executor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize()); | ||
log.info("[{}] Alibaba Dubbo consumption thread pool parameter change. coreSize: {}, maximumSize: {}", | ||
threadPoolKey, | ||
String.format(CHANGE_DELIMITER, originalCoreSize, executor.getCorePoolSize()), | ||
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, executor.getMaximumPoolSize())); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationStartedEvent event) { | ||
String poolKey = ExecutorService.class.getName(); | ||
try { | ||
DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension(); | ||
Map<String, Object> executors = dataStore.get(poolKey); | ||
executors.forEach((key, value) -> DUBBO_PROTOCOL_EXECUTOR.put(key, (ThreadPoolExecutor) value)); | ||
} catch (Exception ex) { | ||
log.error("Failed to get Alibaba Dubbo protocol thread pool", ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...o4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-alibaba-dubbo/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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-spring-boot-starter-adapter</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>hippo4j-spring-boot-starter-adapter-alibaba-dubbo</artifactId> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>cn.hippo4j</groupId> | ||
<artifactId>hippo4j-adapter-alibaba-dubbo</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Implementation-Title>${project.artifactId}</Implementation-Title> | ||
<Implementation-Version>${project.version}</Implementation-Version> | ||
<Build-Time>${maven.build.timestamp}</Build-Time> | ||
<Built-By>chen.ma</Built-By> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.10.3</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
...ippo4j/springboot/starter/adapter/alibaba/dubbo/AlibabaDubboAdapterAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.springboot.starter.adapter.alibaba.dubbo; | ||
|
||
import cn.hippo4j.adapter.alibaba.dubbo.AlibabaDubboThreadPoolAdapter; | ||
import cn.hippo4j.common.config.ApplicationContextHolder; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Alibaba Dubbo adapter auto configuration. | ||
*/ | ||
@Configuration | ||
public class AlibabaDubboAdapterAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public ApplicationContextHolder simpleApplicationContextHolder () { | ||
return new ApplicationContextHolder(); | ||
} | ||
|
||
@Bean | ||
@SuppressWarnings("all") | ||
@ConditionalOnProperty(name = "dubbo.application.name") | ||
public AlibabaDubboThreadPoolAdapter dubboThreadPoolAdapter (ApplicationContextHolder applicationContextHolder) { | ||
return new AlibabaDubboThreadPoolAdapter(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...4j-spring-boot-starter-adapter-alibaba-dubbo/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.springboot.starter.adapter.alibaba.dubbo.AlibabaDubboAdapterAutoConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters