3
3
import com .google .protobuf .AbstractMessage ;
4
4
import com .google .protobuf .Message ;
5
5
import java .lang .reflect .Method ;
6
+ import info .xiaomo .gengine .network .IMessagePool ;
6
7
import info .xiaomo .gengine .network .INetworkConsumer ;
7
8
import info .xiaomo .gengine .network .INetworkEventListener ;
8
- import info .xiaomo .gengine .network .MsgPack ;
9
- import info .xiaomo .gengine .network .pool .MessagePool ;
10
9
import info .xiaomo .gengine .utils .ClassUtil ;
11
10
import io .netty .channel .ChannelHandlerContext ;
12
11
import io .netty .channel .SimpleChannelInboundHandler ;
13
12
import lombok .extern .slf4j .Slf4j ;
14
13
15
14
/** @author xiaomo */
16
15
@ Slf4j
17
- public class MessageExecutor extends SimpleChannelInboundHandler <MsgPack > {
16
+ public class MessageExecutor extends SimpleChannelInboundHandler <Message > {
18
17
19
18
protected final INetworkEventListener listener ;
20
19
private final INetworkConsumer consumer ;
20
+ private final IMessagePool pool ;
21
21
22
- public MessageExecutor (INetworkConsumer consumer , INetworkEventListener listener ) {
22
+ public MessageExecutor (
23
+ INetworkConsumer consumer , INetworkEventListener listener , IMessagePool pool ) {
23
24
this .consumer = consumer ;
24
25
this .listener = listener ;
26
+ this .pool = pool ;
25
27
}
26
28
27
29
@ Override
@@ -30,27 +32,14 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
30
32
}
31
33
32
34
@ Override
33
- public void channelRead0 (ChannelHandlerContext ctx , MsgPack msgPack ) throws Exception {
34
- AbstractMessage abstractMessage = MessagePool . messages . get ( msgPack . getMsgId () );
35
+ public void channelRead0 (ChannelHandlerContext ctx , Message message ) throws Exception {
36
+ int msgId = pool . getMessageId ( message );
35
37
36
- if (abstractMessage == null ) {
37
- if (msgPack .getMsgId () == 0 ) {
38
- log .error ("请求消息未设置msgId" );
39
- } else {
40
- log .error ("消息未注册,请检查" );
41
- }
38
+ if (msgId == 0 ) {
39
+ log .error ("请求消息未设置msgId" );
42
40
return ;
43
41
}
44
-
45
- Method m = ClassUtil .findProtobufMsg (abstractMessage .getClass ());
46
- if (m != null ) {
47
- AbstractMessage message = (AbstractMessage ) m .invoke (null );
48
- Message msg = message .newBuilderForType ().mergeFrom (msgPack .getBytes ()).build ();
49
- msgPack .setMsg (msg );
50
- consumer .consume (msgPack , ctx .channel ());
51
- } else {
52
- log .error ("找有找到消息体:{}" , msgPack .getMsgId ());
53
- }
42
+ consumer .consume (message , ctx .channel ());
54
43
}
55
44
56
45
@ Override
0 commit comments