netty Architectural Overview --reference

reference from:http://docs.jboss.org/netty/3.1/guide/html/architecture.html

The Architecture Diagram of Netty

In this chapter, we will examine what core functionalities are provided in Netty and how they constitute a complete network application development stack on top of the core. Please keep this diagram in mind as you read this chapter.

2.1. Rich Buffer Data Structure

Netty uses its own buffer API instead of NIO ByteBuffer to represent a sequence of bytes. This approach has significant advantage over using ByteBuffer. Netty's new buffer type, ChannelBuffer has been designed from ground up to address the problems of ByteBuffer and to meet the daily needs of network application developers. To list a few cool features:

  • You can define your buffer type if necessary.

  • Transparent zero copy is achieved by built-in composite buffer type.

  • A dynamic buffer type is provided out-of-the-box, whose capacity is expanded on demand, just likeStringBuffer.

  • There's no need to call flip() anymore.

  • It is often faster than ByteBuffer.

 

For more information, please refer to the org.jboss.netty.buffer package description.

2.2. Universal Asynchronous I/O API

Traditional I/O APIs in Java provided different types and methods for different transport types. For example,java.net.Socket and java.net.DatagramSocket do not have any common super type and therefore they have very different ways to perform socket I/O.

This mismatch makes porting a network application from one transport to the other tedious and difficult. The lack of portability between transports becomes a problem when you need to support more transports not rewriting the network layer of the application. Logically, many protocols can run on more than one transport such as TCP/IP, UDP/IP, SCTP, and serial port communication.

To make the matter worse, Java New I/O (NIO) API introduced the incompatibility with the old blocking I/O (OIO) API, and so will NIO.2 (AIO). Because all these APIs are different from each other in design and performance characteristics, you are often forced to determine which API your application will depend on before you even begin the implementation phase.

For instance, you might want to start with OIO because the number of clients you are going to serve will be very small and writing a socket server using OIO is much easier than using NIO. However, you are going to be in trouble when your business grows up exponentially and your server starts to serve tens of thousand clients simultaneously. You could start with NIO, but it might take much longer time to implement due to the complexity of the NIO Selector API, hindering rapid development.

Netty has a universal asynchronous I/O interface called Channel, which abstracts away all operations required to point-to-point communication. That is, once you wrote your application on one Netty transport, your application can run on other Netty transports. Netty provides a number of essential transports via one universal API:

  • NIO-based TCP/IP transport (See org.jboss.netty.channel.socket.nio),

  • OIO-based TCP/IP transport (See org.jboss.netty.channel.socket.oio),

  • OIO-based UDP/IP transport, and

  • Local transport (See org.jboss.netty.channel.local).

Switching from one transport from the other usually takes just a couple lines of changes such as choosing a different ChannelFactory implementation.

Also, you are even able to take advantage of a new transport which is not written yet, serial port communication transport for instance, again by replacing just a couple lines of constructor calls. Moreover, you can write your own transport by extending the core API because it is highly extensible.

2.3. Event Model based on the Interceptor Chain Pattern

Well-defined and extensible event model is a must for an event-driven application. Netty does have a well-defined event model focused on I/O. It also allows you to implement your own event type without breaking the existing code at all because each event type is distinguished from each other by strict type hierarchy. This is another differentiator against other frameworks. Many NIO frameworks have no or very limited notion of event model; they often break the existing code when you try to add a new custom event type, or just do not allow extension.

A ChannelEvent is handled by a list of ChannelHandlers in a ChannelPipeline. The pipeline implements an advanced form of the Intercepting Filter pattern to give a user full control over how an event is handled and how the handlers in the pipeline interact with each other. For example, you can define what to do when a data is read from a socket:

public class MyReadHandler implements SimpleChannelHandler {
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt) {
        Object message = evt.getMessage();
        // Do something with the received message.
        ...

        // And forward the event to the next handler.
        ctx.sendUpstream(evt);
    }
}

You can also define what to do when other handler requested a write operation:

public class MyWriteHandler implements SimpleChannelHandler {
    public void writeRequested(ChannelHandlerContext ctx, MessageEvent evt) {
        Object message = evt.getMessage();
        // Do something with the message to be written.
        ...

        // And forward the event to the next handler.
        ctx.sendDownstream(evt);
    }
}

For more information about the event model, please refer to the API documentation of ChannelEvent andChannelPipeline.

