Netty学习之旅------Netty Channel 概述,扫地阿姨看完都学会了

*/

ChannelMetadata metadata();

/**

  • Returns the local address where this channel is bound to. The returned

  • {@link SocketAddress} is supposed to be down-cast into more concrete

  • type such as {@link InetSocketAddress} to retrieve the detailed

  • information.

  • @return the local address of this channel.

  •     {@code null} if this channel is not bound.
    
  •  返回绑定的地址,服务端的Channel返回监听的地址,而客户端的Channel返回连接到服务端的本地套接字。
    

*/

SocketAddress localAddress();

/**

  • Returns the remote address where this channel is connected to. The

  • returned {@link SocketAddress} is supposed to be down-cast into more

  • concrete type such as {@link InetSocketAddress} to retrieve the detailed

  • information.

  • @return the remote address of this channel.

  •     {@code null} if this channel is not connected.
    
  •     If this channel is not connected but it can receive messages
    
  •     from arbitrary remote addresses (e.g. {@link DatagramChannel},
    
  •     use {@link DatagramPacket#recipient()} to determine
    
  •     the origination of the received message as this method will
    
  •     return {@code null}.
    
  •     返回channel的远程套接字。
    

*/

SocketAddress remoteAddress();

/**

  • Returns the {@link ChannelFuture} which will be notified when this

  • channel is closed. This method always returns the same future instance.

  • 通道的关闭凭证(许可),这里是多线程编程一种典型的设计模式,一个channle返回一个固定的

*/

ChannelFuture closeFuture();

/**

  • Returns {@code true} if and only if the I/O thread will perform the

  • requested write operation immediately. Any write requests made when

  • this method returns {@code false} are queued until the I/O thread is

  • ready to process the queued write requests.

  • 是否可写,如果通道的写缓冲区未满,即返回true,表示写操作可以立即

  • 操作缓冲区,然后返回。

*/

boolean isWritable();

/**

  • Returns an internal-use-only object that provides unsafe operations.

*/

Unsafe unsafe();

/**

  • Return the assigned {@link ChannelPipeline}

  • 返回管道

*/

ChannelPipeline pipeline();

/**

  • Return the assigned {@link ByteBufAllocator} which will be used to allocate {@link ByteBuf}s.

  • 返回ByteBuf内存分配器

*/

ByteBufAllocator alloc();

/**

  • Return a new {@link ChannelPromise}.

  • 诸如newPromise,newSuccessedFuture()方法,就是返回一个凭证,用来保存通知结果的,是多线程编程一 * 中典型的设计模式

*/

ChannelPromise newPromise();

/**

  • Return an new {@link ChannelProgressivePromise}

*/

ChannelProgressivePromise newProgressivePromise();

/**

  • Create a new {@link ChannelFuture} which is marked as succeeded already. So {@link ChannelFuture#isSuccess()}

  • will return {@code true}. All {@link FutureListener} added to it will be notified directly. Also

  • every call of blocking methods will just return without blocking.

*/

ChannelFuture newSucceededFuture();

/**

  • Create a new {@link ChannelFuture} which is marked as failed already. So {@link ChannelFuture#isSuccess()}

  • will return {@code false}. All {@link FutureListener} added to it will be notified directly. Also

  • every call of blocking methods will just return without blocking.

*/

ChannelFuture newFailedFuture(Throwable cause);

/**

  • Return a special ChannelPromise which can be reused for different operations.

  • It’s only supported to use

  • it for {@link Channel#write(Object, ChannelPromise)}.

  • Be aware that the returned {@link ChannelPromise} will not support most operations and should only be used

  • if you want to save an object allocation for every write operation. You will not be able to detect if the

  • operation was complete, only if it failed as the implementation will call

  • {@link ChannelPipeline#fireExceptionCaught(Throwable)} in this case.

  • Be aware this is an expert feature and should be used with care!

*/

ChannelPromise voidPromise();

/**

  • Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation

  • completes, either because the operation was successful or because of an error.

  • This will result in having the

  • {@link ChannelHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method

  • called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

  • 绑定

*/

ChannelFuture bind(SocketAddress localAddress);

/**

  • Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation

  • completes, either because the operation was successful or because of an error.

  • If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with

  • a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}

  • will be used.

  • This will result in having the

  • {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

  • 连接

*/

ChannelFuture connect(SocketAddress remoteAddress);

/**

  • Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the

  • {@link ChannelFuture} once the operation completes, either because the operation was successful or because of

  • an error.

  • This will result in having the

  • {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

*/

ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);

/**

  • Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,

  • either because the operation was successful or because of an error.

  • This will result in having the

  • {@link ChannelHandler#disconnect(ChannelHandlerContext, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

  • 断开连接

*/

ChannelFuture disconnect();

/**

  • Request to close this {@link Channel} and notify the {@link ChannelFuture} once the operation completes,

  • either because the operation was successful or because of

  • an error.

  • After it is closed it is not possible to reuse it again.

  • This will result in having the

  • {@link ChannelHandler#close(ChannelHandlerContext, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

  • 关闭,释放通道资源

*/

ChannelFuture close();

