Top Description Inners Fields Constructors Methods
io.netty5.buffer

public final Class DefaultBufferAllocators

extends Object
Class Inheritance
Imports
io.netty5.util.internal.PlatformDependent, .SystemPropertyUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.util.Locale, java.util.function.Supplier

Accessor for the default, shared BufferAllocator instances. Two allocators are provided; one on-heap allocator, and one off-heap allocator.

These default allocators are configured via system properties.

These allocators cannot be closed directly. They will instead be disposed of when the Runtime is shutdown.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final BufferAllocator
private static final BufferAllocator
private static final BufferAllocator
private static final InternalLogger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BufferAllocator

Returns:

The shared off-heap allocator.
offHeapAllocator
()

Get the shared off-heap allocator.

public static BufferAllocator

Returns:

The shared on-heap allocator.
onHeapAllocator
()

Get the shared on-heap allocator.

public static BufferAllocator

Returns:

The shared, generally preferred allocator.
preferredAllocator
()

Get the preferred, shared allocator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_OFF_HEAP_ALLOCATORback to summary
private static final BufferAllocator DEFAULT_OFF_HEAP_ALLOCATOR
DEFAULT_ON_HEAP_ALLOCATORback to summary
private static final BufferAllocator DEFAULT_ON_HEAP_ALLOCATOR
DEFAULT_PREFERRED_ALLOCATORback to summary
private static final BufferAllocator DEFAULT_PREFERRED_ALLOCATOR
loggerback to summary
private static final InternalLogger logger

Constructor Detail

DefaultBufferAllocatorsback to summary
private DefaultBufferAllocators()

Method Detail

offHeapAllocatorback to summary
public static BufferAllocator offHeapAllocator()

Get the shared off-heap allocator. This allocator always allocates off-heap buffers, and is either pooled, or unpooled.

Returns:BufferAllocator

The shared off-heap allocator.

onHeapAllocatorback to summary
public static BufferAllocator onHeapAllocator()

Get the shared on-heap allocator. This allocator always allocates on-heap buffers, and is either pooled, or unpooled.

Returns:BufferAllocator

The shared on-heap allocator.

preferredAllocatorback to summary
public static BufferAllocator preferredAllocator()

Get the preferred, shared allocator. This allocator is either on- or off-heap, and either pooling or unpooled, depending on the global configuration.

Returns:BufferAllocator

The shared, generally preferred allocator.

io.netty5.buffer back to summary

private final Class DefaultBufferAllocators.UncloseableBufferAllocator

extends Object
implements BufferAllocator
Class Inheritance
  • java.lang.Object
  • io.netty5.buffer.DefaultBufferAllocators.UncloseableBufferAllocator
All Implemented Interfaces
io.netty5.buffer.BufferAllocator, io.netty5.util.SafeCloseable, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
private final BufferAllocator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Buffer
allocate(int
The size of Buffer to allocate.
size
)

Implements io.netty5.buffer.BufferAllocator.allocate.

Allocate a Buffer of the given size in bytes.
public void
close()

Implements io.netty5.buffer.BufferAllocator.close.

Close this allocator, freeing all of its internal resources.
public Supplier<Buffer>
constBufferSupplier(byte[]
The byte contents of the buffers produced by the returned supplier.
bytes
)

Implements io.netty5.buffer.BufferAllocator.constBufferSupplier.

Create a supplier of "constant" Buffers from this allocator, that all have the given byte contents.
public AllocationType
public boolean
isPooling()

Implements io.netty5.buffer.BufferAllocator.isPooling.

Determine if this allocator is pooling and reusing its allocated memory.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final BufferAllocator delegate

Constructor Detail

UncloseableBufferAllocatorback to summary
pack-priv UncloseableBufferAllocator(BufferAllocator delegate)

Method Detail

allocateback to summary
public Buffer allocate(int size)

Implements io.netty5.buffer.BufferAllocator.allocate.

Doc from io.netty5.buffer.BufferAllocator.allocate.

Allocate a Buffer of the given size in bytes. This method may throw an OutOfMemoryError if there is not enough free memory available to allocate a Buffer of the requested size.

The buffer will use big endian byte order.

Note

unlike the JDK ByteBuffers, Netty Buffers are not guaranteed to be zeroed when allocated. In other words, the memory of a newly allocated buffer may contain garbage data from prior allocations, and the memory is likewise not guaranteed to be erased when the buffer is closed. If the data is sensitive and needs to be overwritten when the buffer is closed, then the buffer should be allocated with the SensitiveBufferAllocator.

Parameters
size:int

The size of Buffer to allocate.

Returns:Buffer

The newly allocated Buffer.

Annotations
@Override
closeback to summary
public void close()

Implements io.netty5.buffer.BufferAllocator.close.

Doc from io.netty5.buffer.BufferAllocator.close.

Close this allocator, freeing all of its internal resources.

Existing (currently in-use) allocated buffers will not be impacted by calling this method. If this is a pooling or caching allocator, then existing buffers will be immediately freed when they are closed, instead of being pooled or cached.

The allocator can no longer be used to allocate more buffers after calling this method. Attempting to allocate from a closed allocator will cause IllegalStateExceptions to be thrown.

Annotations
@Override
Exceptions
UnsupportedOperationException:
Close is not supported on this allocator.
constBufferSupplierback to summary
public Supplier<Buffer> constBufferSupplier(byte[] bytes)

Implements io.netty5.buffer.BufferAllocator.constBufferSupplier.

Doc from io.netty5.buffer.BufferAllocator.constBufferSupplier.

Create a supplier of "constant" Buffers from this allocator, that all have the given byte contents. The buffer has the same capacity as the byte array length, and its write offset is placed at the end, and its read offset is at the beginning, such that the entire buffer contents are readable.

The buffers produced by the supplier will each have their own independent life-cycle, and closing them will make them inaccessible, just like normally allocated buffers.

The buffers produced are "constants", in the sense that they are read-only.

It can generally be expected, but is not guaranteed, that the returned supplier is more resource efficient than allocating and copying memory with other available APIs. In such optimised implementations, the underlying memory baking the buffers will be shared among all the buffers produced by the supplier.

The primary use case for this API, is when you need to repeatedly produce buffers with the same contents, and you perhaps wish to keep a static final field with these contents. The supplier-based API enforces that each usage get their own distinct buffer instance. Each of these instances cannot interfere with each other, so bugs like closing, or modifying the contents, of a shared buffer cannot occur.

Parameters
bytes:byte[]

The byte contents of the buffers produced by the returned supplier.

Returns:Supplier<Buffer>

A supplier of read-only buffers with the given contents.

Annotations
@Override
getAllocationTypeback to summary
public AllocationType getAllocationType()

Implements io.netty5.buffer.BufferAllocator.getAllocationType.

Doc from io.netty5.buffer.BufferAllocator.getAllocationType.

Get the AllocationType from this allocator. This would typically be one of the StandardAllocationTypes.

Returns:AllocationType

The type of allocations performed by this allocator.

Annotations
@Override
isPoolingback to summary
public boolean isPooling()

Implements io.netty5.buffer.BufferAllocator.isPooling.

Doc from io.netty5.buffer.BufferAllocator.isPooling.

Determine if this allocator is pooling and reusing its allocated memory.

Returns:boolean

true if this allocator is pooling and reusing its memory, false otherwise.

Annotations
@Override