feat: 功能持续更新.

pull/161/head
chen.ma 3 years ago
parent da0c9318c9
commit 60daa594e3

@ -6,7 +6,7 @@
<parent>
<groupId>io.dynamic-threadpool</groupId>
<artifactId>parent</artifactId>
<version>${revision}</version>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>common</artifactId>

@ -6,7 +6,7 @@
<parent>
<groupId>io.dynamic-threadpool</groupId>
<artifactId>parent</artifactId>
<version>${revision}</version>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>dynamic-threadpool-spring-boot-starter</artifactId>
@ -44,5 +44,11 @@
<groupId>io.dynamic-threadpool</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

@ -13,10 +13,9 @@ public class ConfigAdapter {
/**
* 线
*
* @param tpId
* @param config
*/
public void callbackConfig(String tpId, String config) {
ThreadPoolDynamicRefresh.refreshDynamicPool(tpId, config);
public void callbackConfig(String config) {
ThreadPoolDynamicRefresh.refreshDynamicPool(config);
}
}

@ -31,7 +31,7 @@ public class ThreadPoolConfigAdapter extends ConfigAdapter {
new ThreadPoolExecutor.DiscardOldestPolicy());
public void subscribeConfig(List<String> tpIds) {
tpIds.forEach(each -> threadPoolOperation.subscribeConfig(each, executorService, (tpId, config) -> callbackConfig(tpId, config)));
tpIds.forEach(each -> threadPoolOperation.subscribeConfig(each, executorService, config -> callbackConfig(config)));
}
}

