| File | Date | Author | Commit |
|---|---|---|---|
| .github | 2021-10-31 |
|
[17d69b] 修复手动配置TCPServerConfig时,magicianHandlerMap与webS... |
| src | 2021-10-10 |
|
[f196c8] 修复手动配置TCPServerConfig时,magicianHandlerMap与webS... |
| .gitignore | 2021-04-10 |
|
[31b4d7] 首次提交 |
| BACKERS.md | 2021-06-25 |
|
[727653] 添加支持者榜单 |
| LICENSE | 2021-04-12 |
|
[15e460] 首次提交 |
| README.md | 2021-08-22 |
|
[ec2c76] 增加Kotlin示例 |
| pom.xml | 2021-08-19 |
|
[d5a70d] 给channel加锁,解决给客户端并发写入数据导致异常的问题 |
Magician is an asynchronous non-blocking network protocol analysis package, supports TCP, UDP protocol, built-in Http, WebSocket decoder
JDK11+
If you want to use it on a lower version of the JDK, you can download the source code of this repository and compile it yourself.
<dependency>
<groupId>com.github.yuyenews</groupId>
<artifactId>Magician</artifactId>
<version>last version</version>
</dependency>
<!-- This is the log package, which supports any package that can be bridged with slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.12</version>
</dependency>
@TCPHandler(path="/")
public class DemoHandler implements TCPBaseHandler<MagicianRequest> {
@Override
public void request(MagicianRequest magicianRequest) {
// response data
magicianRequest.getResponse()
.sendJson(200, "{'status':'ok'}");
}
}
Magician.createTCPServer()
.scan("The package name of the handler")
.bind(8080);
EventGroup ioEventGroup = new EventGroup(1, Executors.newCachedThreadPool());
EventGroup workerEventGroup = new EventGroup(10, Executors.newCachedThreadPool());
// When the current EventRunner has no tasks, it is allowed to steal tasks from other EventRunners
workerEventGroup.setSteal(EventEnum.STEAL.YES);
Magician.createTCPServer(ioEventGroup, workerEventGroup)
.scan("The package name of the handler")
.bind(8080);
// Listen to n ports, write n as the first parameter of ioEventGroup
EventGroup ioEventGroup = new EventGroup(2, Executors.newCachedThreadPool());
EventGroup workerEventGroup = new EventGroup(10, Executors.newCachedThreadPool());
// When the current EventRunner has no tasks, it is allowed to steal tasks from other EventRunners
workerEventGroup.setSteal(EventEnum.STEAL.YES);
TCPServer tcpServer = Magician.createTCPServer(ioEventGroup, workerEventGroup)
.scan("The package name of the handler")
tcpServer.bind(8080);
tcpServer.bind(8088);
Just add a handler when creating the http service
@WebSocketHandler(path = "/websocket")
public class DemoSocketHandler implements WebSocketBaseHandler {
@Override
public void onOpen(WebSocketSession webSocketSession) {
}
@Override
public void onClose(WebSocketSession webSocketSession) {
}
@Override
public void onMessage(String message, WebSocketSession webSocketSession) {
}
}
@UDPHandler
public class DemoUDPHandler implements UDPBaseHandler {
@Override
public void receive(ByteArrayOutputStream byteArrayOutputStream) {
}
}
Magician.createUdpServer()
.scan("The package name of the handler")
.bind(8088);
Use these components to easily develop web projects
Magician-Web |
Magician-JDBC |
Magician-Transaction |
Martian