Search in sources :

Example 76 with ByteBufAllocator

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

the class BoltServer method init.

@Override
public void init() {
    Log log = logService.getInternalLog(BoltServer.class);
    boltMemoryPool = new BoltMemoryPool(memoryPools, NETTY_BUF_ALLOCATOR.metric());
    life.add(new BoltMemoryPoolLifeCycleAdapter(boltMemoryPool));
    InternalLoggerFactory.setDefaultFactory(new Netty4LoggerFactory(logService.getInternalLogProvider()));
    TransportThrottleGroup throttleGroup = new TransportThrottleGroup(config, clock);
    BoltSchedulerProvider boltSchedulerProvider = life.setLast(new ExecutorBoltSchedulerProvider(config, new CachedThreadPoolExecutorFactory(), jobScheduler, logService));
    BoltConnectionFactory boltConnectionFactory = createConnectionFactory(config, boltSchedulerProvider, logService, clock);
    BoltStateMachineFactory externalBoltStateMachineFactory = createBoltStateMachineFactory(createAuthentication(externalAuthManager), clock);
    BoltStateMachineFactory internalBoltStateMachineFactory = createBoltStateMachineFactory(createAuthentication(internalAuthManager), clock);
    BoltStateMachineFactory loopbackBoltStateMachineFactory = createBoltStateMachineFactory(createAuthentication(loopbackAuthManager), clock);
    BoltProtocolFactory externalBoltProtocolFactory = createBoltProtocolFactory(boltConnectionFactory, externalBoltStateMachineFactory, throttleGroup, clock, config.get(BoltConnectorInternalSettings.connection_keep_alive));
    BoltProtocolFactory internalBoltProtocolFactory = createBoltProtocolFactory(boltConnectionFactory, internalBoltStateMachineFactory, throttleGroup, clock, config.get(BoltConnectorInternalSettings.connection_keep_alive));
    BoltProtocolFactory loopbackBoltProtocolFactory = createBoltProtocolFactory(boltConnectionFactory, loopbackBoltStateMachineFactory, throttleGroup, clock, config.get(BoltConnectorInternalSettings.connection_keep_alive));
    if (config.get(CommonConnectorConfig.ocsp_stapling_enabled)) {
        enableOcspStapling();
    }
    ByteBufAllocator bufferAllocator = getBufferAllocator();
    if (config.get(BoltConnector.enabled)) {
        jobScheduler.setThreadFactory(Group.BOLT_NETWORK_IO, NettyThreadFactory::new);
        NettyServer nettyServer;
        var isNotReadReplica = config.get(GraphDatabaseSettings.mode) != GraphDatabaseSettings.Mode.READ_REPLICA;
        var loopbackProtocolInitializer = createLoopbackProtocolInitializer(loopbackBoltProtocolFactory, throttleGroup, bufferAllocator);
        if (config.get(GraphDatabaseSettings.routing_enabled) && isNotReadReplica) {
            nettyServer = new NettyServer(jobScheduler.threadFactory(Group.BOLT_NETWORK_IO), createExternalProtocolInitializer(externalBoltProtocolFactory, throttleGroup, log, bufferAllocator), createInternalProtocolInitializer(internalBoltProtocolFactory, throttleGroup, bufferAllocator), loopbackProtocolInitializer, connectorPortRegister, logService, config);
        } else {
            nettyServer = new NettyServer(jobScheduler.threadFactory(Group.BOLT_NETWORK_IO), createExternalProtocolInitializer(externalBoltProtocolFactory, throttleGroup, log, bufferAllocator), loopbackProtocolInitializer, connectorPortRegister, logService, config);
        }
        life.add(nettyServer);
        log.info("Bolt server loaded");
    }
    life.init();
}
Also used : BoltMemoryPool(org.neo4j.bolt.transport.BoltMemoryPool) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) DefaultBoltConnectionFactory(org.neo4j.bolt.runtime.DefaultBoltConnectionFactory) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) Log(org.neo4j.logging.Log) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) ExecutorBoltSchedulerProvider(org.neo4j.bolt.runtime.scheduling.ExecutorBoltSchedulerProvider) NettyThreadFactory(org.neo4j.bolt.runtime.scheduling.NettyThreadFactory) BoltProtocolFactory(org.neo4j.bolt.transport.BoltProtocolFactory) DefaultBoltProtocolFactory(org.neo4j.bolt.transport.DefaultBoltProtocolFactory) NettyServer(org.neo4j.bolt.transport.NettyServer) CachedThreadPoolExecutorFactory(org.neo4j.bolt.runtime.scheduling.CachedThreadPoolExecutorFactory) ExecutorBoltSchedulerProvider(org.neo4j.bolt.runtime.scheduling.ExecutorBoltSchedulerProvider) BoltSchedulerProvider(org.neo4j.bolt.runtime.scheduling.BoltSchedulerProvider) Netty4LoggerFactory(org.neo4j.bolt.transport.Netty4LoggerFactory) TransportThrottleGroup(org.neo4j.bolt.transport.TransportThrottleGroup)

Example 77 with ByteBufAllocator

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

the class WebsocketFinalizer method receive.