2.4. Advanced Components for More Rapid Development

On top of the core components mentioned above, that already enable the implementation of all types of network applications, Netty provides a set of advanced features to accelerate the development pace even more.

2.4.1. Codec framework

As demonstrated in Section 1.8, “ Speaking in POJO instead of ChannelBuffer ”, it is always a good idea to separate a protocol codec from a business logic. However, there are some complications when implementing this idea from scratch. You have to deal with the fragmentation of messages. Some protocols are multi-layered (i.e. built on top of other lower level protocol). Some are too complicated to be implemented in a single state machine.

Consequently, a good network application framework should provide an extensible, reusable, unit-testable, and multi-layered codec framework that generates maintainable user codec.

Netty provides a number of basic and advanced codecs built on top of its core to address most issues you will encounter when you write a protocol codec regardless if it is simple or not, binary or text - simply whatever.

2.4.2. SSL / TLS Support

Unlike old blocking I/O, it is a non-trivial task to support SSL in NIO. You can't simply wrap a stream to encrypt or decrypt data but you have to use javax.net.ssl.SSLEngine. SSLEngine is a state machine which is as complex as SSL is. You have to manage all possible states such as cipher suite and encryption key negotiation (or re-negotiation), certificate exchange and validation. Moreover, SSLEngine is not even completely thread-safe unlike usual expectation.

In Netty, SslHandler takes care of all the gory details and pitfalls of SSLEngine. All you need to do is to configure and insert the SslHandler to your ChannelPipeline. It also allows you to implement advanced features likeStartTLS very easily.

2.4.3. HTTP Implementation

HTTP is definitely the most popular protocol in the Internet. There are already a number of HTTP implementations such as a Servlet container. Then why does Netty have HTTP on top of its core?

Netty's HTTP support is very different from the existing HTTP libraries. It gives you complete control over how HTTP messages are exchanged in a low level. Because it is basically the combination of HTTP codec and HTTP message classes, there is no restriction such as enforced thread model. That is, you can write your own HTTP client or server that works exactly the way you want. You have full control over thread model, connection life cycle, chunked encoding, and as much as what HTTP specification allows you to do.

Thanks to its highly customizable nature, you can write a very efficient HTTP server such as:

  • Chat server that requires persistent connections and server push technology (e.g. Comet)

  • Media streaming server that needs to keep the connection open until the whole media is streamed (e.g. 2 hours of movie)

  • File server that allows the upload of large files without memory pressure (e.g. uploading 1GB per request)

  • Scalable mash-up client that connects to tens of thousand 3rd party web services asynchronously

 

2.4.4. Google Protocol Buffer Integration

Google Protocol Buffers are an ideal solution for the rapid implementation of a highly efficient binary protocol that evolves over time. With ProtobufEncoder and ProtobufDecoder, you can turn the message classes generated by Google Protocol Buffers Compiler (protoc) into Netty codec. Please take a look into the 'LocalTime' examplethat shows how easily you can create a high-performing binary protocol client and server from the sample protocol definition.

2.5. Summary

In this chapter, we reviewed the overall architecture of Netty from the feature-wise standpoint. Netty has simple yet powerful architecture. It is composed of three components - buffer, channel, and event model - and all advanced features are built on top of the three core components. Once you understood how these three work together, it should not be difficult to understand more advanced features which were covered briefly in this chapter.

You might still have an unanswered question about what the overall architecture looks exactly like and how each feature work together. If so, it is a good idea to talk to us to improve this guide.

转载于:https://www.cnblogs.com/davidwang456/p/4287029.html

【CarMaker实战指南】从零构建环形测试场景与车辆连续仿真 本文详细介绍了如何使用CarMaker软件从零构建环形测试场景与实现车辆连续仿真。通过分步指导搭建闭环道路、连接交叉路口、规划车辆轨迹等核心操作,帮助用户掌握CarMaker的基础应用技巧,并提供了常见问题排查与进阶优化建议,适用于车辆耐久性测试和自动驾驶算法验证等场景。 阅读详情

相关推荐

西门子RS485自由口通信Modbus RTU 通信协议

