- 浏览: 2685558 次
- 来自: 杭州
-
文章分类
- 全部博客 (1188)
- webwork (4)
- 网摘 (18)
- java (103)
- hibernate (1)
- Linux (85)
- 职业发展 (1)
- activeMQ (2)
- netty (14)
- svn (1)
- webx3 (12)
- mysql (81)
- css (1)
- HTML (6)
- apache (3)
- 测试 (2)
- javascript (1)
- 储存 (1)
- jvm (5)
- code (13)
- 多线程 (12)
- Spring (18)
- webxs (2)
- python (119)
- duitang (0)
- mongo (3)
- nosql (4)
- tomcat (4)
- memcached (20)
- 算法 (28)
- django (28)
- shell (1)
- 工作总结 (5)
- solr (42)
- beansdb (6)
- nginx (3)
- 性能 (30)
- 数据推荐 (1)
- maven (8)
- tonado (1)
- uwsgi (5)
- hessian (4)
- ibatis (3)
- Security (2)
- HTPP (1)
- gevent (6)
- 读书笔记 (1)
- Maxent (2)
- mogo (0)
- thread (3)
- 架构 (5)
- NIO (5)
- 正则 (1)
- lucene (5)
- feed (4)
- redis (17)
- TCP (6)
- test (0)
- python,code (1)
- PIL (3)
- guava (2)
- jython (4)
- httpclient (2)
- cache (3)
- signal (1)
- dubbo (7)
- HTTP (4)
- json (3)
- java socket (1)
- io (2)
- socket (22)
- hash (2)
- Cassandra (1)
- 分布式文件系统 (5)
- Dynamo (2)
- gc (8)
- scp (1)
- rsync (1)
- mecached (0)
- mongoDB (29)
- Thrift (1)
- scribe (2)
- 服务化 (3)
- 问题 (83)
- mat (1)
- classloader (2)
- javaBean (1)
- 文档集合 (27)
- 消息队列 (3)
- nginx,文档集合 (1)
- dboss (12)
- libevent (1)
- 读书 (0)
- 数学 (3)
- 流程 (0)
- HBase (34)
- 自动化测试 (1)
- ubuntu (2)
- 并发 (1)
- sping (1)
- 图形 (1)
- freemarker (1)
- jdbc (3)
- dbcp (0)
- sharding (1)
- 性能测试 (1)
- 设计模式 (2)
- unicode (1)
- OceanBase (3)
- jmagick (1)
- gunicorn (1)
- url (1)
- form (1)
- 安全 (2)
- nlp (8)
- libmemcached (1)
- 规则引擎 (1)
- awk (2)
- 服务器 (1)
- snmpd (1)
- btrace (1)
- 代码 (1)
- cygwin (1)
- mahout (3)
- 电子书 (1)
- 机器学习 (5)
- 数据挖掘 (1)
- nltk (6)
- pool (1)
- log4j (2)
- 总结 (11)
- c++ (1)
- java源代码 (1)
- ocr (1)
- 基础算法 (3)
- SA (1)
- 笔记 (1)
- ml (4)
- zokeeper (0)
- jms (1)
- zookeeper (5)
- zkclient (1)
- hadoop (13)
- mq (2)
- git (9)
- 问题,io (1)
- storm (11)
- zk (1)
- 性能优化 (2)
- example (1)
- tmux (1)
- 环境 (2)
- kyro (1)
- 日志系统 (3)
- hdfs (2)
- python_socket (2)
- date (2)
- elasticsearch (1)
- jetty (1)
- 树 (1)
- 汽车 (1)
- mdrill (1)
- 车 (1)
- 日志 (1)
- web (1)
- 编译原理 (1)
- 信息检索 (1)
- 性能,linux (1)
- spam (1)
- 序列化 (1)
- fabric (2)
- guice (1)
- disruptor (1)
- executor (1)
- logback (2)
- 开源 (1)
- 设计 (1)
- 监控 (3)
- english (1)
- 问题记录 (1)
- Bitmap (1)
- 云计算 (1)
- 问题排查 (1)
- highchat (1)
- mac (3)
- docker (1)
- jdk (1)
- 表达式 (1)
- 网络 (1)
- 时间管理 (1)
- 时间序列 (1)
- OLAP (1)
- Big Table (0)
- sql (1)
- kafka (1)
- md5 (1)
- springboot (1)
- spring security (1)
- Spring Boot (3)
- mybatis (1)
- java8 (1)
- 分布式事务 (1)
- 限流 (1)
- Shadowsocks (0)
- 2018 (1)
- 服务治理 (1)
- 设计原则 (1)
- log (0)
- perftools (1)
最新评论
-
siphlina:
课程——基于Python数据分析与机器学习案例实战教程分享网盘 ...
Python机器学习库 -
san_yun:
leibnitz 写道hi,我想知道,无论在92还是94版本, ...
hbase的行锁与多版本并发控制(MVCC) -
leibnitz:
hi,我想知道,无论在92还是94版本,更新时(如Puts)都 ...
hbase的行锁与多版本并发控制(MVCC) -
107x:
不错,谢谢!
Latent Semantic Analysis(LSA/ LSI)算法简介 -
107x:
不错,谢谢!
Python机器学习库
FrameDecoder 负责 decodes the received
ChannelBuffer
s into a meaningful frame object.
In a stream-based transport such as TCP/IP, packets can be fragmented and reassembled during transmission even in a LAN environment. For example, let us assume you have received three packets:
+-----+-----+-----+ | ABC | DEF | GHI | +-----+-----+-----+
because of the packet fragmentation, a server can receive them like the following:
+----+-------+---+---+ | AB | CDEFG | H | I | +----+-------+---+---+
FrameDecoder
helps you defrag the received packets into one or more meaningful
frames
that could be easily understood by the application logic. In case of the example above, your
FrameDecoder
implementation could defrag the received packets like the following:
+-----+-----+-----+ | ABC | DEF | GHI | +-----+-----+-----+
The following code shows an example handler which decodes a frame whose first 4 bytes header represents the length of the frame, excluding the header.
MESSAGE FORMAT ============== Offset: 0 4 (Length + 4) +--------+------------------------+ Fields: | Length | Actual message content | +--------+------------------------+ DECODER IMPLEMENTATION ====================== public class IntegerHeaderFrameDecoder extends FrameDecoder { protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { // Make sure if the length field was received. if (buf.readableBytes() < 4) { // The length field was not received yet - return null. // This method will be invoked again when more packets are // received and appended to the buffer. return null ; } // The length field is in the buffer. // Mark the current buffer position before reading the length field // because the whole frame might not be in the buffer yet. // We will reset the buffer position to the marked position if // there's not enough bytes in the buffer. buf.markReaderIndex(); // Read the length field. int length = buf.readInt(); // Make sure if there's enough bytes in the buffer. if (buf.readableBytes() < length) { // The whole bytes were not received yet - return null. // This method will be invoked again when more packets are // received and appended to the buffer. // Reset to the marked position to read the length field again // next time. buf.resetReaderIndex(); return null ; } // There's enough bytes in the buffer. Read it. ChannelBuffer frame = buf.readBytes(length); // Successfully decoded a frame. Return the decoded frame. return frame ; } }
Returning a POJO rather than a
ChannelBuffer
Please note that you can return an object of a different type than
ChannelBuffer
in your
decode()
and
decodeLast()
implementation. For example, you could return a
POJO
so that the next
ChannelUpstreamHandler
receives a
MessageEvent
which contains a POJO rather than a
ChannelBuffer
.
Replacing a decoder with another decoder in a pipeline
If you are going to write a protocol multiplexer, you will probably want to replace a
FrameDecoder
(protocol detector) with another
FrameDecoder
or
ReplayingDecoder
(actual protocol decoder). It is not possible to achieve this simply by callingChannelPipeline.replace(ChannelHandler, String, ChannelHandler)
, but some additional steps are required:
public class FirstDecoder extends FrameDecoder { public FirstDecoder() { super(true); // Enable unfold } protected Object decode(ChannelHandlerContext ctx, Channel ch, ChannelBuffer buf) { ... // Decode the first message Object firstMessage = ...; // Add the second decoder ctx.getPipeline().addLast("second", new SecondDecoder()); // Remove the first decoder (me) ctx.getPipeline().remove(this); if (buf.readable()) { // Hand off the remaining data to the second decoder return new Object[] { firstMessage, buf.readBytes(buf.readableBytes()) }; } else { // Nothing to hand off return firstMessage; } } }
发表评论
-
Netty笔记ReplayingDecoder
2013-03-15 11:39 1337为什么需要ReplayingDecoder,它和FrameD ... -
netty StringDecoderTester
2013-02-21 16:55 1048netty package com.duita ... -
netty文档集合
2013-02-10 13:17 1141Netty 3.1 中文用户手册(一)-序言 Netty ... -
TransferQueue
2013-02-08 14:55 1625在看netty的代码实现发 ... -
ChannelBuffer介绍介绍
2012-11-07 11:28 877A random and sequential ... -
netty简单介绍
2012-11-03 20:05 1181ServerBootstrap 启动nett ... -
Netty服务器线程模型概览
2012-10-08 16:57 10922一切从ServerBootstrap开始 ServerB ... -
netty源代码分析
2012-10-08 16:35 981这篇文章(http://san-yun.iteye.com/b ... -
netty ExecutionHandler
2012-10-08 16:34 1548前面(http://san-yun.iteye.com/blo ... -
netty ChannelFuture
2012-10-08 14:12 1360在Netty中所有的io操作都是异步的,这也就是意味任何io访 ... -
netty的一点学习笔记
2012-10-02 22:57 1094原文:http://macrochen.iteye.com/b ... -
Netty实现原理浅析
2012-09-29 15:47 1383Netty是JBoss出品的高效的Java NIO开发框架, ... -
Netty代码分析
2012-09-29 13:22 785参考:http://rdc.taobao.co ... -
netty初探
2011-05-24 15:56 1647netty API //启动类 Server ...
相关推荐
本示例将详细介绍Netty如何实现心跳检测。 在Netty中,心跳检测通常通过自定义的`FrameDecoder`、`FrameEncoder`和`ChannelInboundHandler`来完成。下面我们将逐步解释这些组件的作用以及如何构建心跳检测机制。 1...
11. **FrameDecoder**:FrameDecoder是Netty中用于解码网络数据包的组件,它将接收到的数据分割成有意义的帧。例如,DelimiterBasedFrameDecoder基于分隔符解码,而LengthFieldBasedFrameDecoder则根据长度字段进行...
下面将详细介绍Unity中的Socket通信以及粘包处理的相关知识。 Unity中的Socket通信: Socket是网络编程的基础,它提供了一种进程间通信的方式,使得运行在不同计算机上的程序能够通过网络交换数据。在Unity中,我们...
以上就是Netty面试专题1中的核心知识点,包括对BIO、NIO、AIO的理解,NIO组件的详细说明,Netty线程模型,TCP粘包/拆包问题的解决,以及序列化协议的介绍。理解这些内容对于深入学习Netty和提升网络编程技能至关重要...
下面将详细介绍如何使用Netty实现心跳检测以及断线后的自动重连功能。 1. **心跳机制** - 心跳包:在网络通信中,心跳包用于检测连接的活性。当连接长时间没有数据传输时,双方可以通过发送心跳包来确认对方是否还...
.frameDecoder(PayloadDecoder.ZERO_COPY) .transport(TcpClientTransport.create(7000)) .start() .block(); } @Bean RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) { return ...
一、Netty 框架介绍 Netty 是由 JBoss 提供的一个开源框架,它提供了对 TCP、UDP 和 HTTP 等多种协议的支持,简化了网络编程的复杂性。Netty 的核心是其 Channel 和 EventLoop 模型,它们使得 I/O 操作变得高效且...
**Netty的HTTP2介绍** Netty是一个高性能、异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端。在HTTP2协议出现后,Netty也提供了对HTTP2的支持,使得开发者能够方便地在Java环境中...