mirror of https://github.com/longtai-cn/hippo4j
commit
1a7acb0897
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "社区",
|
||||||
|
"position": 1,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
# 贡献指南
|
||||||
|
|
||||||
|
Git Commit Log 尽量使用英文。
|
||||||
|
|
||||||
|
Pull Request 尽量保持单一,不同语义的代码贡献应拆分多个 Pull Request。
|
||||||
|
|
||||||
|
为了让您的 GitHub ID 显示在 Contributor 列表中,别忘了以下设置:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git config --global user.name "username"
|
||||||
|
git config --global user.email "GitHub 账号邮箱"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 贡献者列表
|
||||||
|
|
||||||
|
您可以在 [Hippo4J](https://github.com/opengoofy/hippo4j/graphs/contributors) 和 [Hippo4J Console](https://github.com/opengoofy/hippo4j-console) 的贡献列表中找到全部的贡献者名单。
|
||||||
|
|
||||||
|
<a href="https://github.com/opengoofy/hippo4j/graphs/contributors">
|
||||||
|
<img src="https://contrib.rocks/image?repo=opengoofy/hippo4j" />
|
||||||
|
</a>
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "贡献规约",
|
||||||
|
"position": 2,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 2
|
||||||
|
---
|
||||||
|
|
||||||
|
# 代码规约
|
||||||
|
|
||||||
|
1. 代码提交前,执行 `mvn spotless:apply` 保证代码格式符合规范。
|
||||||
|
2. 代码中不要出现无意义的空行。
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"label": "开发者手册",
|
||||||
|
"position": 5,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index",
|
||||||
|
"description": "Hippo4J 留给使用者能够扩展的知识点。"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 内置拒绝策略
|
||||||
|
|
||||||
|
内置两种拒绝策略说明:
|
||||||
|
|
||||||
|
**RunsOldestTaskPolicy**:添加新任务并由主线程运行最早的任务。
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class RunsOldestTaskPolicy implements RejectedExecutionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
if (executor.isShutdown()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockingQueue<Runnable> workQueue = executor.getQueue();
|
||||||
|
Runnable firstWork = workQueue.poll();
|
||||||
|
boolean newTaskAdd = workQueue.offer(r);
|
||||||
|
if (firstWork != null) {
|
||||||
|
firstWork.run();
|
||||||
|
}
|
||||||
|
if (!newTaskAdd) {
|
||||||
|
executor.execute(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**SyncPutQueuePolicy**:主线程把拒绝任务以阻塞的方式添加到队列。
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Slf4j
|
||||||
|
public class SyncPutQueuePolicy implements RejectedExecutionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
if (executor.isShutdown()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
executor.getQueue().put(r);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("Adding Queue task to thread pool failed.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "快速开始",
|
||||||
|
"position": 3,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"label": "依赖配置中心",
|
||||||
|
"position": 2,
|
||||||
|
"collapsed": true
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 4
|
||||||
|
---
|
||||||
|
|
||||||
|
# 参数默认配置
|
||||||
|
|
||||||
|
曾有多名小伙伴反馈说,项目中线程池一多,配置文件中配置就显得很臃肿。为此 hippo4j-config 开发出了动态线程池默认配置。
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
spring:
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
default-executor:
|
||||||
|
core-pool-size: 4
|
||||||
|
maximum-pool-size: 6
|
||||||
|
blocking-queue: ResizableCapacityLinkedBlockingQueue
|
||||||
|
queue-capacity: 1024
|
||||||
|
execute-time-out: 1000
|
||||||
|
keep-alive-time: 9999
|
||||||
|
rejected-handler: AbortPolicy
|
||||||
|
active-alarm: 90
|
||||||
|
capacity-alarm: 85
|
||||||
|
alarm: true
|
||||||
|
allow-core-thread-time-out: true
|
||||||
|
notify:
|
||||||
|
interval: 5
|
||||||
|
receives: chen.ma
|
||||||
|
executors:
|
||||||
|
- thread-pool-id: message-produce
|
||||||
|
- thread-pool-id: message-consume
|
||||||
|
core-pool-size: 80
|
||||||
|
maximum-pool-size: 100
|
||||||
|
execute-time-out: 1000
|
||||||
|
notify:
|
||||||
|
interval: 6
|
||||||
|
receives: chen.ma
|
||||||
|
```
|
||||||
|
|
||||||
|
`spring.dynamic.thread-pool.executors` 层级下,仅需要配置 `thread-pool-id`,其余配置从 `spring.dynamic.thread-pool.default-executor` 读取。
|
||||||
|
|
||||||
|
如果 `spring.dynamic.thread-pool.executors` 下配置和 `spring.dynamic.thread-pool.default-executor` 冲突,以前者为主。
|
||||||
|
|
||||||
|
通过该自定义配置方式,可减少大量重复线程池参数配置项,提高核心配置简洁度。
|
||||||
|
|
||||||
|
提示:`spring.dynamic.thread-pool.default-executor` 层级下参数,不提供动态刷新功能。
|
@ -0,0 +1,121 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 5
|
||||||
|
---
|
||||||
|
|
||||||
|
# 适配SpringBoot1x
|
||||||
|
|
||||||
|
目前已支持 Nacos、Apollo 配置中心适配 SpringBoot 1.5.x 版本。
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-config-spring-boot-1x-starter</artifactId>
|
||||||
|
<version>1.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
Nacos SpringBoot 配置如下:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
config:
|
||||||
|
ext-config:
|
||||||
|
- data-id: hippo4j-nacos.yaml
|
||||||
|
group: DEFAULT_GROUP
|
||||||
|
refresh: true
|
||||||
|
server-addr: 127.0.0.1:8848
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
config-file-type: yml
|
||||||
|
nacos:
|
||||||
|
data-id: hippo4j-nacos.yaml
|
||||||
|
group: DEFAULT_GROUP
|
||||||
|
```
|
||||||
|
|
||||||
|
Apollo SpringBoot 配置如下:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apollo:
|
||||||
|
autoUpdateInjectedSpringProperties: true
|
||||||
|
bootstrap:
|
||||||
|
eagerLoad:
|
||||||
|
enabled: true
|
||||||
|
enabled: true
|
||||||
|
namespaces: application
|
||||||
|
meta: http://127.0.0.1:8080
|
||||||
|
app:
|
||||||
|
id: dynamic-threadpool-example
|
||||||
|
spring:
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
apollo:
|
||||||
|
namespace: application
|
||||||
|
```
|
||||||
|
|
||||||
|
动态线程池通用配置如下:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
management:
|
||||||
|
context-path: /actuator
|
||||||
|
security:
|
||||||
|
enabled: false
|
||||||
|
server:
|
||||||
|
port: 8091
|
||||||
|
servlet:
|
||||||
|
context-path: /example
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: dynamic-threadpool-example
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
banner: true
|
||||||
|
check-state-interval: 5
|
||||||
|
collect-type: micrometer
|
||||||
|
config-file-type: properties
|
||||||
|
enable: true
|
||||||
|
executors:
|
||||||
|
- active-alarm: 80
|
||||||
|
alarm: true
|
||||||
|
allow-core-thread-time-out: true
|
||||||
|
blocking-queue: LinkedBlockingQueue
|
||||||
|
capacity-alarm: 80
|
||||||
|
core-pool-size: 1
|
||||||
|
execute-time-out: 1000
|
||||||
|
keep-alive-time: 6691
|
||||||
|
maximum-pool-size: 1
|
||||||
|
notify:
|
||||||
|
interval: 8
|
||||||
|
receives: chen.ma
|
||||||
|
queue-capacity: 1
|
||||||
|
rejected-handler: AbortPolicy
|
||||||
|
thread-name-prefix: message-consume
|
||||||
|
thread-pool-id: message-consume
|
||||||
|
- active-alarm: 80
|
||||||
|
alarm: true
|
||||||
|
allow-core-thread-time-out: true
|
||||||
|
blocking-queue: LinkedBlockingQueue
|
||||||
|
capacity-alarm: 80
|
||||||
|
core-pool-size: 1
|
||||||
|
execute-time-out: 1000
|
||||||
|
keep-alive-time: 6691
|
||||||
|
maximum-pool-size: 1
|
||||||
|
notify:
|
||||||
|
interval: 8
|
||||||
|
receives: chen.ma
|
||||||
|
queue-capacity: 1
|
||||||
|
rejected-handler: AbortPolicy
|
||||||
|
thread-name-prefix: message-produce
|
||||||
|
thread-pool-id: message-produce
|
||||||
|
notify-platforms:
|
||||||
|
- platform: WECHAT
|
||||||
|
token: ac0426a5-c712-474c-9bff-72b8b8f5caff
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
```
|
||||||
|
|
||||||
|
具体 Demo 运行请参考以下示例模块,已验证对应线程池动态变更、报警以及运行时监控功能。
|
||||||
|
|
||||||
|
- `/hippo4j-config-nacos-spring-boot-1x-starter-example`
|
||||||
|
- `hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example`
|
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 730 KiB |
After Width: | Height: | Size: 27 KiB |
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"label": "无中间件依赖",
|
||||||
|
"position": 3,
|
||||||
|
"collapsed": true
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "运维指南",
|
||||||
|
"position": 4,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "其它",
|
||||||
|
"position": 6,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
# 加群沟通
|
||||||
|
|
||||||
|
扫码添加微信,备注:`hippo4j`,邀您加入群聊。
|
||||||
|
|
||||||
|

|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"label": "用户指南",
|
||||||
|
"position": 2,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index",
|
||||||
|
"description": "帮助想要了解 Hippo4J 的用户快速掌握核心开发理念。"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "社区",
|
||||||
|
"position": 1,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
# 贡献指南
|
||||||
|
|
||||||
|
Git Commit Log 尽量使用英文。
|
||||||
|
|
||||||
|
Pull Request 尽量保持单一,不同语义的代码贡献应拆分多个 Pull Request。
|
||||||
|
|
||||||
|
为了让您的 GitHub ID 显示在 Contributor 列表中,别忘了以下设置:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git config --global user.name "username"
|
||||||
|
git config --global user.email "GitHub 账号邮箱"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 贡献者列表
|
||||||
|
|
||||||
|
您可以在 [Hippo4J](https://github.com/opengoofy/hippo4j/graphs/contributors) 和 [Hippo4J Console](https://github.com/opengoofy/hippo4j-console) 的贡献列表中找到全部的贡献者名单。
|
||||||
|
|
||||||
|
<a href="https://github.com/opengoofy/hippo4j/graphs/contributors">
|
||||||
|
<img src="https://contrib.rocks/image?repo=opengoofy/hippo4j" />
|
||||||
|
</a>
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "贡献规约",
|
||||||
|
"position": 2,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 2
|
||||||
|
---
|
||||||
|
|
||||||
|
# 代码规约
|
||||||
|
|
||||||
|
1. 代码提交前,执行 `mvn spotless:apply` 保证代码格式符合规范。
|
||||||
|
2. 代码中不要出现无意义的空行。
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"label": "开发者手册",
|
||||||
|
"position": 5,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index",
|
||||||
|
"description": "Hippo4J 留给使用者能够扩展的知识点。"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 内置拒绝策略
|
||||||
|
|
||||||
|
内置两种拒绝策略说明:
|
||||||
|
|
||||||
|
**RunsOldestTaskPolicy**:添加新任务并由主线程运行最早的任务。
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class RunsOldestTaskPolicy implements RejectedExecutionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
if (executor.isShutdown()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockingQueue<Runnable> workQueue = executor.getQueue();
|
||||||
|
Runnable firstWork = workQueue.poll();
|
||||||
|
boolean newTaskAdd = workQueue.offer(r);
|
||||||
|
if (firstWork != null) {
|
||||||
|
firstWork.run();
|
||||||
|
}
|
||||||
|
if (!newTaskAdd) {
|
||||||
|
executor.execute(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**SyncPutQueuePolicy**:主线程把拒绝任务以阻塞的方式添加到队列。
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Slf4j
|
||||||
|
public class SyncPutQueuePolicy implements RejectedExecutionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
if (executor.isShutdown()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
executor.getQueue().put(r);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("Adding Queue task to thread pool failed.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "快速开始",
|
||||||
|
"position": 3,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"label": "依赖配置中心",
|
||||||
|
"position": 2,
|
||||||
|
"collapsed": true
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 4
|
||||||
|
---
|
||||||
|
|
||||||
|
# 参数默认配置
|
||||||
|
|
||||||
|
曾有多名小伙伴反馈说,项目中线程池一多,配置文件中配置就显得很臃肿。为此 hippo4j-config 开发出了动态线程池默认配置。
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
spring:
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
default-executor:
|
||||||
|
core-pool-size: 4
|
||||||
|
maximum-pool-size: 6
|
||||||
|
blocking-queue: ResizableCapacityLinkedBlockingQueue
|
||||||
|
queue-capacity: 1024
|
||||||
|
execute-time-out: 1000
|
||||||
|
keep-alive-time: 9999
|
||||||
|
rejected-handler: AbortPolicy
|
||||||
|
active-alarm: 90
|
||||||
|
capacity-alarm: 85
|
||||||
|
alarm: true
|
||||||
|
allow-core-thread-time-out: true
|
||||||
|
notify:
|
||||||
|
interval: 5
|
||||||
|
receives: chen.ma
|
||||||
|
executors:
|
||||||
|
- thread-pool-id: message-produce
|
||||||
|
- thread-pool-id: message-consume
|
||||||
|
core-pool-size: 80
|
||||||
|
maximum-pool-size: 100
|
||||||
|
execute-time-out: 1000
|
||||||
|
notify:
|
||||||
|
interval: 6
|
||||||
|
receives: chen.ma
|
||||||
|
```
|
||||||
|
|
||||||
|
`spring.dynamic.thread-pool.executors` 层级下,仅需要配置 `thread-pool-id`,其余配置从 `spring.dynamic.thread-pool.default-executor` 读取。
|
||||||
|
|
||||||
|
如果 `spring.dynamic.thread-pool.executors` 下配置和 `spring.dynamic.thread-pool.default-executor` 冲突,以前者为主。
|
||||||
|
|
||||||
|
通过该自定义配置方式,可减少大量重复线程池参数配置项,提高核心配置简洁度。
|
||||||
|
|
||||||
|
提示:`spring.dynamic.thread-pool.default-executor` 层级下参数,不提供动态刷新功能。
|
@ -0,0 +1,121 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 5
|
||||||
|
---
|
||||||
|
|
||||||
|
# 适配SpringBoot1x
|
||||||
|
|
||||||
|
目前已支持 Nacos、Apollo 配置中心适配 SpringBoot 1.5.x 版本。
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-config-spring-boot-1x-starter</artifactId>
|
||||||
|
<version>1.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
Nacos SpringBoot 配置如下:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
config:
|
||||||
|
ext-config:
|
||||||
|
- data-id: hippo4j-nacos.yaml
|
||||||
|
group: DEFAULT_GROUP
|
||||||
|
refresh: true
|
||||||
|
server-addr: 127.0.0.1:8848
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
config-file-type: yml
|
||||||
|
nacos:
|
||||||
|
data-id: hippo4j-nacos.yaml
|
||||||
|
group: DEFAULT_GROUP
|
||||||
|
```
|
||||||
|
|
||||||
|
Apollo SpringBoot 配置如下:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apollo:
|
||||||
|
autoUpdateInjectedSpringProperties: true
|
||||||
|
bootstrap:
|
||||||
|
eagerLoad:
|
||||||
|
enabled: true
|
||||||
|
enabled: true
|
||||||
|
namespaces: application
|
||||||
|
meta: http://127.0.0.1:8080
|
||||||
|
app:
|
||||||
|
id: dynamic-threadpool-example
|
||||||
|
spring:
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
apollo:
|
||||||
|
namespace: application
|
||||||
|
```
|
||||||
|
|
||||||
|
动态线程池通用配置如下:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
management:
|
||||||
|
context-path: /actuator
|
||||||
|
security:
|
||||||
|
enabled: false
|
||||||
|
server:
|
||||||
|
port: 8091
|
||||||
|
servlet:
|
||||||
|
context-path: /example
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: dynamic-threadpool-example
|
||||||
|
dynamic:
|
||||||
|
thread-pool:
|
||||||
|
banner: true
|
||||||
|
check-state-interval: 5
|
||||||
|
collect-type: micrometer
|
||||||
|
config-file-type: properties
|
||||||
|
enable: true
|
||||||
|
executors:
|
||||||
|
- active-alarm: 80
|
||||||
|
alarm: true
|
||||||
|
allow-core-thread-time-out: true
|
||||||
|
blocking-queue: LinkedBlockingQueue
|
||||||
|
capacity-alarm: 80
|
||||||
|
core-pool-size: 1
|
||||||
|
execute-time-out: 1000
|
||||||
|
keep-alive-time: 6691
|
||||||
|
maximum-pool-size: 1
|
||||||
|
notify:
|
||||||
|
interval: 8
|
||||||
|
receives: chen.ma
|
||||||
|
queue-capacity: 1
|
||||||
|
rejected-handler: AbortPolicy
|
||||||
|
thread-name-prefix: message-consume
|
||||||
|
thread-pool-id: message-consume
|
||||||
|
- active-alarm: 80
|
||||||
|
alarm: true
|
||||||
|
allow-core-thread-time-out: true
|
||||||
|
blocking-queue: LinkedBlockingQueue
|
||||||
|
capacity-alarm: 80
|
||||||
|
core-pool-size: 1
|
||||||
|
execute-time-out: 1000
|
||||||
|
keep-alive-time: 6691
|
||||||
|
maximum-pool-size: 1
|
||||||
|
notify:
|
||||||
|
interval: 8
|
||||||
|
receives: chen.ma
|
||||||
|
queue-capacity: 1
|
||||||
|
rejected-handler: AbortPolicy
|
||||||
|
thread-name-prefix: message-produce
|
||||||
|
thread-pool-id: message-produce
|
||||||
|
notify-platforms:
|
||||||
|
- platform: WECHAT
|
||||||
|
token: ac0426a5-c712-474c-9bff-72b8b8f5caff
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
```
|
||||||
|
|
||||||
|
具体 Demo 运行请参考以下示例模块,已验证对应线程池动态变更、报警以及运行时监控功能。
|
||||||
|
|
||||||
|
- `/hippo4j-config-nacos-spring-boot-1x-starter-example`
|
||||||
|
- `hippo4j-example/hippo4j-config-apollo-spring-boot-1x-starter-example`
|
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 730 KiB |
After Width: | Height: | Size: 27 KiB |
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"label": "无中间件依赖",
|
||||||
|
"position": 3,
|
||||||
|
"collapsed": true
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "运维指南",
|
||||||
|
"position": 4,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"label": "其它",
|
||||||
|
"position": 6,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
sidebar_position: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
# 加群沟通
|
||||||
|
|
||||||
|
扫码添加微信,备注:`hippo4j`,邀您加入群聊。
|
||||||
|
|
||||||
|

|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"label": "用户指南",
|
||||||
|
"position": 2,
|
||||||
|
"link": {
|
||||||
|
"type": "generated-index",
|
||||||
|
"description": "帮助想要了解 Hippo4J 的用户快速掌握核心开发理念。"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"tutorialSidebar": [
|
||||||
|
{
|
||||||
|
"type": "autogenerated",
|
||||||
|
"dirName": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_docs": [
|
||||||
|
{
|
||||||
|
"type": "autogenerated",
|
||||||
|
"dirName": "user_docs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"community": [
|
||||||
|
{
|
||||||
|
"type": "autogenerated",
|
||||||
|
"dirName": "community"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sponsor": [
|
||||||
|
{
|
||||||
|
"type": "autogenerated",
|
||||||
|
"dirName": "sponsor"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
"1.4.2"
|
||||||
|
]
|
@ -0,0 +1,320 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.executor;
|
||||||
|
|
||||||
|
import cn.hippo4j.core.plugin.*;
|
||||||
|
import cn.hippo4j.core.plugin.manager.ThreadPoolPluginManager;
|
||||||
|
import cn.hippo4j.core.plugin.manager.ThreadPoolPluginSupport;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Extensible thread-pool executor. <br />
|
||||||
|
* Support the callback extension points provided on the basis of {@link ThreadPoolExecutor}.
|
||||||
|
* Each extension point corresponds to a different {@link ThreadPoolPlugin} interface,
|
||||||
|
* users can customize plug-ins and implement one or more {@link ThreadPoolPlugin} interface
|
||||||
|
* to enable plugins to sense thread pool behavior and provide extended functions.
|
||||||
|
*
|
||||||
|
* @see ThreadPoolPluginManager
|
||||||
|
* @see ThreadPoolPlugin
|
||||||
|
*/
|
||||||
|
public class ExtensibleThreadPoolExecutor extends ThreadPoolExecutor implements ThreadPoolPluginSupport {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* thread pool id
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@NonNull
|
||||||
|
private final String threadPoolId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* action aware registry
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final ThreadPoolPluginManager threadPoolPluginManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler wrapper, any changes to the current instance {@link RejectedExecutionHandler} should be made through this wrapper
|
||||||
|
*/
|
||||||
|
private final RejectedAwareHandlerWrapper handlerWrapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@code ExtensibleThreadPoolExecutor} with the given initial parameters.
|
||||||
|
*
|
||||||
|
* @param threadPoolId thread-pool id
|
||||||
|
* @param threadPoolPluginManager action aware registry
|
||||||
|
* @param corePoolSize the number of threads to keep in the pool, even
|
||||||
|
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
|
||||||
|
* @param maximumPoolSize the maximum number of threads to allow in the
|
||||||
|
* pool
|
||||||
|
* @param keepAliveTime when the number of threads is greater than
|
||||||
|
* the core, this is the maximum time that excess idle threads
|
||||||
|
* will wait for new tasks before terminating.
|
||||||
|
* @param unit the time unit for the {@code keepAliveTime} argument
|
||||||
|
* @param workQueue the queue to use for holding tasks before they are
|
||||||
|
* executed. This queue will hold only the {@code Runnable}
|
||||||
|
* tasks submitted by the {@code execute} method.
|
||||||
|
* @param threadFactory the factory to use when the executor
|
||||||
|
* creates a new thread
|
||||||
|
* @param handler the handler to use when execution is blocked
|
||||||
|
* because the thread bounds and queue capacities are reached
|
||||||
|
* @throws IllegalArgumentException if one of the following holds:<br>
|
||||||
|
* {@code corePoolSize < 0}<br>
|
||||||
|
* {@code keepAliveTime < 0}<br>
|
||||||
|
* {@code maximumPoolSize <= 0}<br>
|
||||||
|
* {@code maximumPoolSize < corePoolSize}
|
||||||
|
* @throws NullPointerException if {@code workQueue}
|
||||||
|
* or {@code threadFactory} or {@code handler} is null
|
||||||
|
*/
|
||||||
|
public ExtensibleThreadPoolExecutor(
|
||||||
|
@NonNull String threadPoolId,
|
||||||
|
@NonNull ThreadPoolPluginManager threadPoolPluginManager,
|
||||||
|
int corePoolSize, int maximumPoolSize,
|
||||||
|
long keepAliveTime, TimeUnit unit,
|
||||||
|
@NonNull BlockingQueue<Runnable> workQueue,
|
||||||
|
@NonNull ThreadFactory threadFactory,
|
||||||
|
@NonNull RejectedExecutionHandler handler) {
|
||||||
|
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
|
||||||
|
|
||||||
|
// pool extended info
|
||||||
|
this.threadPoolId = threadPoolId;
|
||||||
|
this.threadPoolPluginManager = threadPoolPluginManager;
|
||||||
|
|
||||||
|
// proxy handler to support Aware callback
|
||||||
|
while (handler instanceof RejectedAwareHandlerWrapper) {
|
||||||
|
handler = ((RejectedAwareHandlerWrapper) handler).getHandler();
|
||||||
|
}
|
||||||
|
this.handlerWrapper = new RejectedAwareHandlerWrapper(threadPoolPluginManager, handler);
|
||||||
|
super.setRejectedExecutionHandler(handlerWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p><b>Before calling the parent class method, {@link ExecuteAwarePlugin#beforeExecute} will be called first.
|
||||||
|
*
|
||||||
|
* @param thread the thread that will run task {@code r}
|
||||||
|
* @param runnable the task that will be executed
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void beforeExecute(Thread thread, Runnable runnable) {
|
||||||
|
Collection<ExecuteAwarePlugin> executeAwarePluginList = threadPoolPluginManager.getExecuteAwarePluginList();
|
||||||
|
executeAwarePluginList.forEach(aware -> aware.beforeExecute(thread, runnable));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p><b>Before calling the superclass method, {@link TaskAwarePlugin#beforeTaskExecute} will be called first.
|
||||||
|
*
|
||||||
|
* @param runnable the task to execute
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void execute(@NonNull Runnable runnable) {
|
||||||
|
Collection<TaskAwarePlugin> taskAwarePluginList = threadPoolPluginManager.getTaskAwarePluginList();
|
||||||
|
for (TaskAwarePlugin taskAwarePlugin : taskAwarePluginList) {
|
||||||
|
runnable = taskAwarePlugin.beforeTaskExecute(runnable);
|
||||||
|
}
|
||||||
|
super.execute(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p><b>After calling the superclass method, {@link ExecuteAwarePlugin#afterExecute} will be called last.
|
||||||
|
*
|
||||||
|
* @param runnable the runnable that has completed
|
||||||
|
* @param throwable the exception that caused termination, or null if
|
||||||
|
* execution completed normally
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void afterExecute(Runnable runnable, Throwable throwable) {
|
||||||
|
Collection<ExecuteAwarePlugin> executeAwarePluginList = threadPoolPluginManager.getExecuteAwarePluginList();
|
||||||
|
executeAwarePluginList.forEach(aware -> aware.afterExecute(runnable, throwable));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p><b>Before calling the superclass method,
|
||||||
|
* {@link ShutdownAwarePlugin#beforeShutdown} will be called first.
|
||||||
|
* and then will be call {@link ShutdownAwarePlugin#afterShutdown}
|
||||||
|
*
|
||||||
|
* @throws SecurityException {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
Collection<ShutdownAwarePlugin> shutdownAwarePluginList = threadPoolPluginManager.getShutdownAwarePluginList();
|
||||||
|
shutdownAwarePluginList.forEach(aware -> aware.beforeShutdown(this));
|
||||||
|
super.shutdown();
|
||||||
|
shutdownAwarePluginList.forEach(aware -> aware.afterShutdown(this, Collections.emptyList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p><b>Before calling the superclass method,
|
||||||
|
* {@link ShutdownAwarePlugin#beforeShutdown} will be called first.
|
||||||
|
* and then will be call {@link ShutdownAwarePlugin#afterShutdown}
|
||||||
|
*
|
||||||
|
* @throws SecurityException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Runnable> shutdownNow() {
|
||||||
|
Collection<ShutdownAwarePlugin> shutdownAwarePluginList = threadPoolPluginManager.getShutdownAwarePluginList();
|
||||||
|
shutdownAwarePluginList.forEach(aware -> aware.beforeShutdown(this));
|
||||||
|
List<Runnable> tasks = super.shutdownNow();
|
||||||
|
shutdownAwarePluginList.forEach(aware -> aware.afterShutdown(this, tasks));
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}.
|
||||||
|
*
|
||||||
|
* <p><b>Before calling the superclass method, {@link ShutdownAwarePlugin#afterTerminated} will be called first.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void terminated() {
|
||||||
|
super.terminated();
|
||||||
|
Collection<ShutdownAwarePlugin> shutdownAwarePluginList = threadPoolPluginManager.getShutdownAwarePluginList();
|
||||||
|
shutdownAwarePluginList.forEach(aware -> aware.afterTerminated(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p><b>Before calling the superclass method, {@link TaskAwarePlugin#beforeTaskCreate} will be called first.
|
||||||
|
*
|
||||||
|
* @param runnable the runnable task being wrapped
|
||||||
|
* @param value the default value for the returned future
|
||||||
|
* @return a {@code RunnableFuture} which, when run, will run the
|
||||||
|
* underlying runnable and which, as a {@code Future}, will yield
|
||||||
|
* the given value as its result and provide for cancellation of
|
||||||
|
* the underlying task
|
||||||
|
* @since 1.6
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
|
||||||
|
Collection<TaskAwarePlugin> taskAwarePluginList = threadPoolPluginManager.getTaskAwarePluginList();
|
||||||
|
for (TaskAwarePlugin taskAwarePlugin : taskAwarePluginList) {
|
||||||
|
runnable = taskAwarePlugin.beforeTaskCreate(this, runnable, value);
|
||||||
|
}
|
||||||
|
return super.newTaskFor(runnable, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p><b>Before calling the superclass method, {@link TaskAwarePlugin#beforeTaskCreate} will be called first.
|
||||||
|
*
|
||||||
|
* @param callable the callable task being wrapped
|
||||||
|
* @return a {@code RunnableFuture} which, when run, will call the
|
||||||
|
* underlying callable and which, as a {@code Future}, will yield
|
||||||
|
* the callable's result as its result and provide for
|
||||||
|
* cancellation of the underlying task
|
||||||
|
* @since 1.6
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
|
||||||
|
Collection<TaskAwarePlugin> taskAwarePluginList = threadPoolPluginManager.getTaskAwarePluginList();
|
||||||
|
for (TaskAwarePlugin taskAwarePlugin : taskAwarePluginList) {
|
||||||
|
callable = taskAwarePlugin.beforeTaskCreate(this, callable);
|
||||||
|
}
|
||||||
|
return super.newTaskFor(callable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new handler for unexecutable tasks.
|
||||||
|
*
|
||||||
|
* @param handler the new handler
|
||||||
|
* @throws NullPointerException if handler is null
|
||||||
|
* @see #getRejectedExecutionHandler
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setRejectedExecutionHandler(@NonNull RejectedExecutionHandler handler) {
|
||||||
|
while (handler instanceof RejectedAwareHandlerWrapper) {
|
||||||
|
handler = ((RejectedAwareHandlerWrapper) handler).getHandler();
|
||||||
|
}
|
||||||
|
handlerWrapper.setHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current handler for unexecutable tasks.
|
||||||
|
*
|
||||||
|
* @return the current handler
|
||||||
|
* @see #setRejectedExecutionHandler(RejectedExecutionHandler)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RejectedExecutionHandler getRejectedExecutionHandler() {
|
||||||
|
return handlerWrapper.getHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get thread-pool executor.
|
||||||
|
*
|
||||||
|
* @return thread-pool executor
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ThreadPoolExecutor getThreadPoolExecutor() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper of original {@link RejectedExecutionHandler} of {@link ThreadPoolExecutor},
|
||||||
|
* It's used to support the {@link RejectedAwarePlugin} on the basis of the {@link RejectedExecutionHandler}.
|
||||||
|
*
|
||||||
|
* @see RejectedAwarePlugin
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
private static class RejectedAwareHandlerWrapper implements RejectedExecutionHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* thread-pool action aware registry
|
||||||
|
*/
|
||||||
|
private final ThreadPoolPluginManager registry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* original target
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private RejectedExecutionHandler handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call {@link RejectedAwarePlugin#beforeRejectedExecution}, then reject the task
|
||||||
|
*
|
||||||
|
* @param r the runnable task requested to be executed
|
||||||
|
* @param executor the executor attempting to execute this task
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
Collection<RejectedAwarePlugin> rejectedAwarePluginList = registry.getRejectedAwarePluginList();
|
||||||
|
rejectedAwarePluginList.forEach(aware -> aware.beforeRejectedExecution(r, executor));
|
||||||
|
handler.rejectedExecution(r, executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.plugin;
|
||||||
|
|
||||||
|
import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback during task execution.
|
||||||
|
*/
|
||||||
|
public interface ExecuteAwarePlugin extends ThreadPoolPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback before task execution.
|
||||||
|
*
|
||||||
|
* @param thread thread of executing task
|
||||||
|
* @param runnable task
|
||||||
|
* @see ExtensibleThreadPoolExecutor#beforeExecute
|
||||||
|
*/
|
||||||
|
default void beforeExecute(Thread thread, Runnable runnable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback after task execution.
|
||||||
|
*
|
||||||
|
* @param runnable runnable
|
||||||
|
* @param throwable exception thrown during execution
|
||||||
|
* @see ExtensibleThreadPoolExecutor#afterExecute
|
||||||
|
*/
|
||||||
|
default void afterExecute(Runnable runnable, Throwable throwable) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.plugin;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plug in runtime information.
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public class PluginRuntime {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* plugin id
|
||||||
|
*/
|
||||||
|
private final String pluginId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* runtime info
|
||||||
|
*/
|
||||||
|
private final List<Info> infoList = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a runtime info item.
|
||||||
|
*
|
||||||
|
* @param name name
|
||||||
|
* @param value value
|
||||||
|
* @return runtime info item
|
||||||
|
*/
|
||||||
|
public PluginRuntime addInfo(String name, Object value) {
|
||||||
|
infoList.add(new Info(name, value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public static class Info {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final Object value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.plugin;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback when task is rejected.
|
||||||
|
*/
|
||||||
|
public interface RejectedAwarePlugin extends ThreadPoolPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback before task is rejected.
|
||||||
|
*
|
||||||
|
* @param runnable task
|
||||||
|
* @param executor executor
|
||||||
|
*/
|
||||||
|
default void beforeRejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue