Search in sources :

Example 1 with ByteBufAllocator

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

the class ReferenceCountedOpenSslContext method toBIO.

/**
     * Return the pointer to a <a href="https://www.openssl.org/docs/crypto/BIO_get_mem_ptr.html">in-memory BIO</a>
     * or {@code 0} if the {@code key} is {@code null}. The BIO contains the content of the {@code key}.
     */
static long toBIO(PrivateKey key) throws Exception {
    if (key == null) {
        return 0;
    }
    ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
    PemEncoded pem = PemPrivateKey.toPEM(allocator, true, key);
    try {
        return toBIO(allocator, pem.retain());
    } finally {
        pem.release();
    }
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator)

Example 2 with ByteBufAllocator

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

the class ReferenceCountedOpenSslContext method toBIO.

/**
     * Return the pointer to a <a href="https://www.openssl.org/docs/crypto/BIO_get_mem_ptr.html">in-memory BIO</a>
     * or {@code 0} if the {@code certChain} is {@code null}. The BIO contains the content of the {@code certChain}.
     */
static long toBIO(X509Certificate... certChain) throws Exception {
    if (certChain == null) {
        return 0;
    }
    if (certChain.length == 0) {
        throw new IllegalArgumentException("certChain can't be empty");
    }
    ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
    PemEncoded pem = PemX509Certificate.toPEM(allocator, true, certChain);
    try {
        return toBIO(allocator, pem.retain());
    } finally {
        pem.release();
    }
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator)

Example 3 with ByteBufAllocator

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

the class AbstractTestsuiteTest method run.

protected void run() throws Throwable {
    List<TestsuitePermutation.BootstrapFactory<T>> combos = newFactories();
    for (ByteBufAllocator allocator : newAllocators()) {
        int i = 0;
        for (TestsuitePermutation.BootstrapFactory<T> e : combos) {
            cb = e.newInstance();
            configure(cb, allocator);
            logger.info(String.format("Running: %s %d of %d with %s", testName.getMethodName(), ++i, combos.size(), StringUtil.simpleClassName(allocator)));
            try {
                Method m = getClass().getMethod(TestUtils.testMethodName(testName), clazz);
                m.invoke(this, cb);
            } catch (InvocationTargetException ex) {
                throw ex.getCause();
            }
        }
    }
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ByteBufAllocator

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

the class Http2FrameWriterBenchmark method boostrapEmbeddedEnv.

private static Environment boostrapEmbeddedEnv(final EnvironmentType environmentType) {
    final ByteBufAllocator alloc = environmentType.params().clientAllocator();
    final EmbeddedEnvironment env = new EmbeddedEnvironment(new DefaultHttp2FrameWriter());
    final Http2Connection connection = new DefaultHttp2Connection(false);
    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, env.writer());
    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, new DefaultHttp2FrameReader());
    Http2ConnectionHandler connectionHandler = new Http2ConnectionHandlerBuilder().encoderEnforceMaxConcurrentStreams(false).frameListener(new Http2FrameAdapter()).codec(decoder, encoder).build();
    env.context(new EmbeddedChannelWriteReleaseHandlerContext(alloc, connectionHandler) {

        @Override
        protected void handleException(Throwable t) {
            handleUnexpectedException(t);
        }
    });
    return env;
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) Http2ConnectionHandlerBuilder(io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder) EmbeddedChannelWriteReleaseHandlerContext(io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader)

Example 5 with ByteBufAllocator

use of io.netty.buffer.ByteBufAllocator in project neo4j by neo4j.

the class BoltProtocolV1Test method newChannelMock.

private static Channel newChannelMock() {
    Channel channel = mock(Channel.class);
    ByteBufAllocator allocator = mock(ByteBufAllocator.class, RETURNS_MOCKS);
    when(channel.alloc()).thenReturn(allocator);
    return channel;
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Channel(io.netty.channel.Channel)

Aggregations

ByteBufAllocator (io.netty.buffer.ByteBufAllocator)75 ByteBuf (io.netty.buffer.ByteBuf)46 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)16 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)10 Test (org.junit.jupiter.api.Test)9 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)8 Channel (io.netty.channel.Channel)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)8 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 ChannelFuture (io.netty.channel.ChannelFuture)6 IOException (java.io.IOException)6 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)5 NettyDataBufferFactory (org.springframework.core.io.buffer.NettyDataBufferFactory)4 ChannelFutureListener (io.netty.channel.ChannelFutureListener)3 ChannelPipeline (io.netty.channel.ChannelPipeline)3 RecvByteBufAllocator (io.netty.channel.RecvByteBufAllocator)3 InetSocketAddress (java.net.InetSocketAddress)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3