Class DelegatingHttpServiceContext
- All Implemented Interfaces:
AsyncCloseable,ListenableAsyncCloseable,HttpConnectionContext,ConnectionContext,ConnectionInfo,ServerListenContext
HttpServiceContext that delegates all calls to a provided HttpServiceContext.
Any method can be overridden to change this default behavior.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.servicetalk.transport.api.ConnectionInfo
ConnectionInfo.Protocol -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptConnections(boolean accept) Toggles the server's ability to accept new connections.Used to close/shutdown a resource.Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync(), but attempts to cleanup state before abruptly closing.String representation of an identifier for this connection (can be globally non-unique).delegate()Returns the delegateHttpServiceContext.Get theExecutionContextfor thisConnectionInfo.TheSocketAddressto which the associated connection is bound.onClose()Returns aCompletablethat is notified once theListenableAsyncCloseablewas closed.Returns aCompletablethat is notified when closing begins.parent()Returns a reference to a parentConnectionContextif any.protocol()Get theConnectionInfo.Protocolfor thisConnectionInfo.TheSocketAddressto which the associated connection is connected.<T> TsocketOption(SocketOption<T> option) Get theSslConfigfor this connection.Get theSSLSessionfor this connection.toString()String representation of the current connection information.Methods inherited from class io.servicetalk.http.api.HttpServiceContext
blockingStreamingResponseFactory, headersFactory, responseFactory, streamingResponseFactory
-
Constructor Details
-
DelegatingHttpServiceContext
New instance.- Parameters:
other-HttpServiceContextto delegate all calls.
-
-
Method Details
-
delegate
Returns the delegateHttpServiceContext.- Returns:
- the delegate
HttpServiceContext.
-
toString
Description copied from interface:ConnectionInfoString representation of the current connection information.- Specified by:
toStringin interfaceConnectionInfo- Overrides:
toStringin classObject- Returns:
- String representation of the current connection information.
-
connectionId
Description copied from interface:ConnectionInfoString representation of an identifier for this connection (can be globally non-unique).Note: this identifier is a string representation of an ID assigned by underlying implementation of the connection. Whether it's globally unique or not depends on that implementation. It's not recommended to use this identifier as a map key for storing connection related data. It can be used for logging purposes to correlate events happening on this connection with other logs or events related to the same instance. If necessary, uniqueness can be ensured by using a combination of the current identifier with
ConnectionInfo.localAddress()andConnectionInfo.remoteAddress().- Returns:
- String representation of an identifier for this connection (can be globally non-unique).
-
localAddress
Description copied from interface:ConnectionInfoTheSocketAddressto which the associated connection is bound.- Returns:
- The
SocketAddressto which the associated connection is bound.
-
remoteAddress
Description copied from interface:ConnectionInfoTheSocketAddressto which the associated connection is connected.- Returns:
- The
SocketAddressto which the associated connection is connected.
-
sslConfig
Description copied from interface:ConnectionInfoGet theSslConfigfor this connection.- Returns:
- The
SslConfigif SSL/TLS is configured, ornullotherwise.
-
sslSession
Description copied from interface:ConnectionInfoGet theSSLSessionfor this connection.- Returns:
- The
SSLSessionif SSL/TLS is enabled, ornullotherwise.
-
executionContext
Description copied from interface:ConnectionInfoGet theExecutionContextfor thisConnectionInfo.The
ExecutionContext.ioExecutor()will represent the thread responsible for IO for thisConnectionInfo. Note that this maybe different that what was used to create this object because at this time a specificIoExecutorhas been selected.- Returns:
- the
ExecutionContextfor thisConnectionInfo.
-
socketOption
Description copied from interface:ConnectionInfo- Type Parameters:
T- the type of theSocketOptionvalue.- Parameters:
option-SocketOptionto get.- Returns:
- the
SocketOptionvalue of typeTfor thisConnectionInfoornullif thisSocketOptionis not supported by thisConnectionInfo. - See Also:
-
protocol
Description copied from interface:ConnectionInfoGet theConnectionInfo.Protocolfor thisConnectionInfo.- Returns:
- the
ConnectionInfo.Protocolfor thisConnectionInfo.
-
parent
Description copied from interface:ConnectionContextReturns a reference to a parentConnectionContextif any.This method is useful when multiple virtual streams are multiplexed over a single connection to get access to the actual
ConnectionContextthat represents network.- Returns:
- a reference to a parent
ConnectionContextif any. Otherwise, returnsnull.
-
onClose
Description copied from interface:ListenableAsyncCloseableReturns aCompletablethat is notified once theListenableAsyncCloseablewas closed.- Returns:
- the
Completablethat is notified on close.
-
onClosing
Description copied from interface:ListenableAsyncCloseableReturns aCompletablethat 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 aconnection: closeheader).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
Completablethat is notified when closing begins.
-
closeAsync
Description copied from interface:AsyncCloseableUsed to close/shutdown a resource.- Returns:
- A
Completablethat is notified once the close is complete.
-
closeAsyncGracefully
Description copied from interface:AsyncCloseableUsed to close/shutdown a resource, similar toAsyncCloseable.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 toAsyncCloseable.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
Completablethat is notified once the close is complete.
-
acceptConnections
public void acceptConnections(boolean accept) Description copied from interface:ServerListenContextToggles the server's ability to accept new connections.Passing a
falsevalue 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
backlogor OS wide settings:- Linux: SOMAXCONN
- MacOS/BSD: kern.ipc.somaxconn / kern.ipc.soacceptqueue
Depending on how long this stays in the
falsestate, 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.
-