-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicThreadPoolController.java
More file actions
79 lines (71 loc) · 2.78 KB
/
Copy pathDynamicThreadPoolController.java
File metadata and controls
79 lines (71 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.yw.dynamicthreadpooladmin.trigger;
import com.alibaba.nacos.api.exception.NacosException;
import com.yw.dynamicthreadpooladmin.register.IRegister;
import com.yw.dynamicthreadpooladmin.types.Response;
import com.yw.sdk.domain.model.entity.ThreadPoolConfigEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 动态线程池控制器
*
* @author: yuanwen
* @since: 2024/9/22
*/
@RestController
@CrossOrigin("*")
@RequestMapping("/api/v1/dynamic/thread/pool/")
@Slf4j
public class DynamicThreadPoolController {
@Resource
private IRegister register;
/**
* 查询线程池数据
* curl --request GET \
* --url 'http://localhost:8089/api/v1/dynamic/thread/pool/query_thread_pool_list'
*/
@RequestMapping(value = "query_thread_pool_list", method = RequestMethod.GET)
public Response<List<ThreadPoolConfigEntity>> queryThreadPoolList() throws NacosException {
try {
List<ThreadPoolConfigEntity> threadPoolConfigEntityList = register.queryThreadPoolList();
return Response.success(threadPoolConfigEntityList);
} catch (Exception e) {
return Response.error(Response.CodeEnum.ERROR);
}
}
/**
* 查询线程池配置
* curl --request GET \
* --url 'http://localhost:8089/api/v1/dynamic/thread/pool/query_thread_pool_config?appName=dynamic-thread-pool-test-app&threadPoolName=threadPoolExecutor'
*/
@RequestMapping(value = "query_thread_pool_config", method = RequestMethod.GET)
public Response<ThreadPoolConfigEntity> queryThreadPoolConfig(@RequestParam String appName, @RequestParam String threadPoolName) {
try {
ThreadPoolConfigEntity threadPoolConfigEntity = register.queryThreadPoolConfig(appName, threadPoolName);
return Response.success(threadPoolConfigEntity);
} catch (Exception e) {
return Response.error(Response.CodeEnum.ERROR);
}
}
/**
* 修改线程池配置
* curl --request POST \
* --url http://localhost:8089/api/v1/dynamic/thread/pool/update_thread_pool_config \
* --header 'content-type: application/json' \
* --data '{
* "appName":"dynamic-thread-pool-test-app",
* "threadPoolName": "threadPoolExecutor",
* "corePoolSize": 1,
* "maximumPoolSize": 10
* }'
*/
@RequestMapping(value = "update_thread_pool_config", method = RequestMethod.POST)
public Response<Boolean> updateThreadPoolConfig(@RequestBody ThreadPoolConfigEntity request) {
try {
return Response.success(register.updateThreadPoolConfigByAdmin(request));
} catch (Exception e) {
return Response.error(Response.CodeEnum.ERROR);
}
}
}