Class NettyServerContext

java.lang.Object
io.servicetalk.transport.netty.internal.NettyServerContext
All Implemented Interfaces:
AsyncCloseable, ListenableAsyncCloseable, GracefulAutoCloseable, ServerContext, ServerListenContext, AutoCloseable

public final class NettyServerContext extends Object implements ServerContext
ServerContext implementation using a netty Channel.
  • Method Details

    • wrap

      public static ServerContext wrap(NettyServerContext toWrap, AsyncCloseable closeBefore)
      Wrap the passed NettyServerContext.
      Parameters:
      toWrap - NettyServerContext to wrap.
      closeBefore - Completable which needs to be closed first before toWrap will be closed.
      Returns:
      A new NettyServerContext instance.
    • wrap

      public static ServerContext wrap(io.netty.channel.Channel listenChannel, ListenableAsyncCloseable channelSetCloseable, @Nullable AsyncCloseable closeBefore, ExecutionContext<?> executionContext)
      Wrap the passed NettyServerContext.
      Parameters:
      listenChannel - Channel to wrap.
      channelSetCloseable - ChannelSet to wrap.
      closeBefore - Completable which needs to closed first before listenChannel will be closed.
      executionContext - ExecutionContext used by this server.
      Returns:
      A new NettyServerContext instance.
    • listenAddress

      public SocketAddress listenAddress()
      Description copied from interface: ServerContext
      Listen address for the server associated with this context.
      Specified by:
      listenAddress in interface ServerContext
      Returns:
      Address which the associated server is listening at.
    • acceptConnections

      public void acceptConnections(boolean accept)
      Description copied from interface: ServerListenContext
      Toggles the server's ability to accept new connections.

      Passing a false value will signal the server to stop accepting new connections. It won't affect any other interactions to currently open connections (i.e., reads / writes).

      Depending on the transport, connections may still get ESTABLISHED, see backlog or OS wide settings:

      For instance, in case of TCP the 3-way handshake may finish, and the connection will await in the accept queue to be accepted. If the accept queue is full, connection SYNs will await in the SYN backlog (in the case of linux). This can be tuned: tcp_max_syn_backlog These additional parameters may affect the behavior of new flows when the service is not accepting.

      Depending on how long this stays in the false state, it may affect other timeouts (i.e., connect-timeout or idleness) on the peer-side and/or the other flows to the peer (i.e., proxies).

      Considerations:

      • Upon resumption, accept == true, backlogged connections will be processed first, which may be inactive by that time.
      • The effect of toggling connection acceptance may be lazy evaluated (implementation detail), meaning that connections may still go through even after setting this to false.
      Specified by:
      acceptConnections in interface ServerListenContext
      Parameters:
      accept - Toggles the server's accepting connection ability.
    • executionContext

      public ExecutionContext<?> executionContext()
      Description copied from interface: ServerContext
      Returns ExecutionContext used by this server.
      Specified by:
      executionContext in interface ServerContext
      Returns:
      ExecutionContext used by this server.
    • closeAsync

      public Completable closeAsync()
      Description copied from interface: AsyncCloseable
      Used to close/shutdown a resource.
      Specified by:
      closeAsync in interface AsyncCloseable
      Returns:
      A Completable that is notified once the close is complete.
    • closeAsyncGracefully

      public Completable closeAsyncGracefully()
      Description copied from interface: AsyncCloseable
      Used to close/shutdown a resource, similar to AsyncCloseable.closeAsync(), but attempts to cleanup state before abruptly closing. This provides a hint that implementations can use to stop accepting new work and finish in flight work. This method is implemented on a "best effort" basis and may be equivalent to AsyncCloseable.closeAsync().

      Note: Implementations may or may not apply a timeout for this operation to complete, if a caller does not want to wait indefinitely, and are unsure if the implementation applies a timeout, it is advisable to apply a timeout and force a call to AsyncCloseable.closeAsync().

      Specified by:
      closeAsyncGracefully in interface AsyncCloseable
      Returns:
      A Completable that is notified once the close is complete.
    • onClose

      public Completable onClose()
      Description copied from interface: ListenableAsyncCloseable
      Returns a Completable that is notified once the ListenableAsyncCloseable was closed.
      Specified by:
      onClose in interface ListenableAsyncCloseable
      Returns:
      the Completable that is notified on close.
    • onClosing

      public Completable onClosing()
      Description copied from interface: ListenableAsyncCloseable
      Returns a Completable that is notified when closing begins.

      Closing begin might be when a close operation is initiated locally (e.g. subscribing to AsyncCloseable.closeAsync()) or it could also be a transport event received from a remote peer (e.g. read a connection: close header).

      For backwards compatibility this method maybe functionally equivalent to ListenableAsyncCloseable.onClose(). Therefore, provides a best-effort leading edge notification of closing, but may fall back to notification on trailing edge.

      The goal of this method is often to notify asap when closing so this method may not be offloaded and care must be taken to avoid blocking if subscribing to the return Completable.

      Specified by:
      onClosing in interface ListenableAsyncCloseable
      Returns:
      a Completable that is notified when closing begins.