11package info .xiaomo .gengine .network .handler ;
22
3+ import com .google .protobuf .AbstractMessage ;
34import info .xiaomo .gengine .network .INetworkConsumer ;
45import info .xiaomo .gengine .network .INetworkEventListener ;
5- import io .netty .channel .ChannelHandlerAdapter ;
66import io .netty .channel .ChannelHandlerContext ;
7+ import io .netty .channel .SimpleChannelInboundHandler ;
78
89/**
910 * @author xiaomo
10- * :todo
1111 */
12- public class MessageExecutor extends ChannelHandlerAdapter {
12+ public class MessageExecutor extends SimpleChannelInboundHandler < Object > {
1313
14- private INetworkConsumer consumer ;
14+ private final INetworkConsumer consumer ;
1515
1616 private final INetworkEventListener listener ;
1717
@@ -22,23 +22,23 @@ public MessageExecutor(INetworkConsumer consumer, INetworkEventListener listener
2222 }
2323
2424
25-
2625 @ Override
2726 public void exceptionCaught (ChannelHandlerContext ctx , Throwable cause ) {
2827 listener .onExceptionOccur (ctx , cause );
2928 }
3029
31- // @Override
32- // public void channelRead(ChannelHandlerContext ctx, Object msg) {
33- // consumer.consume((AbstractMessage) msg, ctx.channel());
34- // }
35- // @Override
36- // public void channelActive(ChannelHandlerContext ctx) {
37- // this.listener.onConnected(ctx);
38- // }
39- //
40- // @Override
41- // public void channelInactive(ChannelHandlerContext ctx) {
42- // this.listener.onDisconnected(ctx);
43- // }
30+ @ Override
31+ public void channelRead0 (ChannelHandlerContext ctx , Object msg ) {
32+ consumer .consume ((AbstractMessage ) msg , ctx .channel ());
33+ }
34+
35+ @ Override
36+ public void channelActive (ChannelHandlerContext ctx ) {
37+ this .listener .onConnected (ctx );
38+ }
39+
40+ @ Override
41+ public void channelInactive (ChannelHandlerContext ctx ) {
42+ this .listener .onDisconnected (ctx );
43+ }
4444}
0 commit comments