# atlas-chain
**Repository Path**: greamrod/atlas-chain
## Basic Information
- **Project Name**: atlas-chain
- **Description**: No description available
- **Primary Language**: Java
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-08-26
- **Last Updated**: 2026-08-26
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Atlas-Chain 责任链框架
[](https://github.com/nemoob/atlas-chain/releases)
[](https://github.com/nemoob/atlas-chain/stargazers)
[](https://github.com/nemoob/atlas-chain/network)
[](https://github.com/nemoob/atlas-chain/issues)
[](https://github.com/nemoob/atlas-chain/blob/main/LICENSE)
[](https://search.maven.org/artifact/io.github.nemoob/atlas-chain-core)
[](https://www.oracle.com/java/)
[](https://spring.io/projects/spring-boot)
一个基于Java的责任链框架,支持核心模块独立使用和Spring Boot集成。
## 项目结构
```
atlas-chain/
├── atlas-chain-core/ # 核心模块,无Spring依赖,可独立使用
├── atlas-chain-spring-boot-starter/ # Spring Boot集成模块
├── examples/ # 使用示例
│ ├── core-example/ # core模块使用示例
│ └── spring-example/ # spring模块使用示例
└── pom.xml # 父项目POM
```
## 模块说明
### atlas-chain-core(核心模块)
核心模块不依赖Spring框架,可以在任何Java 8+环境中独立使用。
#### 主要组件
1. **HandlerContext
** - 责任链上下文,用于在处理者之间传递数据
2. **BaseHandler
** - 抽象处理者类,所有具体处理者需要继承此类
3. **ChainRegistry
** - 链注册器,负责注册和管理处理者
4. **ChainExecutor
** - 链执行器,负责执行责任链
### atlas-chain-spring-boot-starter(Spring Boot集成模块)
Spring Boot集成模块提供了自动配置和注解驱动功能。
#### 主要组件
1. **@ChainHandler** - 注解,用于标记处理者类
2. **ChainHandlerAutoConfiguration** - 自动配置类
3. **ChainHandlerProperties** - 配置属性类
4. **ChainHandlerRegistrar** - 处理者注册器
## 使用方法
### Maven依赖
对于纯Java项目使用core模块:
```xml
io.github.nemoob
atlas-chain-core
0.1.0
```
对于Spring Boot项目使用starter模块:
```xml
io.github.nemoob
atlas-chain-spring-boot-starter
0.1.0
```
### 核心模块使用示例
```java
// 创建注册器
ChainRegistry registry = new ChainRegistry<>();
// 创建处理者
AuthenticationHandler authHandler = new AuthenticationHandler();
AuthorizationHandler authzHandler = new AuthorizationHandler();
BusinessLogicHandler businessHandler = new BusinessLogicHandler();
// 注册处理者到指定链路
String chainId = "user-process-chain";
registry.registerHandler(chainId, authHandler);
registry.registerHandler(chainId, authzHandler);
registry.registerHandler(chainId, businessHandler);
// 创建执行器
ChainExecutor executor = new ChainExecutor<>(registry);
// 创建上下文
UserRequest request = new UserRequest("testUser", "testPassword");
HandlerContext context = new HandlerContext<>(request, null);
// 执行责任链
UserResponse response = executor.execute(chainId, context);
// 关闭执行器
executor.shutdown();
```
### Spring Boot集成使用示例
1. 在处理者类上添加@ChainHandler和@Component注解:
```java
@Component // 必须添加,让Spring管理此Bean
@ChainHandler(value = "user-process", order = 1)
public class UserValidateHandler extends BaseHandler {
@Override
protected boolean doHandle(HandlerContext context) {
// 处理逻辑
return true;
}
}
```
2. 在服务类中注入ChainExecutor并使用:
```java
@Service
public class UserService {
@Autowired
private ChainExecutor chainExecutor;
public UserResponse processUser(Long userId) {
UserRequest request = new UserRequest(userId, "testUser");
HandlerContext context = new HandlerContext<>(request, null);
return chainExecutor.execute("user-process", context);
}
}
```
## 配置属性
在Spring Boot项目中,可以通过以下属性配置线程池:
```yaml
chain:
handler:
core-pool-size: 5
max-pool-size: 10
keep-alive-time: 60
queue-capacity: 100
```
### 🧵 多线程池支持
Atlas-Chain 支持灵活的线程池配置,既可以使用默认配置,也可以自定义线程池。
#### 默认配置(推荐)
**零配置开箱即用**!框架会自动创建 `ChainExecutor` Bean:
```java
// 自动配置 - 使用默认线程池
@Bean("chainExecutor")
@ConditionalOnMissingBean(name = "chainExecutor")
public ChainExecutor