Skip to content

Commit

Permalink
开发 hippo4j-core 示例程序.
Browse files Browse the repository at this point in the history
  • Loading branch information
magestacks committed Feb 25, 2022
1 parent e9f4d9b commit 54b41c3
Show file tree
Hide file tree
Showing 19 changed files with 360 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
48 changes: 48 additions & 0 deletions hippo4j-example/hippo4j-core-spring-boot-starter-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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-example</artifactId>
<version>${revision}</version>
</parent>

<artifactId>hippo4j-core-spring-boot-starter-example</artifactId>
<name>${project.artifactId}</name>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-example-core</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-core-spring-boot-starter</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cn.hippo4j.example.core.starter;

import cn.hippo4j.core.enable.EnableDynamicThreadPool;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@EnableDynamicThreadPool
@SpringBootApplication(scanBasePackages = "cn.hippo4j.example.core")
public class Hippo4jCoreExampleApplication {

public static void main(String[] args) {
SpringApplication.run(Hippo4jCoreExampleApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
server:
port: 8089
servlet:
context-path: /example

spring:
profiles:
active: dev

application:
name: dynamic-threadpool-example

dynamic:
thread-pool:
enable: true
enable-banner: true
check-state-interval: 3
notify-platforms:
- platform: 'WECHAT'
secret-key: 1d307bfa-815f-4662-a2e5-99415e947bb8
- platform: 'DING'
secret-key: 56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55
executors:
- thread-pool-id: 'message-consume'
core-pool-size: 1
maximum-pool-size: 1
queue-capacity: 1
blocking-queue: 'LinkedBlockingQueue'
rejected-handler: 'AbortPolicy'
keep-alive-time: 6691
allow-core-thread-time-out: true
thread-name-prefix: 'message-consume'
notify:
is-alarm: true
active-alarm: 80
capacity-alarm: 80
interval: 8
receives:
WECHAT: 'xxx' # Fill in the enterprise weChat userId
DING: '15601166691' # phone

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cn.hippo4j.example.core.starter;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class Hippo4jCoreExampleApplicationTests {

@Test
void contextLoads() {
}

}
33 changes: 33 additions & 0 deletions hippo4j-example/hippo4j-example-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
37 changes: 37 additions & 0 deletions hippo4j-example/hippo4j-example-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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-example</artifactId>
<version>${revision}</version>
</parent>

<artifactId>hippo4j-example-core</artifactId>
<name>hippo4j-example-core</name>
<description>Hippo4J 实例工程核心包.</description>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-core</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package cn.hippo4j.example.config;
package cn.hippo4j.example.core.config;

import cn.hippo4j.example.inittest.TaskDecoratorTest;
import cn.hippo4j.starter.core.DynamicThreadPool;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.example.core.inittest.TaskDecoratorTest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

import static cn.hippo4j.example.constant.GlobalTestConstant.MESSAGE_CONSUME;
import static cn.hippo4j.example.constant.GlobalTestConstant.MESSAGE_PRODUCE;
import static cn.hippo4j.example.core.constant.GlobalTestConstant.MESSAGE_CONSUME;
import static cn.hippo4j.example.core.constant.GlobalTestConstant.MESSAGE_PRODUCE;

/**
* Thread pool config.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hippo4j.example.constant;
package cn.hippo4j.example.core.constant;

/**
* Global test variables.
Expand All @@ -8,9 +8,8 @@
*/
public class GlobalTestConstant {

public static final String CUSTOM_POOL = "custom-pool";

public static final String MESSAGE_PRODUCE = "message-produce";

public static final String MESSAGE_CONSUME = "message-consume";

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hippo4j.example.handler;
package cn.hippo4j.example.core.handler;

import cn.hippo4j.core.spi.CustomRejectedExecutionHandler;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.hippo4j.example.inittest;
package cn.hippo4j.example.core.inittest;

import cn.hippo4j.example.constant.GlobalTestConstant;
import cn.hippo4j.example.core.constant.GlobalTestConstant;
import cn.hutool.core.thread.ThreadUtil;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
Expand All @@ -22,7 +22,10 @@
@Component
public class AlarmSendMessageTest {

// @PostConstruct
/**
* 测试报警通知.
* 如果需要运行此单测, 方法上添加 @PostConstruct
*/
@SuppressWarnings("all")
public void alarmSendMessageTest() {
ScheduledExecutorService scheduledThreadPool = Executors.newSingleThreadScheduledExecutor();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.hippo4j.example.inittest;
package cn.hippo4j.example.core.inittest;

import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hutool.core.thread.ThreadUtil;
Expand Down Expand Up @@ -37,7 +37,6 @@ public void runStateHandlerTest() {

// 启动动态线程池模拟运行任务
runTask(dynamicThreadPoolExecutor);

}

private void runTask(ExecutorService executorService) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.hippo4j.example.inittest;
package cn.hippo4j.example.core.inittest;

import cn.hippo4j.example.constant.GlobalTestConstant;
import cn.hippo4j.example.core.constant.GlobalTestConstant;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hutool.core.thread.ThreadUtil;
Expand Down
33 changes: 33 additions & 0 deletions hippo4j-example/hippo4j-spring-boot-starter-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
Loading

0 comments on commit 54b41c3

Please sign in to comment.