use of io.netty.util.internal.RecyclableArrayList in project netty by netty.
the class EmbeddedChannel method writeOutbound.
/**
* Write messages to the outbound of this {@link Channel}.
*
* @param msgs the messages to be written
* @return bufferReadable returns {@code true} if the write operation did add something to the outbound buffer
*/
public boolean writeOutbound(Object... msgs) {
ensureOpen();
if (msgs.length == 0) {
return isNotEmpty(outboundMessages);
}
RecyclableArrayList futures = RecyclableArrayList.newInstance(msgs.length);
try {
for (Object m : msgs) {
if (m == null) {
break;
}
futures.add(write(m));
}
flushOutbound0();
int size = futures.size();
for (int i = 0; i < size; i++) {
ChannelFuture future = (ChannelFuture) futures.get(i);
if (future.isDone()) {
recordException(future);
} else {
// The write may be delayed to run later by runPendingTasks()
future.addListener(recordExceptionListener);
}
}
checkException();
return isNotEmpty(outboundMessages);
} finally {
futures.recycle();
}
}
use of io.netty.util.internal.RecyclableArrayList in project netty by netty.
the class FixedCompositeByteBuf method nioBuffers.
@Override
public ByteBuffer[] nioBuffers(int index, int length) {
checkIndex(index, length);
if (length == 0) {
return EmptyArrays.EMPTY_BYTE_BUFFERS;
}
RecyclableArrayList array = RecyclableArrayList.newInstance(buffers.length);
try {
Component c = findComponent(index);
int i = c.index;
int adjustment = c.offset;
ByteBuf s = c.buf;
for (; ; ) {
int localLength = Math.min(length, s.readableBytes() - (index - adjustment));
switch(s.nioBufferCount()) {
case 0:
throw new UnsupportedOperationException();
case 1:
array.add(s.nioBuffer(index - adjustment, localLength));
break;
default:
Collections.addAll(array, s.nioBuffers(index - adjustment, localLength));
}
index += localLength;
length -= localLength;
adjustment += s.readableBytes();
if (length <= 0) {
break;
}
s = buffer(++i);
}
return array.toArray(new ByteBuffer[array.size()]);
} finally {
array.recycle();
}
}
use of io.netty.util.internal.RecyclableArrayList in project netty by netty.
the class RecyclableArrayListBenchmark method recycleSameThread.
@Benchmark
public void recycleSameThread() {
RecyclableArrayList list = RecyclableArrayList.newInstance(size);
list.recycle();
}
Aggregations