部分西门子的RS485模块不能使用西门子自带的Modbus RTU通信指令,需要通过自己拼接、发送、接收和解析报文完成Modbus RTU通信。通过多次尝试完成该功能: #R_TRIG_Instance(CLK := #触发, Q => #触发上升沿); IF #触发上升沿 THEN // 触发后先将读取完成复位 #读写完成 := 0; END_IF; CASE #功能码 OF 1: // 线圈状态读取 ; 2:

qq_20792765的博客 1万+

Java AIO 异步非阻塞 IO

AIO 全称 Asynchronous IO,异步非阻塞 IO,JDK1.7 引入,也叫 NIO.2。BIO:同步阻塞;NIO:同步非阻塞;AIO:异步非阻塞。同步和异步看的是,阻塞非阻塞看线程是否卡住等待。AIO 交给操作系统去完成读写,操作系统读完 / 写完之后,主动回调通知我们的程序,线程不用一直轮询。

2301_81781955的博客 209

修复zookeeper未授权访问漏洞

【代码】修复zookeeper未授权访问漏洞。

qq_28392947的博客 4079

Java RPC 与通信深度实践:手写 Netty、gRPC、OpenFeign 与 RMI 全解析

本文详解RPC核心原理,以一次函数调用切入,揭示跨网络调用的复杂性。通过拆解RPC六大环节(代理、序列化、传输、反序列化、反射、响应),构建基于Netty的自研RPC框架,重点实现请求ID管理与异步超时处理机制。对比REST与消息队列,明确RPC在服务间同步调用中的优势。深入剖析IO多路复用模型,结合手写NIO服务器理解粘包/半包问题,为高性能网络编程奠定基础。代码已在麒麟V10 + JDK21环境验证,完整开源。

一只懂代码不懂人情世故的源码爱好猿 480

AVM环视:系统搭建整体流程

文章目录前言一、畸变矫正鱼眼相机二、透视变换三、图像拼接四、图像融合总结 前言 由于正在做AVM环视,所以记录一下整个过程,归纳为一个系列文章,并对期间遇到的错误进行归纳整理。本文主要概括了AVM环视的大致流程和逻辑,不涉及代码部分,仅供思路参考,其中涉及的具体技术会在后期整理为小章节进行分析。 一、畸变矫正 鱼眼相机 做环视基本上使用到的是鱼眼照片,因为鱼眼相机的视角范围可以达到220°到230°,所以一个相机就可以采集到一个面的全部信息,例如汽车具有四个面,那么在汽车的前后左右分别安装一个鱼眼相机.

qq_34468890的博客 6546

纽扣电池供电系统优化:NBM5100A与STM32F745VG组合方案

在低功耗物联网设备设计中,能量管理是核心挑战之一。纽扣电池因其体积小、成本低被广泛采用,但瞬时大电流需求常导致电压骤降和寿命缩短。通过超级电容缓冲技术,可以实现能量的细水长流式存储与集中释放。NBM5100A电源管理IC与STM32F745VG微控制器的组合方案,采用双阶段能量管理架构,先以恒定小电流充电,再通过电容释放大电流。这种方案不仅能提升系统稳定性,还能延长电池寿命3-5倍,特别适合智能门锁、无线传感器等需要间歇性高功率输出的场景。

weixin_29194255的博客 263

11-1 蜂鸣器 (SDCC + VScode +Makefile+ STC-ISP/普中ISP)

蜂鸣器是将电信号转为声音的器件,分有源(内置振荡源,接电即响)和无源(需外部脉冲驱动,可调音调)。本文采用无源蜂鸣器,通过单片机控制三极管或ULN2003D驱动电路实现开关控制。在按键响应中,调用Buzzer_Time(500)函数,以1kHz方波驱动蜂鸣器发声500ms,实现按键提示音。代码通过精确延时生成方波,实现简单可靠的音频反馈。

xunyan6234的博客 197

手把手实战:快速构建合同智能审查Agent

配置“模型供应商”,选择 “OpenAI-API-compatible”,输入申请到的 “API Key” 和 “URL” 后点击“保存”,如下图示例完成 “AlayaNew/DeepSeek-R1。至此,我们完成了合同智能审核Agent的构建,我们也可以在Dify中把这个智能体发布为API服务,这样企业其它应用如OA就可以通过API集成,在原合同流程中实现智能审核工作。该节点“输入变量”中,配置从“开始”节点中获取上传的文件,输出变量就是合同的内容,配置如下图。接下来我们开始创建智能体。

weixin_46880696的博客 4414

