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);
|
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}.
|
* Wraps the given {@link ByteBuffer} in a {@code DataBuffer}.
|
||||||
* @param byteBuffer the NIO byte buffer to wrap
|
* @param byteBuffer the NIO byte buffer to wrap
|
||||||
|
|
|
||||||
|
|
@ -57,18 +57,9 @@ public class DefaultDataBufferAllocator implements DataBufferAllocator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefaultDataBuffer allocateBuffer(int initialCapacity) {
|
public DefaultDataBuffer allocateBuffer(int initialCapacity) {
|
||||||
return preferDirect ? allocateDirectBuffer(initialCapacity) :
|
return this.preferDirect ?
|
||||||
allocateHeapBuffer(initialCapacity);
|
new DefaultDataBuffer(ByteBuffer.allocateDirect(initialCapacity)) :
|
||||||
}
|
new DefaultDataBuffer(ByteBuffer.allocate(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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -60,18 +60,6 @@ public class NettyDataBufferAllocator implements DataBufferAllocator {
|
||||||
return new NettyDataBuffer(byteBuf);
|
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
|
@Override
|
||||||
public NettyDataBuffer wrap(ByteBuffer byteBuffer) {
|
public NettyDataBuffer wrap(ByteBuffer byteBuffer) {
|
||||||
ByteBuf byteBuf = Unpooled.wrappedBuffer(byteBuffer);
|
ByteBuf byteBuf = Unpooled.wrappedBuffer(byteBuffer);
|
||||||
|
|
|
||||||
|
|
@ -37,28 +37,23 @@ import static org.junit.Assert.assertEquals;
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class DataBufferTests {
|
public class DataBufferTests {
|
||||||
|
|
||||||
@Parameterized.Parameter(0)
|
@Parameterized.Parameter
|
||||||
public DataBufferAllocator allocator;
|
public DataBufferAllocator allocator;
|
||||||
|
|
||||||
@Parameterized.Parameter(1)
|
@Parameterized.Parameters(name = "{0}")
|
||||||
public boolean direct;
|
|
||||||
|
|
||||||
@Parameterized.Parameters(name = "{0} - direct: {1}")
|
|
||||||
public static Object[][] buffers() {
|
public static Object[][] buffers() {
|
||||||
|
|
||||||
return new Object[][]{
|
return new Object[][]{
|
||||||
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false)), true},
|
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(true))},
|
||||||
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false)),
|
{new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false))},
|
||||||
false},
|
{new NettyDataBufferAllocator(new PooledByteBufAllocator(true))},
|
||||||
{new NettyDataBufferAllocator(new PooledByteBufAllocator(false)), true},
|
{new NettyDataBufferAllocator(new PooledByteBufAllocator(false))},
|
||||||
{new NettyDataBufferAllocator(new PooledByteBufAllocator(false)), false},
|
|
||||||
{new DefaultDataBufferAllocator(), true},
|
{new DefaultDataBufferAllocator(), true},
|
||||||
{new DefaultDataBufferAllocator(), false}};
|
{new DefaultDataBufferAllocator(), false}};
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataBuffer createDataBuffer(int capacity) {
|
private DataBuffer createDataBuffer(int capacity) {
|
||||||
return direct ? allocator.allocateDirectBuffer(capacity) :
|
return allocator.allocateBuffer(capacity);
|
||||||
allocator.allocateHeapBuffer(capacity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -183,8 +178,7 @@ public class DataBufferTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteBuffer createByteBuffer(int capacity) {
|
private ByteBuffer createByteBuffer(int capacity) {
|
||||||
return direct ? ByteBuffer.allocateDirect(capacity) :
|
return ByteBuffer.allocate(capacity);
|
||||||
ByteBuffer.allocate(capacity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue