public class BufferIOController extends Object
ByteBuffer which it lazily obtains from a ObjectPool.
One will be allocated for each request received from a client and another will be allocated to produce the response back to the client.
The flow control methods enable an AbsClientRequestConsumer to read in client request data,
which hands off to a TargetRequestProducer who flips the buffer and writes it's content out to the target.| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
Logger |
| Constructor and Description |
|---|
BufferIOController(org.apache.commons.pool2.ObjectPool<ByteBuffer> bufferPool)
Primary constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
This method MUST be called to clean up any borrowed
ByteBuffers. |
boolean |
dataRead()
This flow control method notifies us that data was read from our buffer (by the 'reading'
IOControl). |
void |
dataWritten()
This flow control method notifies us that data was written to our buffer (by the 'writing'
IOControl). |
ByteBuffer |
getByteBuffer()
Returns the
ByteBuffer, lazily obtaining one from the pool if need be. |
protected org.apache.commons.pool2.ObjectPool<ByteBuffer> |
getPool()
Returns the pool from which this IOEontroller allocates
ByteBuffers. |
void |
setReadingIOControl(org.apache.http.nio.IOControl readingControl)
This flow control method notifies us of the
IOControl that will be reading from our ByteBuffer. |
void |
setWritingIOControl(org.apache.http.nio.IOControl writingControl)
This flow control method notifies us of the
IOControl that will be writing to our ByteBuffer. |
void |
writeCompleted()
This flow control method notifies us that the 'writing'
IOControl has finished writing data to our buffer. |
public BufferIOController(org.apache.commons.pool2.ObjectPool<ByteBuffer> bufferPool)
bufferPool - A reusable pool of ByteBuffers that this object can lazily borrow from (and return to).public void close()
ByteBuffers.protected org.apache.commons.pool2.ObjectPool<ByteBuffer> getPool()
ByteBuffers.
Please use this method responsibly!public ByteBuffer getByteBuffer()
ByteBuffer, lazily obtaining one from the pool if need be.public void setWritingIOControl(org.apache.http.nio.IOControl writingControl)
IOControl that will be writing to our ByteBuffer.public void dataWritten()
IOControl).
This gives us the opportunity to suspend the 'writing' IOControl if our buffer is full and to notify the 'reading' IOControl that data is available.public void writeCompleted()
IOControl has finished writing data to our buffer.
This also gives us the opportunity to notify the 'reading' IOControl that data is available.public void setReadingIOControl(org.apache.http.nio.IOControl readingControl)
IOControl that will be reading from our ByteBuffer.public boolean dataRead()
IOControl).
This gives us the opportunity to suspend the 'reading' IOControl if our buffer has been fully drained,
and to notify the 'writing' IOControl that it may write more data into the buffer.IOControl has notified us that it has completed writing, AND there is no more data in the buffer to be read.Copyright © 2015–2024 Frank Stock. All rights reserved.