基于微信小程序的旅游管理系统_50042(附源码+文档+脚本)

本项目为基于微信小程序的平江县智慧旅游系统,采用SpringBoot+MySQL+微信小程序技术架构,实现景点资讯、路线规划、住宿预订及后台管理等功能。系统支持游客、管理员、旅行社多角色使用,具备移动化、智能化与数据可视化特点,助力旅游服务升级。附完整源码、文档与部署指导,可快速运行与二次开发。

tangyuzhidao的博客 181

第一章:GEE 和 GEEMAP

在本章中,我们将介绍地理空间数据科学、谷歌地球引擎和地理地图的基础知识。然后,我们将逐步完成设置 conda 环境和安装 geemap 的步骤。我们还将学习如何在不在您的计算机上安装任何东西的情况下将 geemap 与 Google Colab 一起使用。...

韩天放 8069

【软考高项论文】论信息系统项目管理的干系人绩效域

例如,在处理与电信运营商合作铺设光纤网络的问题时,考虑到其在通信设施建设和运维方面的专业性和重要性,我们将之定位为高权力高利益的干系人,给予了高度关注和优先沟通。项目全程,我们对干系人绩效域的执行效果进行了定期检查和评估,通过定量与定性的数据收集,确认了项目在干系人管理上的成效,具体表现为:建立了稳固的工作关系网络,使干系人普遍认可项目目标;鉴于本项目牵涉到政府各级部门、企事业单位、市民团体、技术研发伙伴等多种类型的干系人,且干系人的诉求和影响力各异,因此,有序且持续的干系人参与管理显得尤为关键。

Programming Talk 1701

宿舍管理系统的楼栋级数据权限设计:SpringBoot 实战复盘

本文分享一套宿舍管理系统的核心设计——“楼栋级数据权限”,实现系统管理员(全局)、宿舍管理员(按楼栋)、学生(仅本人)的三级数据隔离。通过SpringBoot+MySQL技术栈,关键在接口层进行数据过滤,确保权限严格控制,答辩时可重点展示“同数据、不同范围”的权限设计逻辑与实现细节,具有较强复用性与技术说服力。

u014100552的博客 166

内存泄漏系列专题分析之二十三:meminfo无法统计到的黑洞内存泄漏分析

内存泄漏系列专题分析之二十三:meminfo无法统计到的黑洞内存泄漏分析

694

Jupyter SQL 表血缘分析并导出 Excel

完整修复版代码(v1.8.0)整合了全部修复:临时视图识别、别名/通配符、JOIN 裸 *、SQL cell 解析、命令类语句预处理、Command 降级兜底,以及本轮的防死循环性能修复。 v1.8.0 相对 v1.7.0 的改动位置 改动 DEFAULT_MAX_DEPTH / DEFAULT_MAX_STEPS / DEFAULT_MAX_QUEUE 新增常量,作为 CLI 默认值 _SQL_LIKE_CACHE / looks_like_sql 新增缓存;超长(>5000)不做缓存,避免内存无界增长

weixin_30777913的博客 194

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Java 异常堆栈有了行号,断点该打在哪一行?用 MyEclipse 让 AI 参与工程调试

本文从堆栈行号、控制台焦点和源码断点出发,说明 MyEclipse 如何借助 MCP Server 让 AI Agent 读取当前控制台、定位工程代码,并通过断点命中后的变量值验证故障解释。

m0_75220675的博客 654

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

JavaEE|Maven:Spring Boot项目创建、POM继承、版本兼容与JAR打包机制

本文结合 Spring Boot 创建项目,梳理 Maven 坐标、包名与仓库路径关系,说明父 POM 继承与版本管理,分析 Starter 混用,追踪源码到 JAR 转换及打包、安装、部署去向。

Brookty的博客 433

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

MRS Agent实战(十三):智能体集成开发工具的使用

MRS(MounRiverStudio)集成15款支持MCP协议与CLI接口的Windows工具,统一接入智能体MRSAgent,覆盖串口、网络、蓝牙、USB、芯片烧录等嵌入式开发场景。开发者通过自然语言指令即可调用工具,无需手动配置。智能体自动安装并选择合适工具,实现串口调试、网络通信、设备驱动管理、芯片烧录等功能的一键化操作,显著提升开发效率。

qq_36353650的博客 175

基于微信小程序的装修管理系统(源码+脚本+文档)50032

