netty TCP使用示例
2021-05-14 17:05:04 0 举报
netty tcp socket模式开发封装引用
作者其他创作
大纲/内容
引用
继承
xxEventHandler
xxxEvent event;
+onEvent(xxxEvent event)
实现
xxEvent
String xxx;
+ getxxx(); + setxxx(String xxx);
+ onEvent(xxxEvent event);
xxResultToMessageEncoder
+ encode(ChannelEventResult eventResult);
<<interface>> MessageToEventDecoder
+ ChannelEvent decode(Object message);
<<interface>> ChannelEventHandler
+ ChannelEventResult onEvent(E event);
AbstractChannelEventResult
+ getxxx(); + setxxx(String xxx);
TcpServerChannelxxx
TcpChannelConfig config; TcpChannelEncoder<?> tcpChannelEncoder; TcpChannelDecoder tcpChannelDecoder; xxResultToMessageEncoder resultToMessageEncoder; xxMessageToEventDecoder messageToEventDecoder; ChannelDispatcher channelEventDispatcher; TcpServerChannel tcpServerChannel;xxQueuableChannelDispatcher;TcpServerChannel tcpServerChannel;
+ startUp();//server
AbstractQueuableChannelDispatcher
MessageToEventDecoder messageToEventDecoder; ResultToMessageEncoder resultToMessageEncoder;
<<interface>> ChannelEventHandlerInterceptor<E extends ChannelEvent>
客户端程序
xxMessageToEventDecoder
TcpServerChannel
AtomicInteger COUNTER;String name;TcpChannelConfig config;TcpChannelDecoder tcpChannelDecoder;TcpChannelEncoder<?> tcpChannelEncoder;ChannelDispatcher channelEventDispatcher;ServerBootstrap bootstrap;TcpChannelContext tcpChannelContext;EventLoopGroup bossGroup;EventLoopGroup workerGroup;ExecutorService EXECUTOR;
<<interface>>ServerChannel
AbstractChannelEvent
+ getxxx(); + setxxx(String xxx);
+ getxxx(); + setxxx(String xxx);
业务逻辑实现区
<<interface>> ResultToMessageEncoder
xxEventHandlerInterceptor
AtomicInteger COUNTER;TcpClientChannel tcpClientChannel;
TcpChannel
CountDownLatch lock;String host;int port;TcpChannelConfig config;boolean keepalive;Channel channel;Bootstrap bootstrapEventLoopGroup workerGroup;ChannelMessageHandler channelMessageHandler;
SDK核心区
总体相关实现步骤: 1:设置端口(客户端需设置IP)(TcpChannelConfig) ; 2:设置通道编解码格式(TcpChannelEncoder/TcpChannelDecoder) ; 3:自定义事务处理流编解码器 (MessageToEventDecoder/xxResultToMessageEncoder); 4:将自定义的编解码器封装分发(ChannelDispatcher); span style=\"font-size: inherit;\
<<interface>> ChannelEvent
+ getCode(); + setCode(String code);
DefaultChannelDispatcher
TcpChannelxxx
TcpChannelConfig config; TcpChannelEncoder<?> tcpChannelEncoder; TcpChannelDecoder tcpChannelDecoder; xxResultToMessageEncoder resultToMessageEncoder; xxMessageToEventDecoder messageToEventDecoder; TcpServerChannel tcpServerChannel;xxQueuableChannelDispatcher;Channel TcpChannel;
+ connect();//client
服务端程序
xxQueuableChannelDispatcher
MessageToEventDecoder messageToEventDecoder; ResultToMessageEncoder resultToMessageEncoder;
<<interface>>Channel
Queuer
Future<?> future;volatile boolean stopped = false;BlockingQueue<Object> queue;QueueObject queueObject;
+ Queuer(AbstractQueuableChannelDispatcher dispatcher);+put(QueueObject in);+close();
0 条评论
下一页
为你推荐
查看更多