Class ServerTransport<T extends ServerTransport<T,CONF>,CONF extends ServerTransportConfig<CONF>>

java.lang.Object
reactor.netty.transport.Transport<T,CONF>
reactor.netty.transport.ServerTransport<T,CONF>
Type Parameters:
T - ServerTransport implementation
CONF - Server Configuration implementation
Direct Known Subclasses:
HttpServer, TcpServer

public abstract class ServerTransport<T extends ServerTransport<T,CONF>,CONF extends ServerTransportConfig<CONF>> extends Transport<T,CONF>
A generic server Transport that will bind() to a local address and provide a DisposableServer.
Since:
1.0.0
Author:
Stephane Maldini, Violeta Georgieva
  • Constructor Details

    • ServerTransport

      public ServerTransport()
  • Method Details

    • bind

      public Mono<? extends DisposableServer> bind()
      Binds the ServerTransport and returns a Mono of DisposableServer. If Mono is cancelled, the underlying binding will be aborted. Once the DisposableServer has been emitted and is not necessary anymore, disposing the main server loop must be done by the user via DisposableChannel.dispose().
      Returns:
      a Mono of DisposableServer
    • bindNow

      public final DisposableServer bindNow()
      Starts the server in a blocking fashion, and waits for it to finish initializing or the startup timeout expires (the startup timeout is 45 seconds). The returned DisposableServer offers simple server API, including to DisposableChannel.disposeNow() shut it down in a blocking fashion.
      Returns:
      a Mono of Connection
    • bindNow

      public final DisposableServer bindNow(Duration timeout)
      Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires. The returned DisposableServer offers simple server API, including to DisposableChannel.disposeNow() shut it down in a blocking fashion.
      Parameters:
      timeout - max startup timeout (resolution: ns)
      Returns:
      a DisposableServer
    • bindUntilJavaShutdown

      public final void bindUntilJavaShutdown(Duration timeout, @Nullable Consumer<DisposableServer> onStart)
      Start the server in a fully blocking fashion, not only waiting for it to initialize but also blocking during the full lifecycle of the server. Since most servers will be long-lived, this is more adapted to running a server out of a main method, only allowing shutdown of the servers through sigkill.

      Note: JVM shutdown hook is added by this method in order to properly disconnect the server upon receiving a sigkill signal.

      Parameters:
      timeout - a timeout for server shutdown
      onStart - an optional callback on server start
    • childAttr

      public <A> T childAttr(AttributeKey<A> key, @Nullable A value)
      Injects default attribute to the future child Channel connections. It will be available via AttributeMap.attr(AttributeKey). If the value is null, the attribute of the specified key is removed.
      Type Parameters:
      A - the attribute type
      Parameters:
      key - the attribute key
      value - the attribute value - null to remove a key
      Returns:
      a new ServerTransport reference
      See Also:
    • childObserve

      public T childObserve(ConnectionObserver observer)
      Set or add the given ConnectionObserver for each remote connection.
      Parameters:
      observer - the ConnectionObserver addition
      Returns:
      a new ServerTransport reference
    • childOption

      public <A> T childOption(ChannelOption<A> key, @Nullable A value)
      Injects default options to the future child Channel connections. It will be available via Channel.config(). If the value is null, the attribute of the specified key is removed. Note: Setting ChannelOption.AUTO_READ option will be ignored. It is configured to be false.
      Type Parameters:
      A - the option type
      Parameters:
      key - the option key
      value - the option value - null to remove a key
      Returns:
      a new ServerTransport reference
      See Also:
    • doOnBind

      public T doOnBind(Consumer<? super CONF> doOnBind)
      Set or add a callback called when ServerTransport is about to start listening for incoming traffic.
      Parameters:
      doOnBind - a consumer observing connected events
      Returns:
      a new ServerTransport reference
    • doOnBound

      public T doOnBound(Consumer<? super DisposableServer> doOnBound)
      Set or add a callback called after DisposableServer has been started.
      Parameters:
      doOnBound - a consumer observing connected events
      Returns:
      a new ServerTransport reference
    • doOnConnection

      public T doOnConnection(Consumer<? super Connection> doOnConnection)
      Set or add a callback called on new remote Connection.
      Parameters:
      doOnConnection - a consumer observing remote connections
      Returns:
      a new ServerTransport reference
    • doOnUnbound

      public T doOnUnbound(Consumer<? super DisposableServer> doOnUnbound)
      Set or add a callback called after DisposableServer has been shutdown.
      Parameters:
      doOnUnbound - a consumer observing unbound events
      Returns:
      a new ServerTransport reference
    • host

      public T host(String host)
      The host to which this server should bind.
      Parameters:
      host - the host to bind to.
      Returns:
      a new ServerTransport reference
    • port

      public T port(int port)
      The port to which this server should bind.
      Parameters:
      port - The port to bind to.
      Returns:
      a new ServerTransport reference
    • warmup

      public Mono<Void> warmup()
      Based on the actual configuration, returns a Mono that triggers:
      • an initialization of the event loop groups
      • loads the necessary native libraries for the transport
      By default, when method is not used, the bind operation absorbs the extra time needed to load resources.
      Returns:
      a Mono representing the completion of the warmup
      Since:
      1.0.3