简单消息处理器

    这里创建一个最简单的消息处理器,getty最少要配置一个消息处理器,用于处理收发的消息,只需把处理器注册到责任链中即可

    只需继承 SimpleChannelInboundHandler<T> 即可实现简单的消息处理器

    示例:

    1. import com.gettyio.core.channel.AioChannel;
    2. import com.gettyio.core.pipeline.PipelineDirection;
    3. import com.gettyio.core.pipeline.in.SimpleChannelInboundHandler;
    4. public class SimpleHandler extends SimpleChannelInboundHandler<String> {
    5. @Override
    6. public void channelAdded(AioChannel aioChannel) {
    7. System.out.println("连接过来了");
    8. }
    9. @Override
    10. public void channelClosed(AioChannel aioChannel) {
    11. System.out.println("连接关闭了");
    12. }
    13. @Override
    14. public void channelRead0(AioChannel aioChannel, String str) {
    15. System.out.println("读取消息:" + str);
    16. }
    17. @Override
    18. public void exceptionCaught(AioChannel aioChannel, Throwable cause, PipelineDirection pipelineDirection) {
    19. System.out.println("出错了");
    20. }
    21. }