尚硅谷2019年Netty教程 netty 源码分析 ---- 目标netty---step6.10

netty服务器启动 1 2 3
https://www.bilibili.com/video/BV1jK4y1s7GV?p=92 — 25
https://www.bilibili.com/video/BV1jK4y1s7GV?p=93 — 5
https://www.bilibili.com/video/BV1jK4y1s7GV?p=94 — 25
netty接受请求 1 2 3
https://www.bilibili.com/video/BV1jK4y1s7GV?p=95 — 25
https://www.bilibili.com/video/BV1jK4y1s7GV?p=96 — 5
https://www.bilibili.com/video/BV1jK4y1s7GV?p=97 — 10
netty ChannelPipeline
https://www.bilibili.com/video/BV1jK4y1s7GV?p=98 —20
netty ChannelHandler
https://www.bilibili.com/video/BV1jK4y1s7GV?p=99 —10
netty ChannelHandlerContext 管道处理上下文创建
https://www.bilibili.com/video/BV1jK4y1s7GV?p=100 —15
netty Pipeline 调用Handler
https://www.bilibili.com/video/BV1jK4y1s7GV?p=101 —20
netty 三大核心组件
https://www.bilibili.com/video/BV1jK4y1s7GV?p=102 —5
netty 心跳
https://www.bilibili.com/video/BV1jK4y1s7GV?p=103 —15
https://www.bilibili.com/video/BV1jK4y1s7GV?p=104 —20
netty EventLoop 1 2
https://www.bilibili.com/video/BV1jK4y1s7GV?p=105 —20
https://www.bilibili.com/video/BV1jK4y1s7GV?p=106 —5
netty 任务加入线程池 1 2 3
https://www.bilibili.com/video/BV1jK4y1s7GV?p=107 —15
https://www.bilibili.com/video/BV1jK4y1s7GV?p=108 —20
https://www.bilibili.com/video/BV1jK4y1s7GV?p=109 —15
netty RPC 调用流程分析
https://www.bilibili.com/video/BV1jK4y1s7GV?p=110 —10
netty 用netty 实现dubbo RPC 1 2 3 4 5 6
https://www.bilibili.com/video/BV1jK4y1s7GV?p=111 —15
https://www.bilibili.com/video/BV1jK4y1s7GV?p=112 —10
https://www.bilibili.com/video/BV1jK4y1s7GV?p=113 —20
https://www.bilibili.com/video/BV1jK4y1s7GV?p=114 —15
https://www.bilibili.com/video/BV1jK4y1s7GV?p=115 —20
https://www.bilibili.com/video/BV1jK4y1s7GV?p=116 —20


netty服务器启动 1 2 3 
https://www.bilibili.com/video/BV1jK4y1s7GV?p=92
https://www.bilibili.com/video/BV1jK4y1s7GV?p=93
https://www.bilibili.com/video/BV1jK4y1s7GV?p=94

这块的数据讲的很垃圾浪费了俩小时,没有周志磊的牛逼,虽然韩顺平之前讲的很好

=======02 NioEventLoopGroup ======
NioEventLoopGroup  extends  MultithreadEventLoopGroup  extends  MultithreadEventExecutorGroup  extends AbstractEventExecutorGroup   implements EventExecutorGroup

=======  03 ServerBootstrap  ======
ServerBootstrap  extends  AbstractBootstrap   implements Cloneable
 
======= 04 ChannelPipeline  ======
DefaultChannelPipeline implements ChannelPipeline 
interface ChannelPipeline extends ChannelInboundInvoker, ChannelOutboundInvoker

======= 05 NioServerSocketChannel   ======
 NioServerSocketChannel extends AbstractNioMessageChannel extends AbstractNioChannel  extends AbstractChannel  extends DefaultAttributeMap implements AttributeMap

netty接受请求 1 2 3 
https://www.bilibili.com/video/BV1jK4y1s7GV?p=95
https://www.bilibili.com/video/BV1jK4y1s7GV?p=96
https://www.bilibili.com/video/BV1jK4y1s7GV?p=97
 
这块的数据讲的很垃圾浪费了俩小时,没有周志磊的牛逼,虽然之前讲的很好 , 
=======  06   ======
NioEventLoop extends SingleThreadEventLoop  extends SingleThreadEventExecutor extends AbstractScheduledEventExecutor  extends AbstractEventExecutor extends AbstractExecutorService  implements ExecutorService extends Executor




netty ChannelPipeline
https://www.bilibili.com/video/BV1jK4y1s7GV?p=98    ---20 
netty ChannelHandler
https://www.bilibili.com/video/BV1jK4y1s7GV?p=99    ---10
netty ChannelHandlerContext 管道处理上下文创建
https://www.bilibili.com/video/BV1jK4y1s7GV?p=100   ---15 
netty Pipeline 调用Handler 
https://www.bilibili.com/video/BV1jK4y1s7GV?p=101   ---20 
netty 三大核心组件 
https://www.bilibili.com/video/BV1jK4y1s7GV?p=102   ---5 
=======    ======
ChannelPipeline    ChannelHandlerContext   ChannelHandler -- 三个核心组件
 
