Skip to content

Commit 87e80ad

Browse files
author
Evan Hu
committed
修复客户端处理器
1 parent 21c80f6 commit 87e80ad

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<artifactId>mysql-connector-java</artifactId>
143143
<version>8.0.22</version>
144144
</dependency>
145+
<dependency>
146+
<groupId>org.jetbrains</groupId>
147+
<artifactId>annotations</artifactId>
148+
<version>13.0</version>
149+
</dependency>
145150
</dependencies>
146151

147152
<build>

src/main/java/info/xiaomo/gengine/network/client/ClientBuilder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
@Data
1414
public class ClientBuilder {
1515

16-
private int upLimit = 2048; // 解码大小限制
17-
18-
private int downLimit = 5120; // 编码大小限制
19-
2016
/** 网络线程池线程数量 */
2117
private int nioEventLoopCount;
2218

src/main/java/info/xiaomo/gengine/network/client/ClientMessageExecutor.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import com.google.protobuf.Message;
44
import java.util.Map;
5-
import info.xiaomo.gengine.network.IMessagePool;
6-
import info.xiaomo.gengine.network.INetworkConsumer;
7-
import info.xiaomo.gengine.network.INetworkEventListener;
5+
import info.xiaomo.gengine.network.*;
86
import info.xiaomo.gengine.network.handler.MessageExecutor;
7+
import info.xiaomo.gengine.utils.AttributeUtil;
98
import io.netty.channel.ChannelHandlerContext;
109
import io.netty.handler.timeout.IdleState;
1110
import io.netty.handler.timeout.IdleStateEvent;
@@ -16,8 +15,6 @@ public class ClientMessageExecutor extends MessageExecutor {
1615

1716
protected Map<Short, ClientFuture<Message>> futureMap;
1817

19-
protected IMessagePool pool;
20-
2118
protected boolean idleCheck;
2219

2320
public ClientMessageExecutor(
@@ -31,17 +28,30 @@ public ClientMessageExecutor(
3128
this.idleCheck = idleCheck;
3229
}
3330

31+
@SuppressWarnings("unchecked")
3432
@Override
3533
public void channelRead0(ChannelHandlerContext ctx, Message msg) {
34+
Integer msgId = pool.getMessageId(msg);
35+
36+
if (msgId == null) {
37+
log.error("消息未注册:{}", msg);
38+
return;
39+
}
3640

37-
// ClientFuture<MsgPack> f = futureMap.get(m.getSequence());
38-
// if (f != null) {
39-
// if (!f.isCancelled()) {
40-
// f.result(m);
41-
// }
42-
// } else {
43-
// super.channelRead(ctx, msg);
44-
// }
41+
ISession session = AttributeUtil.get(ctx.channel(), SessionKey.SESSION);
42+
43+
if (session == null) {
44+
return;
45+
}
46+
AbstractHandler handler = pool.getHandler(msgId);
47+
if (handler == null) {
48+
log.error("msgId:{} 未注册handler", msgId);
49+
return;
50+
}
51+
handler.setMessage(msg);
52+
handler.setParam(session);
53+
handler.setSession(session);
54+
handler.doAction();
4555
}
4656

4757
@Override

src/main/java/info/xiaomo/gengine/network/handler/MessageExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
public class MessageExecutor extends SimpleChannelInboundHandler<Message> {
1414

1515
protected final INetworkEventListener listener;
16-
private final INetworkConsumer consumer;
17-
private final IMessagePool pool;
16+
protected final INetworkConsumer consumer;
17+
protected final IMessagePool pool;
1818

1919
public MessageExecutor(
2020
INetworkConsumer consumer, INetworkEventListener listener, IMessagePool pool) {

0 commit comments

Comments
 (0)