@Override
public ByteBufFlux receive() {
    ByteBufAllocator alloc = (ByteBufAllocator) configuration().options().get(ChannelOption.ALLOCATOR);
    if (alloc == null) {
        alloc = ByteBufAllocator.DEFAULT;
    }
    @SuppressWarnings("unchecked") Mono<ChannelOperations<?, ?>> connector = (Mono<ChannelOperations<?, ?>>) connect();
    return ByteBufFlux.fromInbound(connector.flatMapMany(contentReceiver), alloc);
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Mono(reactor.core.publisher.Mono) ChannelOperations(reactor.netty.channel.ChannelOperations)

Example 78 with ByteBufAllocator

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

the class HttpClientFinalizer method responseContent.

@Override
public ByteBufFlux responseContent() {
    ByteBufAllocator alloc = (ByteBufAllocator) configuration().options().get(ChannelOption.ALLOCATOR);
    if (alloc == null) {
        alloc = ByteBufAllocator.DEFAULT;
    }
    @SuppressWarnings("unchecked") Mono<ChannelOperations<?, ?>> connector = (Mono<ChannelOperations<?, ?>>) connect();
    return ByteBufFlux.fromInbound(connector.flatMapMany(contentReceiver), alloc);
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Mono(reactor.core.publisher.Mono) ByteBufMono(reactor.netty.ByteBufMono) ChannelOperations(reactor.netty.channel.ChannelOperations)

Example 79 with ByteBufAllocator

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

the class HttpClientTest method testIssue694.

@Test
void testIssue694() {
    disposableServer = createServer().handle((req, res) -> {
        req.receive().subscribe();
        return Mono.empty();
    }).bindNow();
    HttpClient client = createHttpClientForContextWithPort();
    ByteBufAllocator alloc = ByteBufAllocator.DEFAULT;
    ByteBuf buffer1 = alloc.buffer().writeInt(1).retain(9);
    client.request(HttpMethod.GET).send((req, out) -> out.send(Flux.range(0, 10).map(i -> buffer1))).response().block(Duration.ofSeconds(30));
    assertThat(buffer1.refCnt()).isEqualTo(0);
    ByteBuf buffer2 = alloc.buffer().writeInt(1).retain(9);
    client.request(HttpMethod.GET).send(Flux.range(0, 10).map(i -> buffer2)).response().block(Duration.ofSeconds(30));
    assertThat(buffer2.refCnt()).isEqualTo(0);
}
Also used : Arrays(java.util.Arrays) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) StepVerifier(reactor.test.StepVerifier) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Tuples(reactor.util.function.Tuples) Disabled(org.junit.jupiter.api.Disabled) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpResources(reactor.netty.http.HttpResources) TcpClient(reactor.netty.tcp.TcpClient) Future(java.util.concurrent.Future) Loggers(reactor.util.Loggers) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) CharsetUtil(io.netty.util.CharsetUtil) Path(java.nio.file.Path) LoopResources(reactor.netty.resources.LoopResources) HttpObjectDecoder(io.netty.handler.codec.http.HttpObjectDecoder) Context(reactor.util.context.Context) Set(java.util.Set) ConnectionPoolMetrics(reactor.netty.resources.ConnectionPoolMetrics) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) SSLException(javax.net.ssl.SSLException) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) HttpServer(reactor.netty.http.server.HttpServer) LogLevel(io.netty.handler.logging.LogLevel) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SocketUtils(reactor.netty.SocketUtils) HttpProtocol(reactor.netty.http.HttpProtocol) Nullable(reactor.util.annotation.Nullable) ArrayList(java.util.ArrayList) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) SslProvider(reactor.netty.tcp.SslProvider) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) SslContext(io.netty.handler.ssl.SslContext) Files(java.nio.file.Files) Publisher(org.reactivestreams.Publisher) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) Field(java.lang.reflect.Field) Channel(io.netty.channel.Channel) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) Flux(reactor.core.publisher.Flux) FutureMono(reactor.netty.FutureMono) Paths(java.nio.file.Paths) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) ConnectionProvider(reactor.netty.resources.ConnectionProvider) DnsAddressResolverGroup(io.netty.resolver.dns.DnsAddressResolverGroup) Sinks(reactor.core.publisher.Sinks) SocketAddress(java.net.SocketAddress) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) URISyntaxException(java.net.URISyntaxException) BiFunction(java.util.function.BiFunction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelId(io.netty.channel.ChannelId) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) TimeoutException(java.util.concurrent.TimeoutException) BaseHttpTest(reactor.netty.BaseHttpTest) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) TransportConfig(reactor.netty.transport.TransportConfig) SocketChannel(java.nio.channels.SocketChannel) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteBufFlux(reactor.netty.ByteBufFlux) NettyPipeline(reactor.netty.NettyPipeline) Logger(reactor.util.Logger) ByteBufMono(reactor.netty.ByteBufMono) URI(java.net.URI) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelGroup(io.netty.channel.group.ChannelGroup) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) InetSocketAddress(java.net.InetSocketAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpVersion(io.netty.handler.codec.http.HttpVersion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tuple2(reactor.util.function.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Queues(reactor.util.concurrent.Queues) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Connection(reactor.netty.Connection) ExecutorService(java.util.concurrent.ExecutorService) HttpHeaderValues(io.netty.handler.codec.http.HttpHeaderValues) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpMethod(io.netty.handler.codec.http.HttpMethod) CertificateException(java.security.cert.CertificateException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) TcpServer(reactor.netty.tcp.TcpServer) ChannelHandler(io.netty.channel.ChannelHandler) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) ByteBuf(io.netty.buffer.ByteBuf) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBufAllocator (io.netty.buffer.ByteBufAllocator)79 ByteBuf (io.netty.buffer.ByteBuf)48 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 Test (org.junit.jupiter.api.Test)11 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)10 Channel (io.netty.channel.Channel)9 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)8 IOException (java.io.IOException)8 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 ChannelFuture (io.netty.channel.ChannelFuture)6 Mono (reactor.core.publisher.Mono)6 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)4 InetSocketAddress (java.net.InetSocketAddress)4 StandardCharsets (java.nio.charset.StandardCharsets)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 NettyDataBufferFactory (org.springframework.core.io.buffer.NettyDataBufferFactory)4 RecvByteBufAllocator (io.netty.channel.RecvByteBufAllocator)3 ByteBuffer (java.nio.ByteBuffer)3