- 浏览: 2652031 次
- 来自: 杭州
文章分类
- 全部博客 (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机器学习库
A random and sequential accessible sequence of zero or more bytes (octets). This interface provides an abstract view for one or more primitive byte arrays (byte[]
) and
NIO buffers
.
Creation of a buffer
It is recommended to create a new buffer using the helper methods in
ChannelBuffers
rather than calling an individual implementation's constructor.
Random Access Indexing
Just like an ordinary primitive byte array,
ChannelBuffer
uses
zero-based indexing
. It means the index of the first byte is always
0
and the index of the last byte is always
capacity - 1
. For example, to iterate all bytes of a buffer, you can do the following, regardless of its internal implementation:
ChannelBuffer buffer = ...; for (int i = 0; i < buffer.capacity(); i ++) { byte b = array.getByte(i); System.out.println((char) b); }
Sequential Access Indexing
ChannelBuffer
provides two pointer variables to support sequential read and write operations -
readerIndex
for a read operation and
writerIndex
for a write operation respectively. The following diagram shows how a buffer is segmented into three areas by the two pointers:
+-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | | | (CONTENT) | | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity
Readable bytes (the actual content)
This segment is where the actual data is stored. Any operation whose name starts with
read
or
skip
will get or skip the data at the current
readerIndex
and increase it by the number of read bytes. If the argument of the read operation is also a
ChannelBuffer
and no destination index is specified, the specified buffer's
readerIndex
is increased together.
If there's not enough content left,
IndexOutOfBoundsException
is raised. The default value of newly allocated, wrapped or copied buffer's
readerIndex
is
0
.
// Iterates the readable bytes of a buffer. ChannelBuffer buffer = ...; while (buffer.readable()) { System.out.println(buffer.readByte()); }
Writable bytes
This segment is a undefined space which needs to be filled. Any operation whose name ends with
write
will write the data at the current
writerIndex
and increase it by the number of written bytes. If the argument of the write operation is also a
ChannelBuffer
, and no source index is specified, the specified buffer's
readerIndex
is increased together.
If there's not enough writable bytes left,
IndexOutOfBoundsException
is raised. The default value of newly allocated buffer's
writerIndex
is
0
. The default value of wrapped or copied buffer's
writerIndex
is the
capacity
of the buffer.
// Fills the writable bytes of a buffer with random integers. ChannelBuffer buffer = ...; while (buffer.writableBytes() >= 4) { buffer.writeInt(random.nextInt()); }
Discardable bytes
This segment contains the bytes which were read already by a read operation. Initially, the size of this segment is
0
, but its size increases up to the
writerIndex
as read operations are executed. The read bytes can be discarded by callingdiscardReadBytes()
to reclaim unused area as depicted by the following diagram:
BEFORE discardReadBytes() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER discardReadBytes() +------------------+--------------------------------------+ | readable bytes | writable bytes (got more space) | +------------------+--------------------------------------+ | | | readerIndex (0) <= writerIndex (decreased) <= capacity
Please note that there is no guarantee about the content of writable bytes after calling
discardReadBytes()
. The writable bytes will not be moved in most cases and could even be filled with completely different data depending on the underlying buffer implementation.
Clearing the buffer indexes
You can set both readerIndex and writerIndex to 0 by calling clear() . It does not clear the buffer content (e.g. filling with
0
) but just clears the two pointers. Please also note that the semantic of this operation is different fromByteBuffer.clear()
.
BEFORE clear() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER clear() +---------------------------------------------------------+ | writable bytes (got more space) | +---------------------------------------------------------+ | | 0 = readerIndex = writerIndex <= capacity
Search operations
Various
indexOf()
methods help you locate an index of a value which meets a certain criteria. Complicated dynamic sequential search can be done with
ChannelBufferIndexFinder
as well as simple static single byte search.
Mark and reset
There are two marker indexes in every buffer. One is for storing
readerIndex
and the other is for storing
writerIndex
. You can always reposition one of the two indexes by calling a reset method. It works in a similar fashion to the mark and reset methods in
InputStream
except that there's no
readlimit
.
Derived buffers
You can create a view of an existing buffer by calling either
duplicate()
,
slice()
or
slice(int, int)
. A derived buffer will have an independent
readerIndex
,
writerIndex
and marker indexes, while it shares other internal data representation, just like a NIO buffer does.
In case a completely fresh copy of an existing buffer is required, please call
copy()
method instead.
Conversion to existing JDK types
NIO Buffers
Various
toByteBuffer()
and
toByteBuffers()
methods convert a
ChannelBuffer
into one or more NIO buffers. These methods avoid buffer allocation and memory copy whenever possible, but there's no guarantee that memory copy will not be involved or that an explicit memory copy will be involved.
Strings
Various
toString(String)
methods convert a
ChannelBuffer
into a
String
. Please note that
toString()
is not a conversion method.
I/O Streams
Please refer to
ChannelBufferInputStream
and
ChannelBufferOutputStream
.
发表评论
-
Netty笔记ReplayingDecoder
2013-03-15 11:39 1312为什么需要ReplayingDecoder,它和FrameD ... -
netty StringDecoderTester
2013-02-21 16:55 1030netty package com.duita ... -
netty文档集合
2013-02-10 13:17 1111Netty 3.1 中文用户手册(一)-序言 Netty ... -
TransferQueue
2013-02-08 14:55 1593在看netty的代码实现发 ... -
FrameDecoder介绍
2012-11-05 18:26 1204FrameDecoder 负责 decodes ... -
netty简单介绍
2012-11-03 20:05 1169ServerBootstrap 启动nett ... -
Netty服务器线程模型概览
2012-10-08 16:57 10876一切从ServerBootstrap开始 ServerB ... -
netty源代码分析
2012-10-08 16:35 963这篇文章(http://san-yun.iteye.com/b ... -
netty ExecutionHandler
2012-10-08 16:34 1524前面(http://san-yun.iteye.com/blo ... -
netty ChannelFuture
2012-10-08 14:12 1335在Netty中所有的io操作都是异步的,这也就是意味任何io访 ... -
netty的一点学习笔记
2012-10-02 22:57 1068原文:http://macrochen.iteye.com/b ... -
Netty实现原理浅析
2012-09-29 15:47 1351Netty是JBoss出品的高效的Java NIO开发框架, ... -
Netty代码分析
2012-09-29 13:22 771参考:http://rdc.taobao.co ... -
netty初探
2011-05-24 15:56 1615netty API //启动类 Server ...
相关推荐
这个过程介绍了如何构建一个基础的Netty服务端和客户端,以及如何处理ChannelBuffer,即Netty中的数据容器。 手册接着提供了对ReceivedData的详解,通过编写Echo服务,即对收到的任何消息进行回显,来进一步解释...
此外,手册还指导开发者如何用 POJO 替换 ChannelBuffer,以提高代码的可读性和易用性,以及如何优雅地关闭应用程序。 第二章则深入介绍了 Netty 的架构概览,包括其丰富的缓存数据结构、统一的异步 I/O API、基于...
- **使用 POJO 代替 ChannelBuffer**:介绍如何使用普通的 Java 对象(POJOs)替代 ChannelBuffer 进行数据交换,提高代码的可读性和可维护性。 - **关闭应用**:正确的关闭顺序对于资源释放至关重要,Netty 提供...
- **1.8 使用 POJO 而不是 ChannelBuffer**:这里介绍了如何使用普通的 Java 对象 (POJO) 来代替 ChannelBuffer 进行数据处理。 - **1.9 关闭你的应用程序**:讲解如何优雅地关闭 Netty 应用程序。 - **1.10 总结**...
- "响应协议服务":介绍了如何向客户端发送响应。 - "时间协议服务":创建一个定时发送消息的服务,展示了 Netty 处理定时任务的能力。 - "时间协议服务客户端":对应的客户端实现,展示如何接收和处理服务端发送...
- **使用 POJO 替代 ChannelBuffer:**Netty 允许开发者使用普通的 Java 对象 (POJO) 来替代 ChannelBuffer 进行数据处理。 - **应用程序关闭:**介绍了如何优雅地关闭 Netty 应用程序,确保所有资源被正确释放。 #...
通过对Netty的总体结构、网络模型以及缓冲机制的介绍,我们可以看出Netty在设计上充分考虑了高性能和灵活性的需求。它不仅提供了简洁易用的API,还通过灵活的配置选项让开发者可以根据具体的业务场景进行定制化调整...
- **1.8 使用POJO代替`ChannelBuffer`**:学习如何使用普通的Java对象(POJOs)代替`ChannelBuffer`进行数据处理。 - **1.9 应用程序关闭**:了解如何优雅地关闭Netty应用程序。 - **1.10 总结**:回顾本章所学的...
2. **ChannelBuffer**:Netty中的ChannelBuffer是用于存储和传输数据的基本单元,类似于Java NIO中的ByteBuffer,但提供了更高级别的操作。它支持零拷贝,高效地处理网络I/O,并提供了一种线程安全的方式来读写数据...
《Netty-3.2.5终极手册》是一本全面介绍Netty 3.2.5版本的指南书籍,旨在为开发者提供快速开发网络应用的方法与技巧。本书不仅涵盖了Netty的基本概念和入门教程,还深入探讨了其架构设计原理及高级特性。 #### 二、...