dschneider-pivotal commented on code in PR #7621:
URL: https://github.com/apache/geode/pull/7621#discussion_r859088287
##########
geode-core/src/main/java/org/apache/geode/internal/net/BufferPool.java:
##########
@@ -90,46 +87,46 @@ static boolean computeUseDirectBuffers() {
*
* @return a byte buffer to be used for sending on this connection.
*/
- public ByteBuffer acquireDirectSenderBuffer(int size) {
+ public PooledByteBuffer acquireDirectSenderBuffer(int size) {
return acquireDirectBuffer(size, true);
}
- public ByteBuffer acquireDirectReceiveBuffer(int size) {
+ public PooledByteBuffer acquireDirectReceiveBuffer(int size) {
return acquireDirectBuffer(size, false);
}
/**
* try to acquire direct buffer, if enabled by configuration
*/
- private ByteBuffer acquireDirectBuffer(int size, boolean send) {
- ByteBuffer result;
+ private PooledByteBuffer acquireDirectBuffer(int size, boolean send) {
+ ByteBuffer byteBuffer;
if (useDirectBuffers) {
if (size <= MEDIUM_BUFFER_SIZE) {
- result = acquirePredefinedFixedBuffer(send, size);
+ byteBuffer = acquirePredefinedFixedBuffer(send, size);
} else {
- result = acquireLargeBuffer(send, size);
+ byteBuffer = acquireLargeBuffer(send, size);
}
- if (result.capacity() > size) {
- result.position(0).limit(size);
- result = result.slice();
+ if (byteBuffer.capacity() > size) {
+ byteBuffer.position(0).limit(size);
+ return new PooledByteBuffer(byteBuffer, byteBuffer.slice());
}
- return result;
+ return new PooledByteBuffer(byteBuffer);
}
// if we are using heap buffers then don't bother with keeping them around
- result = ByteBuffer.allocate(size);
+ byteBuffer = ByteBuffer.allocate(size);
updateBufferStats(size, send, false);
- return result;
+ return new PooledByteBuffer(byteBuffer);
Review Comment:
because we obtains it from the BufferPool. Additional refactoring could be
done to not obtain it from BufferPool (the heap buffer are not actually pooled
so why do we ask BufferPool for one) but that seemed outside the scope of this
PR which was to not export sun.nio.ch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]