Netty Concepts

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

Java offers access to network via APIs which historically evolved from blocking (java.net) to non-blocking (java.nio.channels). The APIs are quite different, so code that was written for blocking network I/O has to be rewritten for non-blocking network I/O. Netty layers in top of these APIs and exposes a common API regardless of whether the interaction with the network layer is performed in a blocking or non-blocking (preferred) fashion.


High throughput non-blocking I/O. Servers and clients. Channel. ChannelPipeline that holds ChannelHandler instances. ChannelHandler is important because it represents the interface between networking concerns and application business logic. Events. Everything is an event (accept new connection, read data, write data - in this context data is an event). Event lifecycle. Events are processed by EventLoops.

Transport and NIO Transport. A transport support a number of protocols.

Both the server and the client go through a bootstrapping process. This is where the business logic (ChannelHandlers) is "deployed".

Netty is both a framework and a class library.

The ChannelHandlerContext represents the binding between the ChannelPipeline and its installed handlers.

"Server" and "client" denote behaviors relative to the network: a "server" binds to a local port and listens for incoming connections, whereas a "client" initiates a network connection to a remote (over the network) process.

Netty uses the pattern introduced by Java NIO of writing the data in blocks, not byte by byte. It uses ByteBuf for that, also referred to as "Netty's data container".

All operations are asynchronous so their results are "result placeholders", or futures (ChannelFuture).