/**

  • Request to deregister this {@link Channel} from its assigned {@link EventLoop} and notify the

  • {@link ChannelFuture} once the operation completes, either because the operation was successful or because of

  • an error.

  • This will result in having the

  • {@link ChannelHandler#deregister(ChannelHandlerContext, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

  • After this method completes (not the {@link ChannelFuture}!) one can not submit new tasks to the

  • {@link Channel}'s {@link EventLoop} until the {@link Channel} is again registered with an {@link EventLoop}.

  • Any attempt to do so will result in a {@link RejectedExecutionException} being thrown.

  • Any tasks that were submitted before the call to {@link #deregister()} will finish before the

  • {@link ChannelFuture} completes. Furthermore, periodic and delayed tasks will not be executed until the

  • {@link Channel} is registered with an {@link EventLoop} again. Theses are tasks submitted

  • to the {@link EventLoop} via one of the methods declared by {@link ScheduledExecutorService}.

  • Please note that all of the above only applies to tasks created from within the deregistered {@link Channel}'s

  • {@link ChannelHandler}s.

  • It’s only safe to {@linkplain EventLoop#register(Channel)} the {@link Channel} with another (or the same)

  • {@link EventLoop} after the {@link ChannelFuture} has completed.

*/

ChannelFuture deregister();

/**

  • Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation

  • completes, either because the operation was successful or because of an error.

  • The given {@link ChannelPromise} will be notified.

  • This will result in having the

  • {@link ChannelHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method

  • called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

*/

ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);

/**

  • Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation

  • completes, either because the operation was successful or because of an error.

  • The given {@link ChannelFuture} will be notified.

  • If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with

  • a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}

  • will be used.

  • This will result in having the

  • {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

*/

ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);

/**

  • Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the

  • {@link ChannelFuture} once the operation completes, either because the operation was successful or because of

  • an error.

  • The given {@link ChannelPromise} will be notified and also returned.

  • This will result in having the

  • {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

*/

ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);

/**

  • Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,

  • either because the operation was successful or because of an error.

  • The given {@link ChannelPromise} will be notified.

  • This will result in having the

  • {@link ChannelHandler#disconnect(ChannelHandlerContext, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

*/

ChannelFuture disconnect(ChannelPromise promise);

/**

  • Request to close this {@link Channel} and notify the {@link ChannelFuture} once the operation completes,

  • either because the operation was successful or because of

  • an error.

  • After it is closed it is not possible to reuse it again.

  • The given {@link ChannelPromise} will be notified.

  • This will result in having the

  • {@link ChannelHandler#close(ChannelHandlerContext, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

*/

ChannelFuture close(ChannelPromise promise);

/**

  • Request to deregister this {@link Channel} from its assigned {@link EventLoop} and notify the

  • {@link ChannelPromise} once the operation completes, either because the operation was successful or because of

  • an error.

  • This will result in having the

  • {@link ChannelHandler#deregister(ChannelHandlerContext, ChannelPromise)}

  • method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the

  • {@link Channel}.

  • After this method completes (not the {@link ChannelPromise}!) one can not submit new tasks to the

  • {@link Channel}'s {@link EventLoop} until the {@link Channel} is again registered with an {@link EventLoop}.

  • Any attempt to do so will result in a {@link RejectedExecutionException} being thrown.

  • Any tasks that were submitted before the call to {@link #deregister()} will finish before the

  • {@link ChannelPromise} completes. Furthermore, periodic and delayed tasks will not be executed until the

  • {@link Channel} is registered with an {@link EventLoop} again. Theses are tasks submitted

  • to the {@link EventLoop} via one of the methods declared by {@link ScheduledExecutorService}.

  • Please note that all of the above only applies to tasks created from within the deregistered {@link Channel}'s

  • {@link ChannelHandler}s.

  • It’s only safe to {@linkplain EventLoop#register(Channel)} the {@link Channel} with another (or the same)

  • {@link EventLoop} after the {@link ChannelPromise} has completed.

*/

ChannelFuture deregister(ChannelPromise promise);

/**

  • Request to Read data from the {@link Channel} into the first inbound buffer, triggers an

  • {@link ChannelHandler#channelRead(ChannelHandlerContext, Object)} event if data was

  • read, and triggers a

  • {@link ChannelHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the

  • handler can decide to continue reading. If there’s a pending read operation already, this method does nothing.

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
img

最后

由于细节内容实在太多了,为了不影响文章的观赏性,只截出了一部分知识点大致的介绍一下,每个小节点里面都有更细化的内容!

小编准备了一份Java进阶学习路线图(Xmind)以及来年金三银四必备的一份《Java面试必备指南》

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
img

mg-27jrOUG7-1712660548388)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-ytUk3xdH-1712660548388)]

最后

由于细节内容实在太多了,为了不影响文章的观赏性,只截出了一部分知识点大致的介绍一下,每个小节点里面都有更细化的内容!

[外链图片转存中…(img-GbSI1KFA-1712660548388)]

小编准备了一份Java进阶学习路线图(Xmind)以及来年金三银四必备的一份《Java面试必备指南》

[外链图片转存中…(img-ty0UEBZq-1712660548389)]

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-EEaqsagc-1712660548389)]

  • 16
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值