简单消息处理器
这里创建一个最简单的消息处理器,getty最少要配置一个消息处理器,用于处理收发的消息,只需把处理器注册到责任链中即可
只需继承 SimpleChannelInboundHandler<T>
即可实现简单的消息处理器
示例:
import com.gettyio.core.channel.AioChannel;
import com.gettyio.core.pipeline.PipelineDirection;
import com.gettyio.core.pipeline.in.SimpleChannelInboundHandler;
public class SimpleHandler extends SimpleChannelInboundHandler<String> {
@Override
public void channelAdded(AioChannel aioChannel) {
System.out.println("连接过来了");
}
@Override
public void channelClosed(AioChannel aioChannel) {
System.out.println("连接关闭了");
}
@Override
public void channelRead0(AioChannel aioChannel, String str) {
System.out.println("读取消息:" + str);
}
@Override
public void exceptionCaught(AioChannel aioChannel, Throwable cause, PipelineDirection pipelineDirection) {
System.out.println("出错了");
}
}