feat: 功能持续更新.

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

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

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

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

@ -31,7 +31,7 @@ public class ThreadPoolConfigAdapter extends ConfigAdapter {
new ThreadPoolExecutor.DiscardOldestPolicy()); new ThreadPoolExecutor.DiscardOldestPolicy());
public void subscribeConfig(List<String> tpIds) { 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 @Bean
public ConfigService configService() { public ConfigService configService() {
return new ThreadPoolConfigService(); return new ThreadPoolConfigService(properties);
} }
@Bean @Bean
public ThreadPoolRunListener threadPoolRunListener() { public ThreadPoolRunListener threadPoolRunListener() {
return new ThreadPoolRunListener(); return new ThreadPoolRunListener(properties);
} }
@Bean @Bean

@ -17,7 +17,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = DynamicThreadPoolProperties.PREFIX) @ConfigurationProperties(prefix = DynamicThreadPoolProperties.PREFIX)
public class DynamicThreadPoolProperties { 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; 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.ClientWorker;
import io.dynamic.threadpool.starter.listener.Listener; import io.dynamic.threadpool.starter.listener.Listener;
@ -13,10 +16,13 @@ import java.util.Arrays;
*/ */
public class ThreadPoolConfigService implements ConfigService { public class ThreadPoolConfigService implements ConfigService {
private final HttpAgent httpAgent;
private final ClientWorker clientWorker; private final ClientWorker clientWorker;
public ThreadPoolConfigService() { public ThreadPoolConfigService(DynamicThreadPoolProperties properties) {
clientWorker = new ClientWorker(); httpAgent = new ServerHttpAgent(properties);
clientWorker = new ClientWorker(httpAgent);
} }
@Override @Override

@ -15,9 +15,9 @@ import java.util.concurrent.TimeUnit;
*/ */
public class ThreadPoolDynamicRefresh { public class ThreadPoolDynamicRefresh {
public static void refreshDynamicPool(String tpId, String content) { public static void refreshDynamicPool(String content) {
PoolParameterInfo parameter = JSON.parseObject(content, PoolParameterInfo.class); 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) { 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.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
@ -29,8 +28,11 @@ public class ThreadPoolRunListener implements ApplicationRunner {
@Autowired @Autowired
private HttpClientUtil httpClientUtil; private HttpClientUtil httpClientUtil;
@Resource private final DynamicThreadPoolProperties dynamicThreadPoolProperties;
private DynamicThreadPoolProperties dynamicThreadPoolProperties;
public ThreadPoolRunListener(DynamicThreadPoolProperties properties) {
this.dynamicThreadPoolProperties = properties;
}
@Override @Override
public void run(ApplicationArguments args) throws Exception { 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; package io.dynamic.threadpool.starter.listener;
import io.dynamic.threadpool.starter.core.CacheData; import io.dynamic.threadpool.starter.core.CacheData;
import io.dynamic.threadpool.starter.http.HttpAgent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -22,6 +23,8 @@ public class ClientWorker {
private double currentLongingTaskCount = 0; private double currentLongingTaskCount = 0;
private final HttpAgent agent;
private final ScheduledExecutorService executor; private final ScheduledExecutorService executor;
private final ScheduledExecutorService executorService; private final ScheduledExecutorService executorService;
@ -29,7 +32,9 @@ public class ClientWorker {
private final ConcurrentHashMap<String, CacheData> cacheMap = new ConcurrentHashMap(16); private final ConcurrentHashMap<String, CacheData> cacheMap = new ConcurrentHashMap(16);
@SuppressWarnings("all") @SuppressWarnings("all")
public ClientWorker() { public ClientWorker(HttpAgent httpAgent) {
this.agent = httpAgent;
this.executor = Executors.newScheduledThreadPool(1, r -> { this.executor = Executors.newScheduledThreadPool(1, r -> {
Thread t = new Thread(r); Thread t = new Thread(r);
t.setName("io.dynamic.threadPool.client.Worker.executor"); t.setName("io.dynamic.threadPool.client.Worker.executor");
@ -111,7 +116,6 @@ public class ClientWorker {
for (CacheData each : cacheDataList) { for (CacheData each : cacheDataList) {
each.checkListenerMd5(); each.checkListenerMd5();
} }
} }
} }

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

@ -11,8 +11,7 @@ public interface ThreadPoolSubscribeCallback {
/** /**
* *
* *
* @param tpId
* @param config * @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> <parent>
<groupId>io.dynamic-threadpool</groupId> <groupId>io.dynamic-threadpool</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<version>${revision}</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>dynamic-threadpool-example</artifactId> <artifactId>dynamic-threadpool-example</artifactId>
@ -39,7 +39,7 @@
<dependency> <dependency>
<groupId>io.dynamic-threadpool</groupId> <groupId>io.dynamic-threadpool</groupId>
<artifactId>dynamic-threadpool-spring-boot-starter</artifactId> <artifactId>dynamic-threadpool-spring-boot-starter</artifactId>
<version>${revision}</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

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

@ -5,11 +5,11 @@
<groupId>io.dynamic-threadpool</groupId> <groupId>io.dynamic-threadpool</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<version>${revision}</version> <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
<description>动态线程池,附带监控报警功能</description> <description>🔥 强大的动态线程池,附带监控报警功能</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
@ -24,6 +24,7 @@
</properties> </properties>
<modules> <modules>
<module>common</module>
<module>server</module> <module>server</module>
<module>example</module> <module>example</module>
<module>dynamic-threadpool-spring-boot-starter</module> <module>dynamic-threadpool-spring-boot-starter</module>
@ -67,7 +68,7 @@
<dependency> <dependency>
<groupId>io.dynamic-threadpool</groupId> <groupId>io.dynamic-threadpool</groupId>
<artifactId>common</artifactId> <artifactId>common</artifactId>
<version>${revision}</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -80,6 +81,19 @@
</dependency> </dependency>
</dependencies> </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> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -87,6 +101,32 @@
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </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> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>

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

Loading…
Cancel
Save