Class NettyServerContext
- All Implemented Interfaces:
AsyncCloseable,ListenableAsyncCloseable,GracefulAutoCloseable,ServerContext,ServerListenContext,AutoCloseable
ServerContext implementation using a netty Channel.-
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.ReturnsExecutionContextused by this server.Listen address for the server associated with this context.onClose()Returns aCompletablethat is notified once theListenableAsyncCloseablewas closed.Returns aCompletablethat is notified when closing begins.static ServerContextwrap(io.netty.channel.Channel listenChannel, ListenableAsyncCloseable channelSetCloseable, AsyncCloseable closeBefore, ExecutionContext<?> executionContext) Wrap the passedNettyServerContext.static ServerContextwrap(NettyServerContext toWrap, AsyncCloseable closeBefore) Deprecated.This method is not used by ServiceTalk internals anymore and will be removed in the future releases.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.servicetalk.transport.api.ServerContext
awaitShutdown, close, closeGracefully
-
Method Details
-
wrap
Deprecated.This method is not used by ServiceTalk internals anymore and will be removed in the future releases. Replacement API iswrap(Channel, ListenableAsyncCloseable, AsyncCloseable, ExecutionContext).Wrap the passedNettyServerContext.- Parameters:
toWrap-NettyServerContextto wrap.closeBefore-Completablewhich needs to be closed first beforetoWrapwill be closed.- Returns:
- A new
NettyServerContextinstance.
-
wrap
public static ServerContext wrap(io.netty.channel.Channel listenChannel, ListenableAsyncCloseable channelSetCloseable, @Nullable AsyncCloseable closeBefore, ExecutionContext<?> executionContext) Wrap the passedNettyServerContext.- Parameters:
listenChannel-Channelto wrap.channelSetCloseable-ChannelSetto wrap.closeBefore-Completablewhich needs to closed first beforelistenChannelwill be closed.executionContext-ExecutionContextused by this server.- Returns:
- A new
NettyServerContextinstance.
-
listenAddress
Description copied from interface:ServerContextListen address for the server associated with this context.- Specified by:
listenAddressin interfaceServerContext- Returns:
- Address which the associated server is listening at.
-
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.
- Specified by:
acceptConnectionsin interfaceServerListenContext- Parameters:
accept- Toggles the server's accepting connection ability.
-
executionContext
Description copied from interface:ServerContextReturnsExecutionContextused by this server.- Specified by:
executionContextin interfaceServerContext- Returns:
ExecutionContextused by this server.
-
closeAsync
Description copied from interface:AsyncCloseableUsed to close/shutdown a resource.- Specified by:
closeAsyncin interfaceAsyncCloseable- 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().- Specified by:
closeAsyncGracefullyin interfaceAsyncCloseable- Returns:
- A
Completablethat is notified once the close is complete.
-
onClose
Description copied from interface:ListenableAsyncCloseableReturns aCompletablethat is notified once theListenableAsyncCloseablewas closed.- Specified by:
onClosein interfaceListenableAsyncCloseable- 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.- Specified by:
onClosingin interfaceListenableAsyncCloseable- Returns:
- a
Completablethat is notified when closing begins.
-