Apache mina: IoSession.write(Object msg)剖析

2024-02-18 06:58

本文主要是介绍Apache mina: IoSession.write(Object msg)剖析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


在apache mina中通过IoSession 写入数据,返回一个Future可以获取写入数据的结果。

NioSocketSession(AbstractIoSession).write(Object)  


NioSocketSession(AbstractIoSession).write(Object, SocketAddress) .IoSession通过FilterChain 过滤链写出数据。

        // Now, we can write the message. First, create a futureWriteFuture writeFuture = new DefaultWriteFuture(this);WriteRequest writeRequest = new DefaultWriteRequest(message, writeFuture, remoteAddress);// Then, get the chain and inject the WriteRequest into itIoFilterChain filterChain = getFilterChain();filterChain.fireFilterWrite(writeRequest);

DefaultIoFilterChain.callPreviousFilterWrite(IoFilterChain$Entry, IoSession, WriteRequest) 

ProtocolCodecFilter.filterWrite(IoFilter$NextFilter, IoSession, WriteRequest)


在ProtocolCodecFilter 中把Object消息编码后,到达HeadFilter中。在HeadFilter中负责把消息写入消息队列中。

    private class HeadFilter extends IoFilterAdapter {@SuppressWarnings("unchecked")@Overridepublic void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception {AbstractIoSession s = (AbstractIoSession) session;// Maintain counters.if (writeRequest.getMessage() instanceof IoBuffer) {IoBuffer buffer = (IoBuffer) writeRequest.getMessage();// I/O processor implementation will call buffer.reset()// it after the write operation is finished, because// the buffer will be specified with messageSent event.buffer.mark();int remaining = buffer.remaining();if (remaining > 0) {s.increaseScheduledWriteBytes(remaining);}} else {s.increaseScheduledWriteMessages();}//在HeadFilter中把要写入的消息放在WriteRequestQueueWriteRequestQueue writeRequestQueue = s.getWriteRequestQueue();if (!s.isWriteSuspended()) {if (writeRequestQueue.isEmpty(session)) {

这篇关于Apache mina: IoSession.write(Object msg)剖析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/720395

相关文章

深度剖析SpringBoot日志性能提升的原因与解决

《深度剖析SpringBoot日志性能提升的原因与解决》日志记录本该是辅助工具,却为何成了性能瓶颈,SpringBoot如何用代码彻底破解日志导致的高延迟问题,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言第一章:日志性能陷阱的底层原理1.1 日志级别的“双刃剑”效应1.2 同步日志的“吞吐量杀手”

Apache Ignite 与 Spring Boot 集成详细指南

《ApacheIgnite与SpringBoot集成详细指南》ApacheIgnite官方指南详解如何通过SpringBootStarter扩展实现自动配置,支持厚/轻客户端模式,简化Ign... 目录 一、背景:为什么需要这个集成? 二、两种集成方式(对应两种客户端模型) 三、方式一:自动配置 Thick

Apache Ignite缓存基本操作实例详解

《ApacheIgnite缓存基本操作实例详解》文章介绍了ApacheIgnite中IgniteCache的基本操作,涵盖缓存获取、动态创建、销毁、原子及条件更新、异步执行,强调线程池注意事项,避免... 目录一、获取缓存实例(Getting an Instance of a Cache)示例代码:二、动态

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

SpringBoot整合Apache Flink的详细指南

《SpringBoot整合ApacheFlink的详细指南》这篇文章主要为大家详细介绍了SpringBoot整合ApacheFlink的详细过程,涵盖环境准备,依赖配置,代码实现及运行步骤,感兴趣的... 目录1. 背景与目标2. 环境准备2.1 开发工具2.2 技术版本3. 创建 Spring Boot

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

Spring Boot 整合 Apache Flink 的详细过程

《SpringBoot整合ApacheFlink的详细过程》ApacheFlink是一个高性能的分布式流处理框架,而SpringBoot提供了快速构建企业级应用的能力,下面给大家介绍Spri... 目录Spring Boot 整合 Apache Flink 教程一、背景与目标二、环境准备三、创建项目 & 添

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

apache的commons-pool2原理与使用实践记录

《apache的commons-pool2原理与使用实践记录》ApacheCommonsPool2是一个高效的对象池化框架,通过复用昂贵资源(如数据库连接、线程、网络连接)优化系统性能,这篇文章主... 目录一、核心原理与组件二、使用步骤详解(以数据库连接池为例)三、高级配置与优化四、典型应用场景五、注意事

解决Maven项目报错:failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题

《解决Maven项目报错:failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题》这篇文章主要介... 目录Maven项目报错:failed to execute goal org.apache.maven.pl