@ -29,12 +29,12 @@ public class DynamicThreadPoolAutoConfiguration {
@Bean
public ConfigService configService() {
return new ThreadPoolConfigService();
return new ThreadPoolConfigService(properties);
}
@Bean
public ThreadPoolRunListener threadPoolRunListener() {
return new ThreadPoolRunListener();
return new ThreadPoolRunListener(properties);
}
@Bean

@ -17,7 +17,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = DynamicThreadPoolProperties.PREFIX)
public class DynamicThreadPoolProperties {
public static final String PREFIX = "spring.threadpool.dynamic";
public static final String PREFIX = "spring.dynamic.thread-pool";
/**
*
*/
private String serverAddr;
/**
*

@ -1,5 +1,8 @@
package io.dynamic.threadpool.starter.core;
import io.dynamic.threadpool.starter.config.DynamicThreadPoolProperties;
import io.dynamic.threadpool.starter.http.HttpAgent;
import io.dynamic.threadpool.starter.http.ServerHttpAgent;
import io.dynamic.threadpool.starter.listener.ClientWorker;
import io.dynamic.threadpool.starter.listener.Listener;
@ -13,10 +16,13 @@ import java.util.Arrays;
*/
public class ThreadPoolConfigService implements ConfigService {
private final HttpAgent httpAgent;
private final ClientWorker clientWorker;
public ThreadPoolConfigService() {
clientWorker = new ClientWorker();
public ThreadPoolConfigService(DynamicThreadPoolProperties properties) {
httpAgent = new ServerHttpAgent(properties);
clientWorker = new ClientWorker(httpAgent);
}
@Override

@ -15,9 +15,9 @@ import java.util.concurrent.TimeUnit;
*/
public class ThreadPoolDynamicRefresh {
public static void refreshDynamicPool(String tpId, String content) {
public static void refreshDynamicPool(String content) {
PoolParameterInfo parameter = JSON.parseObject(content, PoolParameterInfo.class);
refreshDynamicPool(tpId, parameter.getCoreSize(), parameter.getMaxSize(), parameter.getCapacity(), parameter.getKeepAliveTime());
refreshDynamicPool(parameter.getTpId(), parameter.getCoreSize(), parameter.getMaxSize(), parameter.getCapacity(), parameter.getKeepAliveTime());
}
public static void refreshDynamicPool(String threadPoolId, Integer coreSize, Integer maxSize, Integer capacity, Integer keepAliveTime) {

@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
@ -29,8 +28,11 @@ public class ThreadPoolRunListener implements ApplicationRunner {
@Autowired
private HttpClientUtil httpClientUtil;
@Resource
private DynamicThreadPoolProperties dynamicThreadPoolProperties;
private final DynamicThreadPoolProperties dynamicThreadPoolProperties;
public ThreadPoolRunListener(DynamicThreadPoolProperties properties) {
this.dynamicThreadPoolProperties = properties;
}
@Override
public void run(ApplicationArguments args) throws Exception {

@ -0,0 +1,70 @@
package io.dynamic.threadpool.starter.http;
import java.util.Map;
/**
* Http Agent.
*
* @author chen.ma
* @date 2021/6/23 20:45
*/
public interface HttpAgent {
/**
* NacosIp
*/
void start();
/**
*
*
* @return
*/
String getNameSpace();
/**
*
*
* @return
*/
String getEncode();
/**
* Http Get
*
* @param path
* @param headers
* @param paramValues
* @param encoding
* @param readTimeoutMs
* @return
*/
String httpGet(String path, Map<String, String> headers, Map<String, String> paramValues,
String encoding, long readTimeoutMs);
/**
* Http Post
*
* @param path
* @param headers
* @param paramValues
* @param encoding
* @param readTimeoutMs
* @return
*/
String httpPost(String path, Map<String, String> headers, Map<String, String> paramValues,
String encoding, long readTimeoutMs);
/**
* Http Delete
*
* @param path
* @param headers
* @param paramValues
* @param encoding
* @param readTimeoutMs
* @return
*/
String httpDelete(String path, Map<String, String> headers, Map<String, String> paramValues,
String encoding, long readTimeoutMs);
}

@ -0,0 +1,50 @@
package io.dynamic.threadpool.starter.http;
import io.dynamic.threadpool.starter.config.DynamicThreadPoolProperties;
import java.util.Map;
/**
* Server Http Agent.
*
* @author chen.ma
* @date 2021/6/23 20:50
*/
public class ServerHttpAgent implements HttpAgent {
private final DynamicThreadPoolProperties dynamicThreadPoolProperties;
public ServerHttpAgent(DynamicThreadPoolProperties properties) {
this.dynamicThreadPoolProperties = properties;
}
@Override
public void start() {
}
@Override
public String httpGet(String path, Map<String, String> headers, Map<String, String> paramValues, String encoding, long readTimeoutMs) {
return null;
}
@Override
public String httpPost(String path, Map<String, String> headers, Map<String, String> paramValues, String encoding, long readTimeoutMs) {
return null;
}
@Override
public String httpDelete(String path, Map<String, String> headers, Map<String, String> paramValues, String encoding, long readTimeoutMs) {
return null;
}
@Override
public String getNameSpace() {
return null;
}
@Override
public String getEncode() {
return null;
}
}

@ -0,0 +1,13 @@
package io.dynamic.threadpool.starter.http;
import lombok.extern.slf4j.Slf4j;
/**
* Server List Manager.
*
* @author chen.ma
* @date 2021/6/23 20:42
*/
@Slf4j
public class ServerListManager {
}

@ -1,6 +1,7 @@
package io.dynamic.threadpool.starter.listener;
import io.dynamic.threadpool.starter.core.CacheData;
import io.dynamic.threadpool.starter.http.HttpAgent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
@ -22,6 +23,8 @@ public class ClientWorker {
private double currentLongingTaskCount = 0;
private final HttpAgent agent;
private final ScheduledExecutorService executor;
private final ScheduledExecutorService executorService;
@ -29,7 +32,9 @@ public class ClientWorker {
private final ConcurrentHashMap<String, CacheData> cacheMap = new ConcurrentHashMap(16);
@SuppressWarnings("all")
public ClientWorker() {
public ClientWorker(HttpAgent httpAgent) {
this.agent = httpAgent;
this.executor = Executors.newScheduledThreadPool(1, r -> {
Thread t = new Thread(r);
t.setName("io.dynamic.threadPool.client.Worker.executor");
@ -111,7 +116,6 @@ public class ClientWorker {
for (CacheData each : cacheDataList) {
each.checkListenerMd5();
}
}
}

@ -21,7 +21,7 @@ public class ThreadPoolOperation {
Listener configListener = new Listener() {
@Override
public void receiveConfigInfo(String config) {
threadPoolSubscribeCallback.callback(tpId, config);
threadPoolSubscribeCallback.callback(config);
}
@Override

@ -11,8 +11,7 @@ public interface ThreadPoolSubscribeCallback {
/**
*
*
* @param tpId
* @param config
*/
void callback(String tpId, String config);
void callback(String config);
}

@ -0,0 +1,27 @@
{
"properties": [
{
"name": "spring.dynamic.thread-pool.server-addr",
"type": "java.lang.String",
"defaultValue": "localhost:6691",
"description": "dynamic thread-pool server address."
},
{
"name": "spring.dynamic.thread-pool.enabled",
"type": "java.lang.Boolean",
"defaultValue": false,
"description": "dynamic thread-pool enabled."
},
{
"name": "spring.dynamic.thread-pool.namespace",
"type": "java.lang.String",
"defaultValue": "public",
"description": "dynamic thread-pool namespace."
},
{
"name": "spring.dynamic.thread-pool.item-id",
"type": "java.lang.String",
"description": "dynamic thread-pool item-id."
}
]
}

@ -6,7 +6,7 @@
<parent>
<groupId>io.dynamic-threadpool</groupId>
<artifactId>parent</artifactId>
<version>${revision}</version>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>dynamic-threadpool-example</artifactId>
@ -39,7 +39,7 @@
<dependency>
<groupId>io.dynamic-threadpool</groupId>
<artifactId>dynamic-threadpool-spring-boot-starter</artifactId>
<version>${revision}</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

@ -1,5 +1,7 @@
spring:
threadpool:
dynamic:
namespace: common
itemId: message-center
dynamic:
thread-pool:
enabled: true
server-addr: localhost:6691
namespace: public
item-id: message-center

@ -5,11 +5,11 @@
<groupId>io.dynamic-threadpool</groupId>
<artifactId>parent</artifactId>
<version>${revision}</version>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>动态线程池,附带监控报警功能</description>
<description>🔥 强大的动态线程池,附带监控报警功能</description>
<properties>
<java.version>1.8</java.version>
@ -24,6 +24,7 @@
</properties>
<modules>
<module>common</module>
<module>server</module>
<module>example</module>
<module>dynamic-threadpool-spring-boot-starter</module>
@ -67,7 +68,7 @@
<dependency>
<groupId>io.dynamic-threadpool</groupId>
<artifactId>common</artifactId>
<version>${revision}</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
@ -80,6 +81,19 @@
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>release_user</id>
<name>Release Deploy</name>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshot_user</id>
<name>Snapshot Deploy</name>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
@ -87,6 +101,32 @@
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>

@ -6,7 +6,7 @@
<parent>
<groupId>io.dynamic-threadpool</groupId>
<artifactId>parent</artifactId>
<version>${revision}</version>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>dynamic-threadpool-server</artifactId>

Loading…
Cancel
Save