随笔分类 - Netty
Netty 的 inbound 与 outbound, 以及 InboundHandler 的 channelInactive 与 OutboundHandler 的 close
摘要:先看一个例子.有一个简单 Serverpublic class SimpleServer { public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new NioE...
阅读全文
关于 Netty Channel 的 Autoread
摘要:Netty 4 的 Channel 多了一个 autoread 参数, 它的用处是在让 channel 在触发某些事件以后(例如 channelActive, channelReadComplete)以后还会自动调用一次 read(), 代码:DefaultChannelPipeline.java ...
阅读全文
HashedWheelTimer 原理
摘要:HashedWheelTimer 是根据Hashed and Hierarchical Timing Wheels: Data Structures for the Efficient Implementation of a Timer Facility这篇论文做出来的.HashedWheelTim...
阅读全文
Netty 中 IOException: Connection reset by peer 与 java.nio.channels.ClosedChannelException: null
摘要:最近发现系统中出现了很多 IOException: Connection reset by peer 与 ClosedChannelException: null深入看了看代码, 做了些测试, 发现 Connection reset 会在客户端不知道 channel 被关闭的情况下, 触发了 eve...
阅读全文
Netty端口被占用问题
摘要:问题:最近发现Netty项目每次发布的时候Netty在重启时都会报端口被占用的异常, 需要过十几秒左右手动重启一遍, Netty才能恢复正常目前猜测是由于Tomcat_restart的时候Netty执行相关的销毁操作, Channel.close().awaitUninterrupted() 以及 ...
阅读全文
Netty writeAndFlush() 流程与异步
摘要:Netty writeAndFlush()方法分为两步, 先 write 再 flush @Override public ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) { DefaultCh...
阅读全文
Netty Message RefCount
摘要:ByteBufis always reference countedTo control the life cycle of aByteBufin a more predictable way, Netty does not rely on the garbage collector anymore but employs an explicit reference counter. Here's the basic rule:When a buffer is allocated, its initial reference count is 1.If the reference co
阅读全文
Netty Associated -- Channel
摘要:A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.一个网络套接字或组件的枢纽, 用来进行 I/O 操作, 例如 read, write, connect, bind.A channel provides a user:一个Channel的提供给用户的东西有:the current state of the channel (e.g. is it open? is it connected?),channel目前的
阅读全文
Netty Associated -- ChannelPipeline
摘要:A list of ChannelHandlers which handles or intercepts inbound events and outbound operations of a Channel. ChannelPipeline implements an advanced form of the Intercepting Filter pattern to give a user full control over how an event is handled and how the ChannelHandlers in a pipeline interact with e
阅读全文
User guide for Netty 4.x
摘要:Table of ContentsPrefaceThe SolutionGetting StartedBefore Getting StartedWriting a Discard ServerLooking into the Received DataWriting an Echo ServerWriting a Time ServerWriting a Time ClientDealing with a Stream-based TransportSpeaking in POJO instead of ByteBufShutting Down Your ApplicationSummary
阅读全文
Netty Associated -- ByteBuf
摘要:ByteBufByteBuf是Netty的Server与Client之间通信的数据传输载体.他提供了一个byte数组(byte[])的抽象视图buffer创建我们推荐通过一个Unpooled的帮助方法来创建新的buffer而不是通过调用独立的构造器来创建随机访问索引就像普通的原声字节数组一样, By...
阅读全文