摘要:
5.1、Redis协议 //redis协议测试 public class TestRedis { public static void main(String[] args) { final byte[] line = {13, 10}; NioEventLoopGroup group = new 阅读全文
摘要:
4、解决方案 4.1、短连接 以解决黏包为例。服务端同上,客户端如下 //短连接处理黏包,发送后关闭 public class TestSloveNianbaoClient { public static void main(String[] args) { for (int i = 0; i < 阅读全文
摘要:
Netty进阶 1、黏包 服务端 //测试黏包服务端 @Slf4j public class TestNianbaoServer { public static void main(String[] args) { NioEventLoopGroup boss = new NioEventLoopG 阅读全文
摘要:
3.5、ByteBuf 3.5.1、创建 //结果:初始容量256,扩容到512 //PooledUnsafeDirectByteBuf(ridx: 0, widx: 0, cap: 256) //PooledUnsafeDirectByteBuf(ridx: 0, widx: 300, cap: 阅读全文
摘要:
3.4、Handler & Pipeline ChannelHandler 用来处理 Channel 上的各种事件,分为入站、出站两种。所有 ChannelHandler 被连成一串,就是 Pipeline 入站处理器通常是 ChannelInboundHandlerAdapter 的子类,主要用来 阅读全文
摘要:
3.3、Future & Promise Netty中的Future与Jdk中Future同名,但是是两个接口, 继承关系:Promise extends-->Future(Netty) extend >Future(JDK) 区别: jdk Future 只能同步等待任务结束(或成功、或失败)才能 阅读全文
摘要:
3.2、Channel close() 关闭channel closeFuture() 用来处理channel的关闭 sync() 同步等待channel关闭 addListener() 异步等待channel关闭 pipeline() 添加处理器 write() 将数据写入缓冲区,但不会立即输出 阅读全文
摘要:
3、组件 3.1、EventLoop 事件循环对象EventLop EventLoop 本质是一个单线程执行器(同时维护了一个 Selector),里面有 run 方法处理 Channel 上源源不断的 io 事件。 继承关系: 一条线是继承自 j.u.c.ScheduledExecutorServ 阅读全文
摘要:
Netty入门 1、Netty优势 Netty VS NIO,工作量大,bug多 需要自己构建协议 解决TCP传输问题,如黏包,半包 epoll空轮询导致cpu 100% 对API进行增强,ThreadLocal-->FastThreadLocal,ByteBuffer-->ByteBuf 2、He 阅读全文