See: Description
Interface | Description |
---|---|
ByteBufAllocator |
Implementations are responsible to allocate buffers.
|
ByteBufHolder |
A packet which is send or receive.
|
ByteBufProcessor | |
PoolArenaMetric |
Expose metrics for an arena.
|
PoolChunkListMetric |
Metrics for a list of chunks.
|
PoolChunkMetric |
Metrics for a chunk.
|
PoolSubpageMetric |
Metrics for a sub-page.
|
Class | Description |
---|---|
AbstractByteBuf |
A skeletal implementation of a buffer.
|
AbstractByteBufAllocator |
Skeletal
ByteBufAllocator implementation to extend. |
AbstractDerivedByteBuf | Deprecated
Do not use.
|
AbstractReferenceCountedByteBuf |
Abstract base class for
ByteBuf implementations that count references. |
AbstractUnsafeSwappedByteBuf |
Special
SwappedByteBuf for ByteBuf s that is using unsafe. |
AdvancedLeakAwareByteBuf | |
AdvancedLeakAwareCompositeByteBuf | |
ByteBuf |
A random and sequential accessible sequence of zero or more bytes (octets).
|
ByteBufInputStream |
An
InputStream which reads data from a ByteBuf . |
ByteBufOutputStream |
An
OutputStream which writes data to a ByteBuf . |
ByteBufUtil |
A collection of utility methods that is related with handling
ByteBuf ,
such as the generation of hex dump and swapping an integer's byte order. |
ByteBufUtil.HexUtil | |
ByteBufUtil.IndexOfProcessor | |
ByteBufUtil.ThreadLocalDirectByteBuf | |
ByteBufUtil.ThreadLocalUnsafeDirectByteBuf | |
CompositeByteBuf |
A virtual buffer which shows multiple buffers as a single merged buffer.
|
CompositeByteBuf.Component | |
DefaultByteBufHolder |
Default implementation of a
ByteBufHolder that holds it's data in a ByteBuf . |
DuplicatedAbstractByteBuf |
DuplicatedByteBuf implementation that can do optimizations because it knows the duplicated buffer
is of type AbstractByteBuf . |
DuplicatedByteBuf | Deprecated
Do not use.
|
EmptyByteBuf |
An empty
ByteBuf whose capacity and maximum capacity are all 0 . |
FixedCompositeByteBuf | |
FixedCompositeByteBuf.Component | |
HeapByteBufUtil |
Utility class for heap buffers.
|
PoolArena<T> | |
PoolArena.DirectArena | |
PoolArena.HeapArena | |
PoolChunk<T> |
Description of algorithm for PageRun/PoolSubpage allocation from PoolChunk
Notation: The following terms are important to understand the code
> page - a page is the smallest unit of memory chunk that can be allocated
> chunk - a chunk is a collection of pages
> in this code chunkSize = 2^{maxOrder} * pageSize
To begin we allocate a byte array of size = chunkSize
Whenever a ByteBuf of given size needs to be created we search for the first position
in the byte array that has enough empty space to accommodate the requested size and
return a (long) handle that encodes this offset information, (this memory segment is then
marked as reserved so it is always used by exactly one ByteBuf and no more)
For simplicity all sizes are normalized according to PoolArena#normalizeCapacity method
This ensures that when we request for memory segments of size >= pageSize the normalizedCapacity
equals the next nearest power of 2
To search for the first offset in chunk that has at least requested size available we construct a
complete balanced binary tree and store it in an array (just like heaps) - memoryMap
The tree looks like this (the size of each node being mentioned in the parenthesis)
depth=0 1 node (chunkSize)
depth=1 2 nodes (chunkSize/2)
..
|
PoolChunkList<T> | |
PooledByteBuf<T> | |
PooledByteBufAllocator | |
PooledDirectByteBuf | |
PooledHeapByteBuf | |
PooledUnsafeDirectByteBuf | |
PooledUnsafeHeapByteBuf | |
PoolSubpage<T> | |
PoolThreadCache |
Acts a Thread cache for allocations.
|
PoolThreadCache.MemoryRegionCache<T> | |
PoolThreadCache.MemoryRegionCache.Entry<T> | |
PoolThreadCache.NormalMemoryRegionCache<T> |
Cache used for buffers which are backed by NORMAL size.
|
PoolThreadCache.SubPageMemoryRegionCache<T> |
Cache used for buffers which are backed by TINY or SMALL size.
|
ReadOnlyByteBuf | Deprecated
Do not use.
|
ReadOnlyByteBufferBuf |
Read-only ByteBuf which wraps a read-only ByteBuffer.
|
ReadOnlyUnsafeDirectByteBuf |
Read-only ByteBuf which wraps a read-only direct ByteBuffer and use unsafe for best performance.
|
SimpleLeakAwareByteBuf | |
SimpleLeakAwareCompositeByteBuf | |
SlicedAbstractByteBuf |
A special
SlicedByteBuf that can make optimizations because it knows the sliced buffer is of type
AbstractByteBuf . |
SlicedByteBuf | Deprecated
Do not use.
|
SwappedByteBuf |
Wrapper which swap the
ByteOrder of a ByteBuf . |
Unpooled |
Creates a new
ByteBuf by allocating new space or by wrapping
or copying existing byte arrays, byte buffers and a string. |
UnpooledByteBufAllocator |
Simplistic
ByteBufAllocator implementation that does not pool anything. |
UnpooledDirectByteBuf |
A NIO
ByteBuffer based buffer. |
UnpooledHeapByteBuf |
Big endian Java heap buffer implementation.
|
UnpooledUnsafeDirectByteBuf |
A NIO
ByteBuffer based buffer. |
UnpooledUnsafeHeapByteBuf | |
UnpooledUnsafeNoCleanerDirectByteBuf | |
UnreleasableByteBuf |
A
ByteBuf implementation that wraps another buffer to prevent a user from increasing or decreasing the
wrapped buffer's reference count. |
UnsafeByteBufUtil |
All operations get and set as
ByteOrder.BIG_ENDIAN . |
UnsafeDirectSwappedByteBuf | |
UnsafeHeapSwappedByteBuf |
Special
SwappedByteBuf for ByteBuf s that use unsafe to access the byte array. |
WrappedByteBuf |
Wraps another
ByteBuf . |
WrappedCompositeByteBuf | |
WrappedUnpooledUnsafeDirectByteBuf |
Enum | Description |
---|---|
PoolArena.SizeClass |
ByteBuffer
to
represent a sequence of bytes. This approach has significant advantage over
using ByteBuffer
. Netty's new buffer type,
ByteBuf
, 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:
StringBuffer
.flip()
method anymore.ByteBuffer
.ByteBuf
has rich set of operations
optimized for rapid protocol implementation. For example,
ByteBuf
provides various operations
for accessing unsigned values and strings and searching for certain byte
sequence in a buffer. You can also extend or wrap existing buffer type
to add convenient accessors. The custom buffer type still implements
ByteBuf
interface rather than
introducing an incompatible type.
+--------+----------+ | header | body | +--------+----------+If
ByteBuffer
were used, you would have to create a new big
buffer and copy the two parts into the new buffer. Alternatively, you can
perform a gathering write operation in NIO, but it restricts you to represent
the composite of buffers as an array of ByteBuffer
s rather
than a single buffer, breaking the abstraction and introducing complicated
state management. Moreover, it's of no use if you are not going to read or
write from an NIO channel.
// The composite type is incompatible with the component type. ByteBuffer[] message = new ByteBuffer[] { header, body };By contrast,
ByteBuf
does not have such
caveats because it is fully extensible and has a built-in composite buffer
type.
// The composite type is compatible with the component type.ByteBuf
message =Unpooled
.wrappedBuffer(header, body); // Therefore, you can even create a composite by mixing a composite and an // ordinary buffer.ByteBuf
messageWithFooter =Unpooled
.wrappedBuffer(message, footer); // Because the composite is still aByteBuf
, you can access its content // easily, and the accessor method will behave just like it's a single buffer // even if the region you want to access spans over multiple components. The // unsigned integer being read here is located across body and footer. messageWithFooter.getUnsignedInt( messageWithFooter.readableBytes() - footer.readableBytes() - 1);
String
. You often estimate the length
of the resulting string and let StringBuffer
expand itself
on demand.
// A new dynamic buffer is created. Internally, the actual buffer is created // lazily to avoid potentially wasted memory space.ByteBuf
b =Unpooled
.buffer(4); // When the first write attempt is made, the internal buffer is created with // the specified initial capacity (4). b.writeByte('1'); b.writeByte('2'); b.writeByte('3'); b.writeByte('4'); // When the number of written bytes exceeds the initial capacity (4), the // internal buffer is reallocated automatically with a larger capacity. b.writeByte('5');
ByteBuf
is a very thin wrapper of a
byte array (i.e. byte[]
). Unlike ByteBuffer
, it has
no complicated boundary check and index compensation, and therefore it is
easier for a JVM to optimize the buffer access. More complicated buffer
implementation is used only for sliced or composite buffers, and it performs
as well as ByteBuffer
.