风倍兴提供装修管理小程序全套资源,含源码、数据库脚本、部署文档及工具,基于SpringBoot+小程序+MySQL技术栈,支持快速部署。项目涵盖装修风格、商品展示、详情页及资讯功能,配套截图直观展示界面。如遇环境配置或部署难题,可获远程协助与定制化技术支持,助力高效落地。

tangyuzhidao的博客 67

Java 程序开发笔记:从基础语法到工程实践

Java 开发笔记的价值在于持续积累与复盘。建议把日常遇到的问题、解决方案和代码片段沉淀成个人知识库,定期回顾并更新,逐步形成适合自己的开发习惯。

Linnn_0705的博客 269

医院挂号小程序(源码+脚本+文档)50031

风倍兴推出医院挂号小程序完整解决方案,基于SpringBoot+小程序+MySQL技术栈,提供源码、文档、数据库脚本及部署指导。涵盖登录、预约挂号、排班查询、医生评价等核心功能,支持快速上线。针对部署难题,提供远程协助与定制开发服务,助力项目顺利落地。

tangyuzhidao的博客 42

OpenCode 安装及集成至VsCode及Idea 的详细步骤

本文详细介绍OpenCode的安装与集成流程,涵盖CLI、桌面版及VSCode/IDEA插件的安装方法。核心步骤包括:下载官方独立二进制文件,解压并配置环境变量,验证opencode --version;通过扩展或第三方插件实现VSCode与IntelliJ IDEA集成;最后完成API认证以连接AI模型。全程无需依赖Node.js、Git等工具,支持跨平台使用

mjxin123456的博客 230

Git在局域网里建库并推送保存

在局域网内搭建Git仓库无需公网服务器,可实现本地推送拉取。推荐三种方案:裸仓库(最简单,依赖文件共享,适合2人以下);git-daemon(轻量服务,无共享依赖,适合3~5人技术项目);Gitea(功能完整,支持网页管理与权限控制,适合多人团队)。配合VSCode可无缝操作,克隆、提交、推送均如GitHub。注意开启防火墙端口(9418/3000),设置静态IP,避免地址失效。根据需求快速选型:小团队用裸仓库,追求效率用git-daemon,需管理功能则选Gitea。

cxhust001688的博客 272

开篇|我准备基于Northstar开源底座,自研一套量化平台:鸥泊尔 Oupal Quant

免责声明:本文仅记录量化平台软件开发、源码改造的技术实现,不构成任何投资建议,不提供交易指导,市场有风险,投资需谨慎。大家好,我是程序员王海龙,一名Java后端开发,2020年参加工作,坐标上海浦东。之前一直在后端业务开发方向深耕,最近一段时间,把重心转到这个赛道。经过对比调研,最终选择基于。很多朋友会问:既然有现成开源框架,为什么还要二次改造?这里先说下我的规划和版本选择逻辑:Northstar有很多版本,v9.1.6功能更强,但是前端代码不再开源,只能自己对接接口、重新搭建控制台;而。

weixin_45714733的博客 232

idea安装AI插件DevoxxGenie

所以可以接入。你之前测试成功的。

君临天下tjm的博客 198

2026最新版Qoder 桌面端安装开发指南

本文详细介绍2026版Qoder桌面端在Windows系统的安装与开发流程。文中以生成斐波那契数列求和的Java与Python程序为例,演示从需求输入到代码生成、编译运行的完整过程,展现Qoder高效辅助开发的能力,助力开发者快速构建应用。

jackson_lingua的博客 354

使用并掌握Jupyter Notebook基本功能

1. 安装完成Anaconda、或者单独安装Jupyter Notebook并配置好环境变量后,在windows命令提示符中、或者Linux终端中输入:jupyter notebook ,即可启动Jupyter Notebook(自动在浏览器中打开)编辑模式下按ESC键,或鼠标单击输入框外部区域,即可进入命令模式,此时单元格左侧竖线为蓝色。选中单元格,按Enter键或鼠标单击输入框,即可进入编辑模式,此时单元格左侧竖线为绿色。A) 代码单元(code):用以编写代码(In[ ]中的数字表示代码执行顺序)。

wh_wolf2014的博客 229
上一篇: 当前工程读取配置文件示例
下一篇: netty Getting Started--reference
aebdm757009
博客等级 码龄10年 52粉丝 543原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值