Search in sources :

Example 1 with TcpServerBinder

use of io.servicetalk.tcp.netty.internal.TcpServerBinder in project servicetalk by apple.

the class DeferredServerChannelBinder method bind.

static Single<HttpServerContext> bind(final HttpExecutionContext executionContext, final ReadOnlyHttpServerConfig config, final SocketAddress listenAddress, @Nullable final InfluencerConnectionAcceptor connectionAcceptor, final StreamingHttpService service, final boolean drainRequestPayloadBody, final boolean sniOnly) {
    final ReadOnlyTcpServerConfig tcpConfig = config.tcpConfig();
    assert tcpConfig.sslContext() != null;
    final BiFunction<Channel, ConnectionObserver, Single<NettyConnectionContext>> channelInit = sniOnly ? (channel, connectionObserver) -> sniInitChannel(listenAddress, channel, config, executionContext, service, drainRequestPayloadBody, connectionObserver) : (channel, connectionObserver) -> alpnInitChannel(listenAddress, channel, config, executionContext, service, drainRequestPayloadBody, connectionObserver);
    // In case ALPN negotiates h2, h2 connection MUST enable auto read for its Channel.
    return TcpServerBinder.bind(listenAddress, tcpConfig, false, executionContext, connectionAcceptor, channelInit, serverConnection -> {
        // Start processing requests on http/1.1 connection:
        if (serverConnection instanceof NettyHttpServerConnection) {
            ((NettyHttpServerConnection) serverConnection).process(true);
        }
    // Nothing to do otherwise as h2 uses auto read on the parent channel
    }).map(delegate -> {
        LOGGER.debug("Started HTTP server with ALPN for address {}", delegate.listenAddress());
        // The ServerContext returned by TcpServerBinder takes care of closing the connectionAcceptor.
        return new NettyHttpServer.NettyHttpServerContext(delegate, service, executionContext);
    });
}
Also used : ConnectionObserver(io.servicetalk.transport.api.ConnectionObserver) NettyHttpServerConnection(io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerConnection) Logger(org.slf4j.Logger) SocketAddress(java.net.SocketAddress) HTTP_2(io.servicetalk.http.netty.AlpnIds.HTTP_2) Single(io.servicetalk.concurrent.api.Single) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) TcpServerChannelInitializer(io.servicetalk.tcp.netty.internal.TcpServerChannelInitializer) InfluencerConnectionAcceptor(io.servicetalk.transport.netty.internal.InfluencerConnectionAcceptor) TcpServerBinder(io.servicetalk.tcp.netty.internal.TcpServerBinder) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig) Channel(io.netty.channel.Channel) ConnectionObserver(io.servicetalk.transport.api.ConnectionObserver) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) HTTP_1_1(io.servicetalk.http.netty.AlpnIds.HTTP_1_1) HttpServerContext(io.servicetalk.http.api.HttpServerContext) NoopChannelInitializer(io.servicetalk.http.netty.AlpnChannelSingle.NoopChannelInitializer) Single.failed(io.servicetalk.concurrent.api.Single.failed) NettyConnectionContext(io.servicetalk.transport.netty.internal.NettyConnectionContext) Nullable(javax.annotation.Nullable) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) NettyHttpServerConnection(io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerConnection) Single(io.servicetalk.concurrent.api.Single) Channel(io.netty.channel.Channel) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig)

Aggregations

Channel (io.netty.channel.Channel)1 Single (io.servicetalk.concurrent.api.Single)1 Single.failed (io.servicetalk.concurrent.api.Single.failed)1 HttpExecutionContext (io.servicetalk.http.api.HttpExecutionContext)1 HttpServerContext (io.servicetalk.http.api.HttpServerContext)1 StreamingHttpService (io.servicetalk.http.api.StreamingHttpService)1 NoopChannelInitializer (io.servicetalk.http.netty.AlpnChannelSingle.NoopChannelInitializer)1 HTTP_1_1 (io.servicetalk.http.netty.AlpnIds.HTTP_1_1)1 HTTP_2 (io.servicetalk.http.netty.AlpnIds.HTTP_2)1 NettyHttpServerConnection (io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerConnection)1 ReadOnlyTcpServerConfig (io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig)1 TcpServerBinder (io.servicetalk.tcp.netty.internal.TcpServerBinder)1 TcpServerChannelInitializer (io.servicetalk.tcp.netty.internal.TcpServerChannelInitializer)1 ConnectionObserver (io.servicetalk.transport.api.ConnectionObserver)1 InfluencerConnectionAcceptor (io.servicetalk.transport.netty.internal.InfluencerConnectionAcceptor)1 NettyConnectionContext (io.servicetalk.transport.netty.internal.NettyConnectionContext)1 SocketAddress (java.net.SocketAddress)1 BiFunction (java.util.function.BiFunction)1 Nullable (javax.annotation.Nullable)1 Logger (org.slf4j.Logger)1