Class DelegatingHttpServiceContext

java.lang.Object
io.servicetalk.http.api.HttpServiceContext
io.servicetalk.http.api.DelegatingHttpServiceContext
All Implemented Interfaces:
AsyncCloseable, ListenableAsyncCloseable, HttpConnectionContext, ConnectionContext, ConnectionInfo, ServerListenContext

public class DelegatingHttpServiceContext extends HttpServiceContext
An implementation of HttpServiceContext that delegates all calls to a provided HttpServiceContext. Any method can be overridden to change this default behavior.
  • Constructor Details

  • Method Details

    • delegate

      public HttpServiceContext delegate()
      Returns the delegate HttpServiceContext.
      Returns:
      the delegate HttpServiceContext.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • localAddress

      public SocketAddress localAddress()
      Description copied from interface: ConnectionInfo
      The SocketAddress to which the associated connection is bound.
      Returns:
      The SocketAddress to which the associated connection is bound.
    • remoteAddress

      public SocketAddress remoteAddress()
      Description copied from interface: ConnectionInfo
      The SocketAddress to which the associated connection is connected.
      Returns:
      The SocketAddress to which the associated connection is connected.
    • sslConfig

      @Nullable public SslConfig sslConfig()
      Description copied from interface: ConnectionInfo
      Get the SslConfig for this connection.
      Returns:
      The SslConfig if SSL/TLS is configured, or null otherwise.
    • sslSession

      @Nullable public SSLSession sslSession()
      Description copied from interface: ConnectionInfo
      Get the SSLSession for this connection.
      Returns:
      The SSLSession if SSL/TLS is enabled, or null otherwise.
    • executionContext

      public HttpExecutionContext executionContext()
      Description copied from interface: ConnectionInfo
      Get the ExecutionContext for this ConnectionInfo.

      The ExecutionContext.ioExecutor() will represent the thread responsible for IO for this ConnectionInfo. Note that this maybe different that what was used to create this object because at this time a specific IoExecutor has been selected.

      Returns:
      the ExecutionContext for this ConnectionInfo.
    • socketOption

      @Nullable public <T> T socketOption(SocketOption<T> option)
      Description copied from interface: ConnectionInfo
      Get the SocketOption value of type T for this ConnectionInfo.
      Type Parameters:
      T - the type of the SocketOption value.
      Parameters:
      option - SocketOption to get.
      Returns:
      the SocketOption value of type T for this ConnectionInfo or null if this SocketOption is not supported by this ConnectionInfo.
      See Also:
    • protocol

      public HttpProtocolVersion protocol()
      Description copied from interface: ConnectionInfo
      Returns:
      the ConnectionInfo.Protocol for this ConnectionInfo.
    • parent

      @Nullable public ConnectionContext parent()
      Description copied from interface: ConnectionContext
      Returns a reference to a parent ConnectionContext if any.

      This method is useful when multiple virtual streams are multiplexed over a single connection to get access to the actual ConnectionContext that represents network.

      Returns:
      a reference to a parent ConnectionContext if any. Otherwise, returns null.
    • onClose

      public Completable onClose()
      Description copied from interface: ListenableAsyncCloseable
      Returns a Completable that is notified once the ListenableAsyncCloseable was closed.
      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.

      Returns:
      a Completable that is notified when closing begins.
    • closeAsync

      public Completable closeAsync()
      Description copied from interface: AsyncCloseable
      Used to close/shutdown a resource.
      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().

      Returns:
      A Completable that is notified once the close is complete.
    • 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.
      Parameters:
      accept - Toggles the server's accepting connection ability.