Compare commits
10 Commits
cb8151889b
...
8142655a37
Author | SHA1 | Date |
---|---|---|
|
8142655a37 | |
|
e8f8f1d925 | |
|
6ad1f5f712 | |
|
29070514ba | |
|
8aae04dbab | |
|
55be772fc0 | |
|
99b50ab2d2 | |
|
8e6f35ae2a | |
|
9131645204 | |
|
6339e56b43 |
15
README.md
15
README.md
|
@ -8,12 +8,11 @@
|
||||||
* TCP协议服务端开发
|
* TCP协议服务端开发
|
||||||
|
|
||||||
## 代码仓库
|
## 代码仓库
|
||||||
* Gitee仓库地址:[https://gitee.com/yezhihao/netmc/tree/master](https://gitee.com/yezhihao/netmc/tree/master)
|
* Gitee仓库地址:[http://115.29.108.160:3000/TripartiteOpenSource/netmc](http://115.29.108.160:3000/TripartiteOpenSource/netmc)
|
||||||
* Github仓库地址:[https://github.com/yezhihao/netmc/tree/master](https://github.com/yezhihao/netmc/tree/master)
|
* Github仓库地址:[http://115.29.108.160:3000/TripartiteOpenSource/netmc](http://115.29.108.160:3000/TripartiteOpenSource/netmc)
|
||||||
|
|
||||||
## 下载方式
|
## 下载方式
|
||||||
* Gitee下载命令:`git clone https://gitee.com/yezhihao/netmc -b master`
|
* Git下载命令:`git clone http://115.29.108.160:3000/TripartiteOpenSource/netmc.git -b master`
|
||||||
* Github下载命令:`git clone https://github.com/yezhihao/netmc -b master`
|
|
||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
```sh
|
```sh
|
||||||
|
@ -72,10 +71,4 @@ public class JT808Endpoint {
|
||||||
|
|
||||||
详细的例子请参考Test目录
|
详细的例子请参考Test目录
|
||||||
|
|
||||||
使用该组件的项目:[https://gitee.com/yezhihao/jt808-server/tree/master](https://gitee.com/yezhihao/jt808-server/tree/master)
|
当前项目是Fork [剑器近](https://gitee.com/yezhihao) 的 [netmc](https://gitee.com/yezhihao/netmc?_from=gitee_search)
|
||||||
|
|
||||||
项目会不定期进行更新,建议star和watch一份,您的支持是我最大的动力。
|
|
||||||
|
|
||||||
如有任何疑问或者BUG,请联系我,非常感谢。
|
|
||||||
|
|
||||||
技术交流QQ群:[906230542]
|
|
||||||
|
|
122
pom.xml
122
pom.xml
|
@ -1,9 +1,10 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.github.yezhihao</groupId>
|
|
||||||
|
<groupId>com.dust.tripartite</groupId>
|
||||||
<artifactId>netmc</artifactId>
|
<artifactId>netmc</artifactId>
|
||||||
<version>2.0.4.RELEASE</version>
|
<version>2.0.6.RELEASE</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Netmc</name>
|
<name>Netmc</name>
|
||||||
|
@ -18,25 +19,17 @@
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<url>https://github.com/yezhihao/netmc</url>
|
<url>http://115.29.108.160:3000/TripartiteOpenSource/netmc</url>
|
||||||
<connection>https://github.com/yezhihao/netmc.git</connection>
|
<connection>http://115.29.108.160:3000/TripartiteOpenSource/netmc.git</connection>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<id>netmc.yezhihao</id>
|
|
||||||
<name>netmc</name>
|
|
||||||
<email>zhihao.ye@qq.com</email>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<resource.delimiter>@</resource.delimiter>
|
<resource.delimiter>@</resource.delimiter>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<maven.test.skip>true</maven.test.skip>
|
<maven.test.skip>true</maven.test.skip>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -62,26 +55,26 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-handler</artifactId>
|
<artifactId>netty-handler</artifactId>
|
||||||
<version>4.1.66.Final</version>
|
<version>4.1.70.Final</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||||
<artifactId>caffeine</artifactId>
|
<artifactId>caffeine</artifactId>
|
||||||
<version>2.8.8</version>
|
<version>3.0.4</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<version>5.3.9</version>
|
<version>5.3.12</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>nexus-release</id>
|
<id>nexus-releases</id>
|
||||||
<activation>
|
<activation>
|
||||||
<activeByDefault>true</activeByDefault>
|
<activeByDefault>true</activeByDefault>
|
||||||
</activation>
|
</activation>
|
||||||
|
@ -103,7 +96,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.3.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
@ -113,20 +106,20 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
|
||||||
<version>1.6</version>
|
<!-- <version>3.0.1</version>-->
|
||||||
<executions>
|
<!-- <executions>-->
|
||||||
<execution>
|
<!-- <execution>-->
|
||||||
<id>sign-artifacts</id>
|
<!-- <id>sign-artifacts</id>-->
|
||||||
<phase>verify</phase>
|
<!-- <phase>verify</phase>-->
|
||||||
<goals>
|
<!-- <goals>-->
|
||||||
<goal>sign</goal>
|
<!-- <goal>sign</goal>-->
|
||||||
</goals>
|
<!-- </goals>-->
|
||||||
</execution>
|
<!-- </execution>-->
|
||||||
</executions>
|
<!-- </executions>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
@ -143,6 +136,7 @@
|
||||||
<version>2.5.3</version>
|
<version>2.5.3</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>2.8.2</version>
|
<version>2.8.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
|
@ -155,43 +149,45 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
<!-- <groupId>org.sonatype.plugins</groupId>-->
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
<!-- <artifactId>nexus-staging-maven-plugin</artifactId>-->
|
||||||
<version>1.6.8</version>
|
<!-- <version>1.6.8</version>-->
|
||||||
<extensions>true</extensions>
|
<!-- <extensions>true</extensions>-->
|
||||||
<configuration>
|
<!-- <configuration>-->
|
||||||
<serverId>central-nexus</serverId>
|
<!-- <serverId>central-nexus</serverId>-->
|
||||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
<!-- <nexusUrl>https://oss.sonatype.org/</nexusUrl>-->
|
||||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
<!-- <autoReleaseAfterClose>true</autoReleaseAfterClose>-->
|
||||||
</configuration>
|
<!-- </configuration>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<artifactId>maven-scm-plugin</artifactId>
|
<!-- <artifactId>maven-scm-plugin</artifactId>-->
|
||||||
<version>1.11.2</version>
|
<!-- <version>1.11.3</version>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<distributionManagement>
|
|
||||||
<repository>
|
|
||||||
<id>nexus-release</id>
|
|
||||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
|
|
||||||
</repository>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>nexus-snapshot</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
</distributionManagement>
|
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>store</id>
|
||||||
|
<url>http://117.33.142.185:8081/repository/store/</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>store</id>
|
||||||
|
<url>http://117.33.142.185:8081/repository/store/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>maven-public</id>
|
||||||
<name>Maven Central</name>
|
<url>http://117.33.142.185:8081/repository/maven-public/</url>
|
||||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
<snapshots>
|
||||||
<layout>default</layout>
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
<releases>
|
<releases>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</releases>
|
</releases>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package io.github.yezhihao.netmc;
|
package com.dust.tripartite.netmc;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.codec.Delimiter;
|
import com.dust.tripartite.netmc.codec.LengthField;
|
||||||
import io.github.yezhihao.netmc.codec.LengthField;
|
import com.dust.tripartite.netmc.codec.MessageEncoder;
|
||||||
import io.github.yezhihao.netmc.codec.MessageDecoder;
|
import com.dust.tripartite.netmc.core.HandlerInterceptor;
|
||||||
import io.github.yezhihao.netmc.codec.MessageEncoder;
|
import com.dust.tripartite.netmc.core.HandlerMapping;
|
||||||
import io.github.yezhihao.netmc.core.HandlerInterceptor;
|
import com.dust.tripartite.netmc.session.SessionListener;
|
||||||
import io.github.yezhihao.netmc.core.HandlerMapping;
|
import com.dust.tripartite.netmc.codec.Delimiter;
|
||||||
import io.github.yezhihao.netmc.session.SessionListener;
|
import com.dust.tripartite.netmc.codec.MessageDecoder;
|
||||||
import io.github.yezhihao.netmc.session.SessionManager;
|
import com.dust.tripartite.netmc.session.SessionManager;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,9 +1,9 @@
|
||||||
package io.github.yezhihao.netmc;
|
package com.dust.tripartite.netmc;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.codec.DelimiterBasedFrameDecoder;
|
import com.dust.tripartite.netmc.codec.DelimiterBasedFrameDecoder;
|
||||||
import io.github.yezhihao.netmc.codec.LengthFieldAndDelimiterFrameDecoder;
|
import com.dust.tripartite.netmc.codec.LengthFieldAndDelimiterFrameDecoder;
|
||||||
import io.github.yezhihao.netmc.codec.MessageDecoderWrapper;
|
import com.dust.tripartite.netmc.codec.MessageDecoderWrapper;
|
||||||
import io.github.yezhihao.netmc.codec.MessageEncoderWrapper;
|
import com.dust.tripartite.netmc.codec.MessageEncoderWrapper;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
@ -20,6 +20,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yezhihao
|
* @author yezhihao
|
||||||
|
@ -28,13 +29,13 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class TCPServer {
|
public class TCPServer {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(TCPServer.class);
|
private static final Logger log = LoggerFactory.getLogger(TCPServer.class);
|
||||||
private volatile boolean isRunning = false;
|
private final AtomicBoolean isRunning = new AtomicBoolean(false);
|
||||||
|
|
||||||
private EventLoopGroup bossGroup = null;
|
private EventLoopGroup bossGroup = null;
|
||||||
private EventLoopGroup workerGroup = null;
|
private EventLoopGroup workerGroup = null;
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
private NettyConfig config;
|
private final NettyConfig config;
|
||||||
|
|
||||||
public TCPServer(String name, NettyConfig config) {
|
public TCPServer(String name, NettyConfig config) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -53,8 +54,8 @@ public class TCPServer {
|
||||||
.childOption(NioChannelOption.TCP_NODELAY, true)
|
.childOption(NioChannelOption.TCP_NODELAY, true)
|
||||||
.childHandler(new ChannelInitializer<NioSocketChannel>() {
|
.childHandler(new ChannelInitializer<NioSocketChannel>() {
|
||||||
|
|
||||||
private MessageEncoderWrapper messageEncoderWrapper = new MessageEncoderWrapper(config.encoder);
|
private final MessageEncoderWrapper messageEncoderWrapper = new MessageEncoderWrapper(config.encoder);
|
||||||
private MessageDecoderWrapper messageDecoderWrapper = new MessageDecoderWrapper(config.decoder);
|
private final MessageDecoderWrapper messageDecoderWrapper = new MessageDecoderWrapper(config.decoder);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initChannel(NioSocketChannel channel) {
|
public void initChannel(NioSocketChannel channel) {
|
||||||
|
@ -71,7 +72,7 @@ public class TCPServer {
|
||||||
log.warn("==={}启动成功, port={}===", name, config.port);
|
log.warn("==={}启动成功, port={}===", name, config.port);
|
||||||
channelFuture.channel().closeFuture().sync();
|
channelFuture.channel().closeFuture().sync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("==={}出现异常, port={}===", e);
|
log.warn("==={}出现异常, port={}===", e, config.port);
|
||||||
} finally {
|
} finally {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
@ -83,29 +84,27 @@ public class TCPServer {
|
||||||
return new LengthFieldAndDelimiterFrameDecoder(config.maxFrameLength, config.lengthField, config.delimiter);
|
return new LengthFieldAndDelimiterFrameDecoder(config.maxFrameLength, config.lengthField, config.delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void start() {
|
public void start() {
|
||||||
if (this.isRunning) {
|
if (!isRunning.compareAndSet(false, true)) {
|
||||||
log.warn("==={}已经启动, port={}===", name, config.port);
|
log.warn("==={}已经启动, port={}===", name, config.port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.isRunning = true;
|
new Thread(this::startInternal).start();
|
||||||
new Thread(() -> startInternal()).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void stop() {
|
public void stop() {
|
||||||
if (!this.isRunning) {
|
if (!isRunning.compareAndSet(true, false)) {
|
||||||
log.warn("==={}已经停止, port={}===", name, config.port);
|
log.warn("==={}已经停止, port={}===", name, config.port);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.isRunning = false;
|
Future<?> future = this.bossGroup.shutdownGracefully();
|
||||||
|
if (!future.isSuccess()) {
|
||||||
Future future = this.bossGroup.shutdownGracefully();
|
|
||||||
if (!future.isSuccess())
|
|
||||||
log.warn("bossGroup 无法正常停止", future.cause());
|
log.warn("bossGroup 无法正常停止", future.cause());
|
||||||
|
}
|
||||||
future = this.workerGroup.shutdownGracefully();
|
future = this.workerGroup.shutdownGracefully();
|
||||||
if (!future.isSuccess())
|
if (!future.isSuccess()) {
|
||||||
log.warn("workerGroup 无法正常停止", future.cause());
|
log.warn("workerGroup 无法正常停止", future.cause());
|
||||||
|
}
|
||||||
log.warn("==={}已经停止, port={}===", name, config.port);
|
log.warn("==={}已经停止, port={}===", name, config.port);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
package io.github.yezhihao.netmc;
|
package com.dust.tripartite.netmc;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.HandlerInterceptor;
|
import com.dust.tripartite.netmc.core.HandlerInterceptor;
|
||||||
import io.github.yezhihao.netmc.core.HandlerMapping;
|
import com.dust.tripartite.netmc.core.HandlerMapping;
|
||||||
import io.github.yezhihao.netmc.core.handler.Handler;
|
import com.dust.tripartite.netmc.core.handler.Handler;
|
||||||
import io.github.yezhihao.netmc.core.model.Message;
|
import com.dust.tripartite.netmc.core.model.Message;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.github.yezhihao.netmc.session.SessionListener;
|
import com.dust.tripartite.netmc.session.SessionListener;
|
||||||
import io.github.yezhihao.netmc.session.SessionManager;
|
import com.dust.tripartite.netmc.session.SessionManager;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -27,13 +27,13 @@ public class TCPServerHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(TCPServerHandler.class.getSimpleName());
|
private static final Logger log = LoggerFactory.getLogger(TCPServerHandler.class.getSimpleName());
|
||||||
|
|
||||||
private HandlerMapping handlerMapping;
|
private final HandlerMapping handlerMapping;
|
||||||
|
|
||||||
private HandlerInterceptor interceptor;
|
private final HandlerInterceptor interceptor;
|
||||||
|
|
||||||
private SessionManager sessionManager;
|
private final SessionManager sessionManager;
|
||||||
|
|
||||||
private SessionListener sessionListener;
|
private final SessionListener sessionListener;
|
||||||
|
|
||||||
public TCPServerHandler(HandlerMapping handlerMapping,
|
public TCPServerHandler(HandlerMapping handlerMapping,
|
||||||
HandlerInterceptor interceptor,
|
HandlerInterceptor interceptor,
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
public class Delimiter {
|
public class Delimiter {
|
||||||
protected byte[] value;
|
protected byte[] value;
|
|
@ -1,11 +1,11 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
import io.netty.util.internal.ObjectUtil;
|
import io.netty.util.internal.ObjectUtil;
|
||||||
import io.github.yezhihao.netmc.util.ByteBufUtils;
|
import com.dust.tripartite.netmc.util.ByteBufUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
|
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||||
// Try all delimiters and choose the delimiter which yields the shortest frame.
|
// Try all delimiters and choose the delimiter which yields the shortest frame.
|
||||||
int minFrameLength = Integer.MAX_VALUE;
|
int minFrameLength = Integer.MAX_VALUE;
|
||||||
Delimiter minDelim = null;
|
Delimiter minDelim = null;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import static io.netty.util.internal.ObjectUtil.checkPositive;
|
import static io.netty.util.internal.ObjectUtil.checkPositive;
|
||||||
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
|
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
|
|
@ -1,12 +1,12 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
|
import com.dust.tripartite.netmc.util.ByteBufUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.CorruptedFrameException;
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
import io.netty.handler.codec.DecoderException;
|
import io.netty.handler.codec.DecoderException;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
import io.netty.util.internal.ObjectUtil;
|
import io.netty.util.internal.ObjectUtil;
|
||||||
import io.github.yezhihao.netmc.util.ByteBufUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class LengthFieldAndDelimiterFrameDecoder extends DelimiterBasedFrameDeco
|
||||||
throw new CorruptedFrameException("Adjusted frame length (" + frameLength + ") is less than initialBytesToStrip: " + initialBytesToStrip);
|
throw new CorruptedFrameException("Adjusted frame length (" + frameLength + ") is less than initialBytesToStrip: " + initialBytesToStrip);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) {
|
||||||
if (in.readableBytes() < this.lengthFieldEndOffset) {
|
if (in.readableBytes() < this.lengthFieldEndOffset) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
|
@ -1,6 +1,6 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,6 +1,6 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
|
@ -16,7 +16,7 @@ import io.netty.handler.codec.DecoderException;
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class MessageDecoderWrapper extends ChannelInboundHandlerAdapter {
|
public class MessageDecoderWrapper extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
private MessageDecoder decoder;
|
private final MessageDecoder decoder;
|
||||||
|
|
||||||
public MessageDecoderWrapper(MessageDecoder decoder) {
|
public MessageDecoderWrapper(MessageDecoder decoder) {
|
||||||
this.decoder = decoder;
|
this.decoder = decoder;
|
|
@ -1,6 +1,6 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,6 +1,6 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
|
@ -17,7 +17,7 @@ import io.netty.handler.codec.EncoderException;
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class MessageEncoderWrapper extends ChannelOutboundHandlerAdapter {
|
public class MessageEncoderWrapper extends ChannelOutboundHandlerAdapter {
|
||||||
|
|
||||||
private MessageEncoder encoder;
|
private final MessageEncoder encoder;
|
||||||
|
|
||||||
public MessageEncoderWrapper(MessageEncoder encoder) {
|
public MessageEncoderWrapper(MessageEncoder encoder) {
|
||||||
this.encoder = encoder;
|
this.encoder = encoder;
|
|
@ -1,10 +1,10 @@
|
||||||
package io.github.yezhihao.netmc.core;
|
package com.dust.tripartite.netmc.core;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.annotation.AsyncBatch;
|
import com.dust.tripartite.netmc.core.annotation.AsyncBatch;
|
||||||
import io.github.yezhihao.netmc.core.annotation.Mapping;
|
import com.dust.tripartite.netmc.core.annotation.Mapping;
|
||||||
import io.github.yezhihao.netmc.core.handler.AsyncBatchHandler;
|
import com.dust.tripartite.netmc.core.handler.AsyncBatchHandler;
|
||||||
import io.github.yezhihao.netmc.core.handler.Handler;
|
import com.dust.tripartite.netmc.core.handler.Handler;
|
||||||
import io.github.yezhihao.netmc.core.handler.SimpleHandler;
|
import com.dust.tripartite.netmc.core.handler.SimpleHandler;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -17,7 +17,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHandlerMapping implements HandlerMapping {
|
public abstract class AbstractHandlerMapping implements HandlerMapping {
|
||||||
|
|
||||||
private final Map<Object, Handler> handlerMap = new HashMap(60);
|
private final Map<Object, Handler> handlerMap = new HashMap<>(64);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将Endpoint中被@Mapping标记的方法注册到映射表
|
* 将Endpoint中被@Mapping标记的方法注册到映射表
|
||||||
|
@ -25,8 +25,6 @@ public abstract class AbstractHandlerMapping implements HandlerMapping {
|
||||||
protected synchronized void registerHandlers(Object bean) {
|
protected synchronized void registerHandlers(Object bean) {
|
||||||
Class<?> beanClass = bean.getClass();
|
Class<?> beanClass = bean.getClass();
|
||||||
Method[] methods = beanClass.getDeclaredMethods();
|
Method[] methods = beanClass.getDeclaredMethods();
|
||||||
if (methods == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package io.github.yezhihao.netmc.core;
|
package com.dust.tripartite.netmc.core;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.annotation.Endpoint;
|
import com.dust.tripartite.netmc.util.ClassUtils;
|
||||||
import io.github.yezhihao.netmc.util.ClassUtils;
|
import com.dust.tripartite.netmc.core.annotation.Endpoint;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package io.github.yezhihao.netmc.core;
|
package com.dust.tripartite.netmc.core;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.model.Message;
|
import com.dust.tripartite.netmc.core.model.Message;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息拦截器
|
* 消息拦截器
|
||||||
|
@ -9,18 +9,18 @@ import io.github.yezhihao.netmc.session.Session;
|
||||||
* home https://gitee.com/yezhihao/jt808-server
|
* home https://gitee.com/yezhihao/jt808-server
|
||||||
*/
|
*/
|
||||||
public interface HandlerInterceptor<T extends Message> {
|
public interface HandlerInterceptor<T extends Message> {
|
||||||
/** 未找到对应的Handle */
|
/** @return Response 未找到对应的Handle */
|
||||||
T notSupported(T request, Session session);
|
T notSupported(T request, Session session);
|
||||||
|
|
||||||
/** 调用之前 */
|
/** @return boolean 调用之前 */
|
||||||
boolean beforeHandle(T request, Session session);
|
boolean beforeHandle(T request, Session session);
|
||||||
|
|
||||||
/** 调用之后,返回值为void的 */
|
/** @return Response 调用之后,返回值为void的 */
|
||||||
T successful(T request, Session session);
|
T successful(T request, Session session);
|
||||||
|
|
||||||
/** 调用之后,有返回值的 */
|
/** 调用之后,有返回值的 */
|
||||||
void afterHandle(T request, T response, Session session);
|
void afterHandle(T request, T response, Session session);
|
||||||
|
|
||||||
/** 调用之后抛出异常的 */
|
/** @return Response 调用之后抛出异常的 */
|
||||||
T exceptional(T request, Session session, Exception e);
|
T exceptional(T request, Session session, Exception e);
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package io.github.yezhihao.netmc.core;
|
package com.dust.tripartite.netmc.core;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.handler.Handler;
|
import com.dust.tripartite.netmc.core.handler.Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息映射接口
|
* 消息映射接口
|
|
@ -1,6 +1,6 @@
|
||||||
package io.github.yezhihao.netmc.core;
|
package com.dust.tripartite.netmc.core;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.annotation.Endpoint;
|
import com.dust.tripartite.netmc.core.annotation.Endpoint;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.core.annotation;
|
package com.dust.tripartite.netmc.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.core.annotation;
|
package com.dust.tripartite.netmc.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.core.annotation;
|
package com.dust.tripartite.netmc.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package io.github.yezhihao.netmc.core.handler;
|
package com.dust.tripartite.netmc.core.handler;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.model.Message;
|
import com.dust.tripartite.netmc.core.model.Message;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.github.yezhihao.netmc.util.BasicThreadFactory;
|
import com.dust.tripartite.netmc.util.BasicThreadFactory;
|
||||||
import io.github.yezhihao.netmc.util.VirtualList;
|
import com.dust.tripartite.netmc.util.VirtualList;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -23,17 +23,17 @@ public class AsyncBatchHandler extends Handler {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(AsyncBatchHandler.class.getSimpleName());
|
private static final Logger log = LoggerFactory.getLogger(AsyncBatchHandler.class.getSimpleName());
|
||||||
|
|
||||||
private ConcurrentLinkedQueue<Message> queue;
|
private final ConcurrentLinkedQueue<Message> queue;
|
||||||
|
|
||||||
private ThreadPoolExecutor executor;
|
private final ThreadPoolExecutor executor;
|
||||||
|
|
||||||
private int poolSize;
|
private final int poolSize;
|
||||||
|
|
||||||
private int maxElements;
|
private final int maxElements;
|
||||||
|
|
||||||
private int maxWait;
|
private final int maxWait;
|
||||||
|
|
||||||
private int warningLines;
|
private final int warningLines;
|
||||||
|
|
||||||
public AsyncBatchHandler(Object actionClass, Method actionMethod, String desc, int poolSize, int maxElements, int maxWait) {
|
public AsyncBatchHandler(Object actionClass, Method actionMethod, String desc, int poolSize, int maxElements, int maxWait) {
|
||||||
super(actionClass, actionMethod, desc);
|
super(actionClass, actionMethod, desc);
|
||||||
|
@ -50,8 +50,7 @@ public class AsyncBatchHandler extends Handler {
|
||||||
this.warningLines = maxElements * poolSize * 50;
|
this.warningLines = maxElements * poolSize * 50;
|
||||||
|
|
||||||
this.queue = new ConcurrentLinkedQueue();
|
this.queue = new ConcurrentLinkedQueue();
|
||||||
this.executor = new ThreadPoolExecutor(this.poolSize, this.poolSize, 1000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(400),
|
this.executor = new ThreadPoolExecutor(this.poolSize, this.poolSize, 1000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(400), new BasicThreadFactory.Builder().daemon(true).namingPattern(actionMethod.getName() + "-pool-%d").build());
|
||||||
new BasicThreadFactory.Builder().daemon(true).namingPattern(actionMethod.getName() + "-pool-%d").build());
|
|
||||||
|
|
||||||
for (int i = 0; i < poolSize; i++) {
|
for (int i = 0; i < poolSize; i++) {
|
||||||
boolean master = i == 0;
|
boolean master = i == 0;
|
||||||
|
@ -65,7 +64,7 @@ public class AsyncBatchHandler extends Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message invoke(Message request, Session session) {
|
public <T extends Message> T invoke(T request, Session session) {
|
||||||
queue.offer(request);
|
queue.offer(request);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package io.github.yezhihao.netmc.core.handler;
|
package com.dust.tripartite.netmc.core.handler;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.model.Message;
|
import com.dust.tripartite.netmc.core.model.Message;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
|
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -34,7 +34,7 @@ public abstract class Handler {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
Type type = types[i];
|
Type type = types[i];
|
||||||
Class clazz;
|
Class<?> clazz;
|
||||||
if (type instanceof ParameterizedTypeImpl)
|
if (type instanceof ParameterizedTypeImpl)
|
||||||
clazz = (Class<?>) ((ParameterizedTypeImpl) type).getActualTypeArguments()[0];
|
clazz = (Class<?>) ((ParameterizedTypeImpl) type).getActualTypeArguments()[0];
|
||||||
else
|
else
|
|
@ -1,7 +1,7 @@
|
||||||
package io.github.yezhihao.netmc.core.handler;
|
package com.dust.tripartite.netmc.core.handler;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.model.Message;
|
import com.dust.tripartite.netmc.core.model.Message;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public class SimpleHandler extends Handler {
|
||||||
super(actionClass, actionMethod, desc);
|
super(actionClass, actionMethod, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message invoke(Message request, Session session) throws Exception {
|
public <T extends Message> T invoke(T request, Session session) throws Exception {
|
||||||
return super.invoke(request, session);
|
return super.invoke(request, session);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.core.model;
|
package com.dust.tripartite.netmc.core.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.core.model;
|
package com.dust.tripartite.netmc.core.model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yezhihao
|
* @author yezhihao
|
|
@ -1,7 +1,7 @@
|
||||||
package io.github.yezhihao.netmc.session;
|
package com.dust.tripartite.netmc.session;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.model.Message;
|
import com.dust.tripartite.netmc.core.model.Message;
|
||||||
import io.github.yezhihao.netmc.core.model.Response;
|
import com.dust.tripartite.netmc.core.model.Response;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.session;
|
package com.dust.tripartite.netmc.session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yezhihao
|
* @author yezhihao
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.session;
|
package com.dust.tripartite.netmc.session;
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import java.util.AbstractCollection;
|
import java.util.AbstractCollection;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import java.util.AbstractSet;
|
import java.util.AbstractSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -8,7 +8,6 @@ import java.lang.annotation.Annotation;
|
||||||
import java.net.JarURLConnection;
|
import java.net.JarURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
|
@ -24,17 +23,12 @@ public class ClassUtils {
|
||||||
|
|
||||||
public static List<Class<?>> getClassList(String packageName, Class<? extends Annotation> annotationClass) {
|
public static List<Class<?>> getClassList(String packageName, Class<? extends Annotation> annotationClass) {
|
||||||
List<Class<?>> classList = getClassList(packageName);
|
List<Class<?>> classList = getClassList(packageName);
|
||||||
Iterator<Class<?>> iterator = classList.iterator();
|
classList.removeIf(next -> !next.isAnnotationPresent(annotationClass));
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Class<?> next = iterator.next();
|
|
||||||
if (!next.isAnnotationPresent(annotationClass))
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
return classList;
|
return classList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Class<?>> getClassList(String packageName) {
|
public static List<Class<?>> getClassList(String packageName) {
|
||||||
List<Class<?>> classList = new LinkedList();
|
List<Class<?>> classList = new LinkedList<>();
|
||||||
String path = packageName.replace(".", "/");
|
String path = packageName.replace(".", "/");
|
||||||
try {
|
try {
|
||||||
Enumeration<URL> urls = ClassUtils.getClassLoader().getResources(path);
|
Enumeration<URL> urls = ClassUtils.getClassLoader().getResources(path);
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.util;
|
package com.dust.tripartite.netmc.util;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
|
@ -1,10 +1,10 @@
|
||||||
package io.github.yezhihao.netmc;
|
package com.dust.tripartite.netmc;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.DefaultHandlerMapping;
|
import com.dust.tripartite.netmc.codec.MyMessageDecoder;
|
||||||
import io.github.yezhihao.netmc.endpoint.MyHandlerInterceptor;
|
import com.dust.tripartite.netmc.codec.MyMessageEncoder;
|
||||||
import io.github.yezhihao.netmc.codec.MyMessageDecoder;
|
import com.dust.tripartite.netmc.core.DefaultHandlerMapping;
|
||||||
import io.github.yezhihao.netmc.codec.MyMessageEncoder;
|
import com.dust.tripartite.netmc.endpoint.MyHandlerInterceptor;
|
||||||
import io.github.yezhihao.netmc.session.SessionManager;
|
import com.dust.tripartite.netmc.session.SessionManager;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc;
|
package com.dust.tripartite.netmc;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.model.MyHeader;
|
import com.dust.tripartite.netmc.model.MyHeader;
|
||||||
import io.github.yezhihao.netmc.model.MyMessage;
|
import com.dust.tripartite.netmc.model.MyMessage;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
|
@ -1,8 +1,8 @@
|
||||||
package io.github.yezhihao.netmc.codec;
|
package com.dust.tripartite.netmc.codec;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.model.MyHeader;
|
import com.dust.tripartite.netmc.model.MyHeader;
|
||||||
import io.github.yezhihao.netmc.model.MyMessage;
|
import com.dust.tripartite.netmc.model.MyMessage;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.dust.tripartite.netmc.endpoint;
|
||||||
|
|
||||||
|
import com.dust.tripartite.netmc.core.annotation.Endpoint;
|
||||||
|
import com.dust.tripartite.netmc.core.annotation.Mapping;
|
||||||
|
import com.dust.tripartite.netmc.model.MyMessage;
|
||||||
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
|
|
||||||
|
@Endpoint
|
||||||
|
public class MyEndpoint {
|
||||||
|
|
||||||
|
@Mapping(types = 1, desc = "注册")
|
||||||
|
public void register(MyMessage request, Session session) {
|
||||||
|
System.out.println(request);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
package io.github.yezhihao.netmc.endpoint;
|
package com.dust.tripartite.netmc.endpoint;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.HandlerInterceptor;
|
import com.dust.tripartite.netmc.core.HandlerInterceptor;
|
||||||
import io.github.yezhihao.netmc.model.MyHeader;
|
import com.dust.tripartite.netmc.model.MyHeader;
|
||||||
import io.github.yezhihao.netmc.model.MyMessage;
|
import com.dust.tripartite.netmc.model.MyMessage;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.yezhihao.netmc.model;
|
package com.dust.tripartite.netmc.model;
|
||||||
|
|
||||||
public class MyHeader {
|
public class MyHeader {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package io.github.yezhihao.netmc.model;
|
package com.dust.tripartite.netmc.model;
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.model.Message;
|
import com.dust.tripartite.netmc.core.model.Message;
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
import com.dust.tripartite.netmc.session.Session;
|
||||||
|
|
||||||
public class MyMessage implements Message {
|
public class MyMessage implements Message {
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package io.github.yezhihao.netmc.endpoint;
|
|
||||||
|
|
||||||
import io.github.yezhihao.netmc.core.annotation.Endpoint;
|
|
||||||
import io.github.yezhihao.netmc.core.annotation.Mapping;
|
|
||||||
import io.github.yezhihao.netmc.model.MyMessage;
|
|
||||||
import io.github.yezhihao.netmc.session.Session;
|
|
||||||
|
|
||||||
@Endpoint
|
|
||||||
public class MyEndpoint {
|
|
||||||
|
|
||||||
@Mapping(types = 1, desc = "注册")
|
|
||||||
public void register(MyMessage request, Session session) {
|
|
||||||
System.out.println(request);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue