Compare commits

...

10 Commits

Author SHA1 Message Date
axzsd 8142655a37 nexus-releases 2023-05-25 17:04:38 +08:00
wanglong e8f8f1d925 nexus-releases 2021-11-13 14:14:17 +08:00
wanglong 6ad1f5f712 注释掉maven-gpg-plugin 2021-11-13 12:12:23 +08:00
wanglong 29070514ba 注释掉maven-gpg-plugin 2021-11-13 12:10:40 +08:00
wanglong 8aae04dbab update caffeine version 2021-11-13 12:07:12 +08:00
wanglong 55be772fc0 update caffeine version 2021-11-13 12:00:35 +08:00
wanglong 99b50ab2d2 rename package 2021-11-13 11:56:53 +08:00
剑器近 8e6f35ae2a deployed 2.0.6.RELEASE,优化部分代码、升级相关依赖 2021-11-10 17:55:14 +08:00
剑器近 9131645204 优化部分代码 2021-11-10 16:52:26 +08:00
剑器近 6339e56b43 deployed 2.0.5.RELEASE 2021-08-06 17:55:52 +08:00
46 changed files with 226 additions and 247 deletions

View File

@ -8,12 +8,11 @@
* TCP协议服务端开发
## 代码仓库
* Gitee仓库地址[https://gitee.com/yezhihao/netmc/tree/master](https://gitee.com/yezhihao/netmc/tree/master)
* Github仓库地址[https://github.com/yezhihao/netmc/tree/master](https://github.com/yezhihao/netmc/tree/master)
* Gitee仓库地址[http://115.29.108.160:3000/TripartiteOpenSource/netmc](http://115.29.108.160:3000/TripartiteOpenSource/netmc)
* 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`
* Github下载命令`git clone https://github.com/yezhihao/netmc -b master`
* Git下载命令`git clone http://115.29.108.160:3000/TripartiteOpenSource/netmc.git -b master`
## 项目结构
```sh
@ -72,10 +71,4 @@ public class JT808Endpoint {
详细的例子请参考Test目录
使用该组件的项目:[https://gitee.com/yezhihao/jt808-server/tree/master](https://gitee.com/yezhihao/jt808-server/tree/master)
项目会不定期进行更新建议star和watch一份您的支持是我最大的动力。
如有任何疑问或者BUG请联系我非常感谢。
技术交流QQ群[906230542]
当前项目是Fork [剑器近](https://gitee.com/yezhihao) 的 [netmc](https://gitee.com/yezhihao/netmc?_from=gitee_search)

122
pom.xml
View File

@ -1,9 +1,10 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.yezhihao</groupId>
<groupId>com.dust.tripartite</groupId>
<artifactId>netmc</artifactId>
<version>2.0.4.RELEASE</version>
<version>2.0.6.RELEASE</version>
<packaging>jar</packaging>
<name>Netmc</name>
@ -18,25 +19,17 @@
</licenses>
<scm>
<url>https://github.com/yezhihao/netmc</url>
<connection>https://github.com/yezhihao/netmc.git</connection>
<url>http://115.29.108.160:3000/TripartiteOpenSource/netmc</url>
<connection>http://115.29.108.160:3000/TripartiteOpenSource/netmc.git</connection>
</scm>
<developers>
<developer>
<id>netmc.yezhihao</id>
<name>netmc</name>
<email>zhihao.ye@qq.com</email>
</developer>
</developers>
<properties>
<java.version>1.8</java.version>
<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.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>
</properties>
@ -62,26 +55,26 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.1.66.Final</version>
<version>4.1.70.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.8</version>
<version>3.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.9</version>
<version>5.3.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>nexus-release</id>
<id>nexus-releases</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
@ -103,7 +96,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
<executions>
<execution>
<phase>package</phase>
@ -113,20 +106,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!-- <version>3.0.1</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>sign-artifacts</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -143,6 +136,7 @@
<version>2.5.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
@ -155,43 +149,45 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>central-nexus</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.11.2</version>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.sonatype.plugins</groupId>-->
<!-- <artifactId>nexus-staging-maven-plugin</artifactId>-->
<!-- <version>1.6.8</version>-->
<!-- <extensions>true</extensions>-->
<!-- <configuration>-->
<!-- <serverId>central-nexus</serverId>-->
<!-- <nexusUrl>https://oss.sonatype.org/</nexusUrl>-->
<!-- <autoReleaseAfterClose>true</autoReleaseAfterClose>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-scm-plugin</artifactId>-->
<!-- <version>1.11.3</version>-->
<!-- </plugin>-->
</plugins>
</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>
</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>
<repository>
<id>central</id>
<name>Maven Central</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<layout>default</layout>
<id>maven-public</id>
<url>http://117.33.142.185:8081/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>

View File

@ -1,13 +1,13 @@
package io.github.yezhihao.netmc;
package com.dust.tripartite.netmc;
import io.github.yezhihao.netmc.codec.Delimiter;
import io.github.yezhihao.netmc.codec.LengthField;
import io.github.yezhihao.netmc.codec.MessageDecoder;
import io.github.yezhihao.netmc.codec.MessageEncoder;
import io.github.yezhihao.netmc.core.HandlerInterceptor;
import io.github.yezhihao.netmc.core.HandlerMapping;
import io.github.yezhihao.netmc.session.SessionListener;
import io.github.yezhihao.netmc.session.SessionManager;
import com.dust.tripartite.netmc.codec.LengthField;
import com.dust.tripartite.netmc.codec.MessageEncoder;
import com.dust.tripartite.netmc.core.HandlerInterceptor;
import com.dust.tripartite.netmc.core.HandlerMapping;
import com.dust.tripartite.netmc.session.SessionListener;
import com.dust.tripartite.netmc.codec.Delimiter;
import com.dust.tripartite.netmc.codec.MessageDecoder;
import com.dust.tripartite.netmc.session.SessionManager;
import io.netty.channel.ChannelInboundHandlerAdapter;
/**

View File

@ -1,9 +1,9 @@
package io.github.yezhihao.netmc;
package com.dust.tripartite.netmc;
import io.github.yezhihao.netmc.codec.DelimiterBasedFrameDecoder;
import io.github.yezhihao.netmc.codec.LengthFieldAndDelimiterFrameDecoder;
import io.github.yezhihao.netmc.codec.MessageDecoderWrapper;
import io.github.yezhihao.netmc.codec.MessageEncoderWrapper;
import com.dust.tripartite.netmc.codec.DelimiterBasedFrameDecoder;
import com.dust.tripartite.netmc.codec.LengthFieldAndDelimiterFrameDecoder;
import com.dust.tripartite.netmc.codec.MessageDecoderWrapper;
import com.dust.tripartite.netmc.codec.MessageEncoderWrapper;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
@ -20,6 +20,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author yezhihao
@ -28,13 +29,13 @@ import java.util.concurrent.TimeUnit;
public class TCPServer {
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 workerGroup = null;
private String name;
private NettyConfig config;
private final String name;
private final NettyConfig config;
public TCPServer(String name, NettyConfig config) {
this.name = name;
@ -53,8 +54,8 @@ public class TCPServer {
.childOption(NioChannelOption.TCP_NODELAY, true)
.childHandler(new ChannelInitializer<NioSocketChannel>() {
private MessageEncoderWrapper messageEncoderWrapper = new MessageEncoderWrapper(config.encoder);
private MessageDecoderWrapper messageDecoderWrapper = new MessageDecoderWrapper(config.decoder);
private final MessageEncoderWrapper messageEncoderWrapper = new MessageEncoderWrapper(config.encoder);
private final MessageDecoderWrapper messageDecoderWrapper = new MessageDecoderWrapper(config.decoder);
@Override
public void initChannel(NioSocketChannel channel) {
@ -71,7 +72,7 @@ public class TCPServer {
log.warn("==={}启动成功, port={}===", name, config.port);
channelFuture.channel().closeFuture().sync();
} catch (Exception e) {
log.warn("==={}出现异常, port={}===", e);
log.warn("==={}出现异常, port={}===", e, config.port);
} finally {
stop();
}
@ -83,29 +84,27 @@ public class TCPServer {
return new LengthFieldAndDelimiterFrameDecoder(config.maxFrameLength, config.lengthField, config.delimiter);
}
public synchronized void start() {
if (this.isRunning) {
public void start() {
if (!isRunning.compareAndSet(false, true)) {
log.warn("==={}已经启动, port={}===", name, config.port);
return;
}
this.isRunning = true;
new Thread(() -> startInternal()).start();
new Thread(this::startInternal).start();
}
public synchronized void stop() {
if (!this.isRunning) {
public void stop() {
if (!isRunning.compareAndSet(true, false)) {
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());
}
future = this.workerGroup.shutdownGracefully();
if (!future.isSuccess())
if (!future.isSuccess()) {
log.warn("workerGroup 无法正常停止", future.cause());
}
log.warn("==={}已经停止, port={}===", name, config.port);
}
}

View File

@ -1,12 +1,12 @@
package io.github.yezhihao.netmc;
package com.dust.tripartite.netmc;
import io.github.yezhihao.netmc.core.HandlerInterceptor;
import io.github.yezhihao.netmc.core.HandlerMapping;
import io.github.yezhihao.netmc.core.handler.Handler;
import io.github.yezhihao.netmc.core.model.Message;
import io.github.yezhihao.netmc.session.Session;
import io.github.yezhihao.netmc.session.SessionListener;
import io.github.yezhihao.netmc.session.SessionManager;
import com.dust.tripartite.netmc.core.HandlerInterceptor;
import com.dust.tripartite.netmc.core.HandlerMapping;
import com.dust.tripartite.netmc.core.handler.Handler;
import com.dust.tripartite.netmc.core.model.Message;
import com.dust.tripartite.netmc.session.Session;
import com.dust.tripartite.netmc.session.SessionListener;
import com.dust.tripartite.netmc.session.SessionManager;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
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 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,
HandlerInterceptor interceptor,

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.codec;
package com.dust.tripartite.netmc.codec;
public class Delimiter {
protected byte[] value;

View File

@ -1,11 +1,11 @@
package io.github.yezhihao.netmc.codec;
package com.dust.tripartite.netmc.codec;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.internal.ObjectUtil;
import io.github.yezhihao.netmc.util.ByteBufUtils;
import com.dust.tripartite.netmc.util.ByteBufUtils;
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.
int minFrameLength = Integer.MAX_VALUE;
Delimiter minDelim = null;

View File

@ -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.checkPositiveOrZero;

View File

@ -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.channel.ChannelHandlerContext;
import io.netty.handler.codec.CorruptedFrameException;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.internal.ObjectUtil;
import io.github.yezhihao.netmc.util.ByteBufUtils;
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);
}
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) {
if (in.readableBytes() < this.lengthFieldEndOffset) {
return null;
} else {

View File

@ -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;
/**

View File

@ -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.ByteBufUtil;
import io.netty.channel.ChannelHandler;
@ -16,7 +16,7 @@ import io.netty.handler.codec.DecoderException;
@ChannelHandler.Sharable
public class MessageDecoderWrapper extends ChannelInboundHandlerAdapter {
private MessageDecoder decoder;
private final MessageDecoder decoder;
public MessageDecoderWrapper(MessageDecoder decoder) {
this.decoder = decoder;

View File

@ -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;
/**

View File

@ -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.Unpooled;
import io.netty.channel.ChannelHandler;
@ -17,7 +17,7 @@ import io.netty.handler.codec.EncoderException;
@ChannelHandler.Sharable
public class MessageEncoderWrapper extends ChannelOutboundHandlerAdapter {
private MessageEncoder encoder;
private final MessageEncoder encoder;
public MessageEncoderWrapper(MessageEncoder encoder) {
this.encoder = encoder;

View File

@ -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 io.github.yezhihao.netmc.core.annotation.Mapping;
import io.github.yezhihao.netmc.core.handler.AsyncBatchHandler;
import io.github.yezhihao.netmc.core.handler.Handler;
import io.github.yezhihao.netmc.core.handler.SimpleHandler;
import com.dust.tripartite.netmc.core.annotation.AsyncBatch;
import com.dust.tripartite.netmc.core.annotation.Mapping;
import com.dust.tripartite.netmc.core.handler.AsyncBatchHandler;
import com.dust.tripartite.netmc.core.handler.Handler;
import com.dust.tripartite.netmc.core.handler.SimpleHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
@ -17,7 +17,7 @@ import java.util.Map;
*/
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
@ -25,8 +25,6 @@ public abstract class AbstractHandlerMapping implements HandlerMapping {
protected synchronized void registerHandlers(Object bean) {
Class<?> beanClass = bean.getClass();
Method[] methods = beanClass.getDeclaredMethods();
if (methods == null)
return;
for (Method method : methods) {

View File

@ -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 io.github.yezhihao.netmc.util.ClassUtils;
import com.dust.tripartite.netmc.util.ClassUtils;
import com.dust.tripartite.netmc.core.annotation.Endpoint;
import java.util.List;

View File

@ -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 io.github.yezhihao.netmc.session.Session;
import com.dust.tripartite.netmc.core.model.Message;
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
*/
public interface HandlerInterceptor<T extends Message> {
/** 未找到对应的Handle */
/** @return Response 未找到对应的Handle */
T notSupported(T request, Session session);
/** 调用之前 */
/** @return boolean 调用之前 */
boolean beforeHandle(T request, Session session);
/** 调用之后返回值为void的 */
/** @return Response 调用之后返回值为void的 */
T successful(T request, Session session);
/** 调用之后,有返回值的 */
void afterHandle(T request, T response, Session session);
/** 调用之后抛出异常的 */
/** @return Response 调用之后抛出异常的 */
T exceptional(T request, Session session, Exception e);
}

View File

@ -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;
/**
*

View File

@ -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.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.core.annotation;
package com.dust.tripartite.netmc.core.annotation;
import java.lang.annotation.*;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.core.annotation;
package com.dust.tripartite.netmc.core.annotation;
import java.lang.annotation.*;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.core.annotation;
package com.dust.tripartite.netmc.core.annotation;
import java.lang.annotation.*;

View File

@ -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 io.github.yezhihao.netmc.session.Session;
import io.github.yezhihao.netmc.util.BasicThreadFactory;
import io.github.yezhihao.netmc.util.VirtualList;
import com.dust.tripartite.netmc.core.model.Message;
import com.dust.tripartite.netmc.session.Session;
import com.dust.tripartite.netmc.util.BasicThreadFactory;
import com.dust.tripartite.netmc.util.VirtualList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -23,17 +23,17 @@ public class AsyncBatchHandler extends Handler {
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) {
super(actionClass, actionMethod, desc);
@ -50,8 +50,7 @@ public class AsyncBatchHandler extends Handler {
this.warningLines = maxElements * poolSize * 50;
this.queue = new ConcurrentLinkedQueue();
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());
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());
for (int i = 0; i < poolSize; i++) {
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);
return null;
}

View File

@ -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 io.github.yezhihao.netmc.session.Session;
import com.dust.tripartite.netmc.core.model.Message;
import com.dust.tripartite.netmc.session.Session;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import java.lang.reflect.Method;
@ -34,7 +34,7 @@ public abstract class Handler {
try {
for (int i = 0; i < types.length; i++) {
Type type = types[i];
Class clazz;
Class<?> clazz;
if (type instanceof ParameterizedTypeImpl)
clazz = (Class<?>) ((ParameterizedTypeImpl) type).getActualTypeArguments()[0];
else

View File

@ -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 io.github.yezhihao.netmc.session.Session;
import com.dust.tripartite.netmc.core.model.Message;
import com.dust.tripartite.netmc.session.Session;
import java.lang.reflect.Method;
@ -16,7 +16,7 @@ public class SimpleHandler extends Handler {
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);
}
}

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.core.model;
package com.dust.tripartite.netmc.core.model;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.core.model;
package com.dust.tripartite.netmc.core.model;
/**
* @author yezhihao

View File

@ -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 io.github.yezhihao.netmc.core.model.Response;
import com.dust.tripartite.netmc.core.model.Message;
import com.dust.tripartite.netmc.core.model.Response;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.session;
package com.dust.tripartite.netmc.session;
/**
* @author yezhihao

View File

@ -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.Caffeine;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.util;
package com.dust.tripartite.netmc.util;
import java.util.AbstractCollection;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.util;
package com.dust.tripartite.netmc.util;
import java.util.AbstractList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.util;
package com.dust.tripartite.netmc.util;
import java.util.AbstractMap;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.util;
package com.dust.tripartite.netmc.util;
import java.util.AbstractSet;
import java.util.Iterator;

View File

@ -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.ThreadFactory;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.util;
package com.dust.tripartite.netmc.util;
import io.netty.buffer.ByteBuf;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.util;
package com.dust.tripartite.netmc.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -8,7 +8,6 @@ import java.lang.annotation.Annotation;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.jar.JarEntry;
@ -24,17 +23,12 @@ public class ClassUtils {
public static List<Class<?>> getClassList(String packageName, Class<? extends Annotation> annotationClass) {
List<Class<?>> classList = getClassList(packageName);
Iterator<Class<?>> iterator = classList.iterator();
while (iterator.hasNext()) {
Class<?> next = iterator.next();
if (!next.isAnnotationPresent(annotationClass))
iterator.remove();
}
classList.removeIf(next -> !next.isAnnotationPresent(annotationClass));
return classList;
}
public static List<Class<?>> getClassList(String packageName) {
List<Class<?>> classList = new LinkedList();
List<Class<?>> classList = new LinkedList<>();
String path = packageName.replace(".", "/");
try {
Enumeration<URL> urls = ClassUtils.getClassLoader().getResources(path);

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.util;
package com.dust.tripartite.netmc.util;
import java.io.Serializable;
import java.util.*;

View File

@ -1,10 +1,10 @@
package io.github.yezhihao.netmc;
package com.dust.tripartite.netmc;
import io.github.yezhihao.netmc.core.DefaultHandlerMapping;
import io.github.yezhihao.netmc.endpoint.MyHandlerInterceptor;
import io.github.yezhihao.netmc.codec.MyMessageDecoder;
import io.github.yezhihao.netmc.codec.MyMessageEncoder;
import io.github.yezhihao.netmc.session.SessionManager;
import com.dust.tripartite.netmc.codec.MyMessageDecoder;
import com.dust.tripartite.netmc.codec.MyMessageEncoder;
import com.dust.tripartite.netmc.core.DefaultHandlerMapping;
import com.dust.tripartite.netmc.endpoint.MyHandlerInterceptor;
import com.dust.tripartite.netmc.session.SessionManager;
import java.nio.charset.StandardCharsets;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc;
package com.dust.tripartite.netmc;
import io.netty.buffer.ByteBufUtil;

View File

@ -1,8 +1,8 @@
package io.github.yezhihao.netmc.codec;
package com.dust.tripartite.netmc.codec;
import io.github.yezhihao.netmc.model.MyHeader;
import io.github.yezhihao.netmc.model.MyMessage;
import io.github.yezhihao.netmc.session.Session;
import com.dust.tripartite.netmc.model.MyHeader;
import com.dust.tripartite.netmc.model.MyMessage;
import com.dust.tripartite.netmc.session.Session;
import io.netty.buffer.ByteBuf;
import java.nio.charset.StandardCharsets;

View File

@ -1,8 +1,8 @@
package io.github.yezhihao.netmc.codec;
package com.dust.tripartite.netmc.codec;
import io.github.yezhihao.netmc.model.MyHeader;
import io.github.yezhihao.netmc.model.MyMessage;
import io.github.yezhihao.netmc.session.Session;
import com.dust.tripartite.netmc.model.MyHeader;
import com.dust.tripartite.netmc.model.MyMessage;
import com.dust.tripartite.netmc.session.Session;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

View File

@ -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);
}
}

View File

@ -1,9 +1,9 @@
package io.github.yezhihao.netmc.endpoint;
package com.dust.tripartite.netmc.endpoint;
import io.github.yezhihao.netmc.core.HandlerInterceptor;
import io.github.yezhihao.netmc.model.MyHeader;
import io.github.yezhihao.netmc.model.MyMessage;
import io.github.yezhihao.netmc.session.Session;
import com.dust.tripartite.netmc.core.HandlerInterceptor;
import com.dust.tripartite.netmc.model.MyHeader;
import com.dust.tripartite.netmc.model.MyMessage;
import com.dust.tripartite.netmc.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,4 +1,4 @@
package io.github.yezhihao.netmc.model;
package com.dust.tripartite.netmc.model;
public class MyHeader {

View File

@ -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 io.github.yezhihao.netmc.session.Session;
import com.dust.tripartite.netmc.core.model.Message;
import com.dust.tripartite.netmc.session.Session;
public class MyMessage implements Message {

View File

@ -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);
}
}