1.每当ServerSocket创建一个新的连接,就会创建一个Socket,对应目标客户端
2.每创建一个socket,都会分配一个全新的ChannelPipeline
3.每个channelPipeline内部会有多个ChannelHandlerContext
4.多个ChannelHandlerContext一起组成一个双向链表,这些ChannelHandlerContext包装ChannelHandler 

5.ChannelSocket 与 ChannelPipeline 是一对一的关系,pipeline内部有多个Context形成链表,context对handler的封装 
6.当前一个请求进来,会进入Socket对应的pipeline,并经过pipeline所有的handler,对应设计模式的 过滤器模式  。




=======  ChannelPipeline  ======
ChannelPipeline       extends ChannelInboundInvoker, ChannelOutboundInvoker

ChannelHandlerContext extends AttributeMap, ChannelInboundInvoker, ChannelOutboundInvoker  

@Sharable
public class EchoServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        ctx.write(msg);
        //当有非常耗时的处理时候,不要直接放在这里,要放在eventLoop 的taskQueue 或者 scheduledTaskQueue 
		// 之前的某一集 讲的 
    }
}

=======  ChannelHandler  ======
public interface ChannelHandler {
   // 将 ChannelHandler 添加到 pipeline  或者 ChannelHandler 从pipeline 删除 时候会调用 
   // 定义了两个子接口 
    void handlerAdded(ChannelHandlerContext var1) throws Exception;
    void handlerRemoved(ChannelHandlerContext var1) throws Exception;
}

interface ChannelInboundHandler extends ChannelHandler 
interface ChannelOutboundHandler extends ChannelHandler
class ChannelDuplexHandler extends ChannelInboundHandlerAdapter extends ChannelHandlerAdapter implements ChannelHandler 
同时处理入站出站 ,但是开发中尽量不要用,容易混淆 入站出站 


=======  ChannelHandlerContext  ======
 
ChannelHandlerContext extends AttributeMap, ChannelInboundInvoker, ChannelOutboundInvoker  
interface ChannelInboundInvoker
interface ChannelOutboundInvoker
ChannelPipeline    ChannelHandlerContext   ChannelHandler三个核心组件创建过程
1. Channelsocket创建时候,会创建pipeline ;
2. 当调用pipeline.add(***Handler) 的时候,会创建包装这个ChannelHandler的ChannelHandlerContext ;
3. 这些***Context在pipeline中形成双向链表 



=======   DefaultChannelPipeline  ======
AbstractChannel
    protected AbstractChannel(Channel parent) {
        this.pipeline = this.newChannelPipeline();
    }
	
    protected DefaultChannelPipeline newChannelPipeline() {
        return new DefaultChannelPipeline(this);
    }
}






=======    netty 心跳     ======
 


https://www.bilibili.com/video/BV1jK4y1s7GV?p=103   ---15  
https://www.bilibili.com/video/BV1jK4y1s7GV?p=104   ---20 

 

netty心跳

idleStateHandler 可以时效件心跳功能,当服务器与客户端没有任何交互,并且超出了给定的时间,会触发handler的userEventTriggered方法,
用户可以在这个方法中尝试向对方发送消息,如果发送失败关闭连接。
IdleStateHandler 的实现是基于 EvnetLoop 的定时任务。


IdleStateHandler / ReadTimeoutHandler / WriteTimeoutHandler  
重点看 IdleStateHandler
 IdleStateHandler  extends ChannelDuplexHandler   extends ChannelInboundHandlerAdapter  extends ChannelHandlerAdapter

class IdleStateHandler
{
    final class ReaderIdleTimeoutTask
    final class WriterIdleTimeoutTask
    final class AllIdleTimeoutTask
}
ReadTimeoutHandler 与 WriteTimeoutHandler 底层的原理不一致,
class ReadTimeoutHandler extends IdleStateHandler
class WriteTimeoutHandler extends ChannelOutboundHandlerAdapter 





======= netty EventLoop ======
在这里插入图片描述





=======   netty EventLoop  ======


netty EventLoop 1  2  
https://www.bilibili.com/video/BV1jK4y1s7GV?p=105   ---20 
https://www.bilibili.com/video/BV1jK4y1s7GV?p=106   ---5 


EventLoopGroup event= new NioEventLoopGroup();

NioEventLoop extends SingleThreadEventLoop  extends SingleThreadEventExecutor  extends AbstractScheduledEventExecutor extends AbstractEventExecutor  extends AbstractExecutorService  AbstractExecutorService implements ExecutorService 


ScheduledExecutorService   
在 NioEventLoop.run() 方法里面 
this.selector.wakeup();
this.processSelectedKeys();
this.runAllTasks();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值