Search in sources :

Example 56 with ByteBuf

use of io.netty.buffer.ByteBuf in project netty by netty.

the class ByteBufAllocatorBenchmark method pooledDirectAllocAndFree.

@Benchmark
public void pooledDirectAllocAndFree() {
    int idx = rand.nextInt(pooledDirectBuffers.length);
    ByteBuf oldBuf = pooledDirectBuffers[idx];
    if (oldBuf != null) {
        oldBuf.release();
    }
    pooledDirectBuffers[idx] = pooledAllocator.directBuffer(size);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 57 with ByteBuf

use of io.netty.buffer.ByteBuf in project netty by netty.

the class ByteBufAllocatorBenchmark method unpooledDirectAllocAndFree.

@Benchmark
public void unpooledDirectAllocAndFree() {
    int idx = rand.nextInt(unpooledDirectBuffers.length);
    ByteBuf oldBuf = unpooledDirectBuffers[idx];
    if (oldBuf != null) {
        oldBuf.release();
    }
    unpooledDirectBuffers[idx] = unpooledAllocator.directBuffer(size);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 58 with ByteBuf

use of io.netty.buffer.ByteBuf in project netty by netty.

the class ByteBufAllocatorBenchmark method defaultPooledHeapAllocAndFree.

@Benchmark
public void defaultPooledHeapAllocAndFree() {
    int idx = rand.nextInt(defaultPooledHeapBuffers.length);
    ByteBuf oldBuf = defaultPooledHeapBuffers[idx];
    if (oldBuf != null) {
        oldBuf.release();
    }
    defaultPooledHeapBuffers[idx] = PooledByteBufAllocator.DEFAULT.heapBuffer(size);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 59 with ByteBuf

use of io.netty.buffer.ByteBuf in project netty by netty.

the class SlicedByteBufBenchmark method setup.

@Setup
public void setup() {
    // Use buffer sizes that will also allow to write UTF-8 without grow the buffer
    ByteBuf buffer = Unpooled.buffer(512).retain();
    slicedByteBuf = buffer.slice(0, 256);
    slicedAbstractByteBuf = buffer.slice(0, 256);
    if (slicedByteBuf.getClass() == slicedAbstractByteBuf.getClass()) {
        throw new IllegalStateException();
    }
    StringBuilder asciiSequence = new StringBuilder(128);
    for (int i = 0; i < 128; i++) {
        asciiSequence.append('a');
    }
    ascii = asciiSequence.toString();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Setup(org.openjdk.jmh.annotations.Setup)

Example 60 with ByteBuf

use of io.netty.buffer.ByteBuf in project netty by netty.

the class EmbeddedChannelWriteAccumulatingHandlerContext method writeAndFlush.

@Override
public final ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) {
    try {
        if (msg instanceof ByteBuf) {
            ByteBuf buf = (ByteBuf) msg;
            if (cumulation == null) {
                cumulation = buf;
            } else {
                cumulation = cumulator.cumulate(alloc(), cumulation, buf);
            }
            promise.setSuccess();
        } else {
            channel().writeAndFlush(msg, promise);
        }
    } catch (Exception e) {
        promise.setFailure(e);
        handleException(e);
    }
    return promise;
}
Also used : ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1557 Test (org.junit.Test)668 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)162 IOException (java.io.IOException)99 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)89 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)81 Test (org.testng.annotations.Test)68 InetSocketAddress (java.net.InetSocketAddress)60 Channel (io.netty.channel.Channel)57 ChannelFuture (io.netty.channel.ChannelFuture)56 ArrayList (java.util.ArrayList)55 Map (java.util.Map)45 ChannelPromise (io.netty.channel.ChannelPromise)41 AtomicReference (java.util.concurrent.atomic.AtomicReference)36 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)35 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)34 HashMap (java.util.HashMap)34 CountDownLatch (java.util.concurrent.CountDownLatch)34 RecyclableDuplicateByteBuf (io.netty.buffer.RecyclableDuplicateByteBuf)32 EventLoopGroup (io.netty.channel.EventLoopGroup)32