源码分析
Java · 33 notes
- Netty 3.x Source Analysishistorical
Netty 3.x creates thread pools and initializes Boss and Worker components. These notes trace its networking implementation through thread organization.
- Summaryhistorical
This page connects Netty source-analysis topics on server startup, Channel registration, and port binding through their call relationships.
- Off-Heap Memoryhistorical
Off-heap memory lies outside the Java heap. These notes compare ByteBuffer allocation approaches and their relationship to data transfer.
- 2.56 1. Create NioEventLoopGrouphistorical
NioEventLoopGroup manages multiple NioEventLoops and accepts Runnable tasks. These notes trace how the group is created through its constructors.
- 2. Bootstrap Creationhistorical
After creating ServerBootstrap, Channel types, handlers, and options must be configured. These notes focus on how the Channel type is set.
- 3. Bind the Porthistorical
These notes follow bind calls to examine how Netty port-binding requests reach the concrete Channel implementation.
- 1. Detect a New Connectionhistorical
When a connection arrives, NioEventLoop handles an OP_ACCEPT event. These notes trace connection detection with breakpoints and a client connection.
- Pipeline Initializationhistorical
Each Netty Channel has its own pipeline, created during AbstractChannel construction. These notes examine pipeline initialization.
- 1. Creating the Serverhistorical
Starting from the server bind method, these notes follow the call chain to AbstractBootstrap.doBind and examine server creation.
- Create Executorhistorical
These notes trace Netty Executor creation, starting with the thread factory and executor initialization.
- 2. Create NioSocketChannelhistorical
Netty wraps accepted Java NIO connections in NioSocketChannel. These notes trace construction of that object and its parent classes.
- Adding and Removing ChannelHandlershistorical
These notes begin with methods such as DefaultChannelPipeline.addLast and trace ChannelHandler insertion, validation, and removal.
- 2. Server Initializationhistorical
These notes follow bind and doBind calls to trace the work performed during Netty server initialization.
- Create the NioEventLoop Arrayhistorical
NioEventLoopGroup creates individual NioEventLoops through newChild. These notes follow that call to examine event-loop-array initialization.
- 3. Allocate a Thread and Register the Selectorhistorical
After a new connection passes through the pipeline, it needs a processing thread and Selector registration. These notes trace the related calls from connection acceptance.
- 3. Register the Selectorhistorical
Starting from the server's bind call, these notes trace how a Channel is assigned an event loop and registered with the Selector.
- 4. Register Read Events with the Selectorhistorical
After Channel registration, read events must be registered with the Selector. These notes trace the process through AbstractChannel's register operation.
- 4. Bind the Server Porthistorical
These notes trace the server bind call chain to examine how Netty binds a listening port to the underlying network channel.
- Server Startuphistorical
This page organizes Netty server-startup analysis into creation, initialization, Selector registration, and port binding.
- 2.79 1. Instantiate the Channelhistorical
Netty invokes the NioServerSocketChannel constructor through reflection and creates the underlying Java NIO channel. These notes trace that instantiation.
- Netty Bind Source: Actually Binding the Listening Porthistorical
Netty wraps port binding as a task for the Channel's NioEventLoop. These notes trace the calls after task submission.
- Inbound Eventshistorical
Experiments with multiple InboundHandlers show how Netty inbound events propagate through the pipeline.
- ByteBufhistorical
ByteBuf uses reader and writer indexes to divide consumed, readable, and writable regions. These notes examine read and write API behavior through those indexes.
- 2. Initialize Channelhistorical
Channel initialization adds a ChannelInitializer to the pipeline and connects the handlers configured in ServerBootstrap.
- Netty Source: NioEventLoop run Methodhistorical
NioEventLoop's run method repeatedly processes I/O events and tasks. These notes separate the main parts of the loop and trace execution.
- Outbound Eventshistorical
Code examples with multiple OutboundHandlers show how Netty outbound events propagate through the pipeline.
- ByteBufAllocatorhistorical
ByteBufAllocator allocates ByteBuf instances. These notes follow the abstract buffer method to examine choices such as heap and direct memory.
- 2.91 3. Register the Channelhistorical
A server Channel uses EventLoopGroup to choose an event loop and register itself. These notes trace the process through ServerBootstrap calls.
- Exception Eventshistorical
Server and Handler examples generate exceptions to examine how Netty propagates and handles exception events in the pipeline.
- Usagehistorical
Code examples record Netty memory-related usage and provide a practical starting point for reading allocator implementations.
- Channel Class Hierarchyhistorical
Channel abstracts network I/O in Netty. These notes examine skeletal implementations and relationships among channel types through the class hierarchy.
- PooledByteBufAllocatorhistorical
PooledByteBufAllocator obtains a thread cache and its PoolArena, then allocates memory through the arena. These notes trace both stages.
- PoolThreadCachehistorical
PoolThreadCache creates caches for memory regions of different sizes. These notes examine initialization of tiny, small, and normal MemoryRegionCache instances.