public final class LocalBufferPool extends Object implements BufferProvider
GlobalBufferPool.
A local buffer pool mediates buffer requests to the global buffer pool to ensure dead-lock free operation of the network stack by limiting the number of designated buffers per local buffer pool. It also implements the default mechanism for buffer recycling, which ensures that every buffer is ultimately returned to the global buffer pool.
BufferProvider.BufferAvailabilityRegistration| Constructor and Description |
|---|
LocalBufferPool(GlobalBufferPool globalBufferPool,
int numDesignatedBuffers) |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Destroys this local buffer pool and immediately returns all available buffers to the global buffer pool.
|
int |
getBufferSize()
Returns the size of buffers (in bytes) available at this buffer provider.
|
int |
numAvailableBuffers()
Returns the number of buffers available in the local buffer pool.
|
int |
numDesignatedBuffers()
Returns the designated number of buffers for this local buffer pool.
|
int |
numRequestedBuffers()
Returns the number of buffers, which have been requested from the global buffer pool.
|
BufferProvider.BufferAvailabilityRegistration |
registerBufferAvailabilityListener(BufferAvailabilityListener listener)
Registers the given
BufferAvailabilityListener with an empty buffer pool. |
void |
reportAsynchronousEvent()
Reports an asynchronous event and interrupts each blocking method of this buffer provider in order to allow the
blocked thread to respond to the event.
|
Buffer |
requestBuffer(int minBufferSize)
Requests a buffer with a minimum size of
minBufferSize. |
Buffer |
requestBufferBlocking(int minBufferSize)
Requests a buffer with a minimum size of
minBufferSize. |
void |
setNumDesignatedBuffers(int numDesignatedBuffers)
Sets the designated number of buffers for this local buffer pool and returns excess buffers to the global buffer
pool.
|
public LocalBufferPool(GlobalBufferPool globalBufferPool, int numDesignatedBuffers)
public Buffer requestBuffer(int minBufferSize) throws IOException
BufferProviderminBufferSize. The method returns immediately, even if the
request could not be fulfilled.requestBuffer in interface BufferProviderminBufferSize - minimum size of the requested buffer (in bytes)null if no such buffer is currently availableIOExceptionpublic Buffer requestBufferBlocking(int minBufferSize) throws IOException, InterruptedException
BufferProviderminBufferSize. The method blocks until the request has
been fulfilled or BufferProvider.reportAsynchronousEvent() has been called.requestBufferBlocking in interface BufferProviderminBufferSize - minimum size of the requested buffer (in bytes)IOExceptionInterruptedExceptionpublic int getBufferSize()
BufferProvidergetBufferSize in interface BufferProviderpublic void reportAsynchronousEvent()
BufferProviderreportAsynchronousEvent in interface BufferProviderpublic BufferProvider.BufferAvailabilityRegistration registerBufferAvailabilityListener(BufferAvailabilityListener listener)
BufferProviderBufferAvailabilityListener with an empty buffer pool.
The registration only succeeds, if the buffer pool is empty and has not been destroyed yet.
The registered listener will receive a notification when at least one buffer has become available again. After the notification, the listener will be unregistered.
registerBufferAvailabilityListener in interface BufferProviderlistener - the listener to be registeredtrue if the registration has been successful; false if the registration
failed, because the buffer pool was not empty or has already been destroyedpublic void setNumDesignatedBuffers(int numDesignatedBuffers)
The designated number of buffers determines how many buffers this buffer pool is allowed to manage. New buffers can only be requested, if the requested number of buffers is less than the designated number. If possible, excess buffers will be returned to the global buffer pool.
numDesignatedBuffers - number of buffers designated for this local buffer poolpublic int numAvailableBuffers()
public int numRequestedBuffers()
public int numDesignatedBuffers()
public void destroy()
Buffers, which have been requested from this local buffer pool via requestBuffer cannot be returned
immediately and will be returned when the respective buffer is recycled (see recycleBuffer(MemorySegment)).
Copyright © 2014 The Apache Software Foundation. All rights reserved.