Removed DataBufferAllocator.allocateHeapBuffer and allocateDirectBuffer in favor of allocateBuffer.
This commit is contained in:
parent
b8f2388d60
commit
66c424daf9
|
|
@ -42,20 +42,6 @@ public interface DataBufferAllocator {
|
|||
*/
|
||||
DataBuffer allocateBuffer(int initialCapacity);
|
||||
|
||||
/**
|
||||
* Allocates a data buffer of the given initial capacity on the heap.
|
||||
* @param initialCapacity the initial capacity of the buffer to allocate
|
||||
* @return the allocated buffer
|
||||
*/
|
||||
DataBuffer allocateHeapBuffer(int initialCapacity);
|
||||
|
||||
/**
|
||||
* Allocates a direct data buffer of the given initial capacity.
|
||||
* @param initialCapacity the initial capacity of the buffer to allocate
|
||||
* @return the allocated buffer
|
||||
*/
|
||||
DataBuffer allocateDirectBuffer(int initialCapacity);
|
||||
|
||||
/**
|
||||
* Wraps the given {@link ByteBuffer} in a {@code DataBuffer}.
|
||||
* @param byteBuffer the NIO byte buffer to wrap
|
||||
|
|
|
|||
|
|
@ -57,18 +57,9 @@ public class DefaultDataBufferAllocator implements DataBufferAllocator {
|
|||
|
||||
@Override
|
||||
public DefaultDataBuffer allocateBuffer(int initialCapacity) {
|
||||
return preferDirect ? allocateDirectBuffer(initialCapacity) :
|
||||
allocateHeapBuffer(initialCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultDataBuffer allocateHeapBuffer(int initialCapacity) {
|
||||
return new DefaultDataBuffer(ByteBuffer.allocate(initialCapacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultDataBuffer allocateDirectBuffer(int initialCapacity) {
|
||||
return new DefaultDataBuffer(ByteBuffer.allocateDirect(initialCapacity));
|
||||
return this.preferDirect ?
|
||||
new DefaultDataBuffer(ByteBuffer.allocateDirect(initialCapacity)) :
|
||||
new DefaultDataBuffer(ByteBuffer.allocate(initialCapacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -60,18 +60,6 @@ public class NettyDataBufferAllocator implements DataBufferAllocator {
|
|||
return new NettyDataBuffer(byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NettyDataBuffer allocateHeapBuffer(int initialCapacity) {
|
||||
ByteBuf byteBuf = this.byteBufAllocator.heapBuffer(initialCapacity);
|
||||
return new NettyDataBuffer(byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NettyDataBuffer allocateDirectBuffer(int initialCapacity) {
|
||||
ByteBuf byteBuf = this.byteBufAllocator.directBuffer(initialCapacity);
|
||||
return new NettyDataBuffer(byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NettyDataBuffer wrap(ByteBuffer byteBuffer) {
|
||||
ByteBuf byteBuf = Unpooled.wrappedBuffer(byteBuffer);
|
||||
|
|
|
|||
|
|
@ -37,28 +37,23 @@ import static org.junit.Assert.assertEquals;
|
|||
@RunWith(Parameterized.class)
|
||||
public class DataBufferTests {
|
||||
|
||||
@Parameterized.Parameter(0)
|
||||
@Parameterized.Parameter
|
||||
public DataBufferAllocator allocator;
|
||||
|
||||
@Parameterized.Parameter(1)
|
||||
public boolean direct;
|
||||
|
||||
@Parameterized.Parameters(name = "{0} - direct: {1}")
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Object[][] buffers() {
|
||||
|
||||
return new Object[][]{
|
||||
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false)), true},
|
||||
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false)),
|
||||
false},
|
||||
{new NettyDataBufferAllocator(new PooledByteBufAllocator(false)), true},
|
||||
{new NettyDataBufferAllocator(new PooledByteBufAllocator(false)), false},
|
||||
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(true))},
|
||||
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false))},
|
||||
{new NettyDataBufferAllocator(new PooledByteBufAllocator(true))},
|
||||
{new NettyDataBufferAllocator(new PooledByteBufAllocator(false))},
|
||||
{new DefaultDataBufferAllocator(), true},
|
||||
{new DefaultDataBufferAllocator(), false}};
|
||||
}
|
||||
|
||||
private DataBuffer createDataBuffer(int capacity) {
|
||||
return direct ? allocator.allocateDirectBuffer(capacity) :
|
||||
allocator.allocateHeapBuffer(capacity);
|
||||
return allocator.allocateBuffer(capacity);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -183,8 +178,7 @@ public class DataBufferTests {
|
|||
}
|
||||
|
||||
private ByteBuffer createByteBuffer(int capacity) {
|
||||
return direct ? ByteBuffer.allocateDirect(capacity) :
|
||||
ByteBuffer.allocate(capacity);
|
||||
return ByteBuffer.allocate(capacity);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue