APIdia Launch Partner
Top Description Methods
jdk.internal.net.http.common

public Interface BufferSupplier

extends Supplier<ByteBuffer>
Known Direct Implementers
jdk.internal.net.http.HttpClientImpl.SSLDirectBufferSupplier
Imports
java.nio.ByteBuffer, java.util.concurrent.ConcurrentLinkedQueue, java.util.function.Supplier

This interface allows to recycle buffers used for SSL decryption. Buffers that are used for reading SSL encrypted data are typically very short lived, as it is necessary to aggregate their content before calling SSLEngine::unwrap. Because both reading and copying happen in the SelectorManager thread, then it makes it possible to pool these buffers and recycle them for the next socket read, instead of simply letting them be GC'ed. That also makes it possible to use direct byte buffers, and avoid another layer of copying by the SocketChannel implementation. The HttpClientImpl has an implementation of this interface that allows to reuse the same 3 direct buffers for reading off SSL encrypted data from the socket. The BufferSupplier::get method is called by SocketTube (see SocketTube.SSLDirectBufferSource) and BufferSupplier::recycle is called by SSLFlowDelegate.Reader.

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer

Returns:

a buffer to read encrypted data off the socket.
get
()

Redeclares java.util.function.Supplier.get.

Returns a buffer to read encrypted data off the socket.

public void
recycle(ByteBuffer
This must be a buffer previously obtained by calling BufferSupplier::get. The caller must not touch the buffer after returning it to the pool.
buffer
)

Returns a buffer to the pool.

Method Detail

getback to summary
public ByteBuffer get()

Redeclares java.util.function.Supplier.get.

Returns a buffer to read encrypted data off the socket.

Returns:ByteBuffer

a buffer to read encrypted data off the socket.

recycleback to summary
public void recycle(ByteBuffer buffer)

Returns a buffer to the pool.

Parameters
buffer:ByteBuffer

This must be a buffer previously obtained by calling BufferSupplier::get. The caller must not touch the buffer after returning it to the pool.