Class NettyServerContext
- All Implemented Interfaces:
AsyncCloseable
,ListenableAsyncCloseable
,GracefulAutoCloseable
,ServerContext
,ServerListenContext
,AutoCloseable
ServerContext
implementation using a netty Channel
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptConnections
(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.ReturnsExecutionContext
used by this server.Listen address for the server associated with this context.onClose()
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.Returns aCompletable
that is notified when closing begins.static ServerContext
wrap
(io.netty.channel.Channel listenChannel, ListenableAsyncCloseable channelSetCloseable, AsyncCloseable closeBefore, ExecutionContext<?> executionContext) Wrap the passedNettyServerContext
.static ServerContext
wrap
(NettyServerContext toWrap, AsyncCloseable closeBefore) Wrap the passedNettyServerContext
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.servicetalk.transport.api.ServerContext
awaitShutdown, close, closeGracefully
-
Method Details
-
wrap
Wrap the passedNettyServerContext
.- Parameters:
toWrap
-NettyServerContext
to wrap.closeBefore
-Completable
which needs to be closed first beforetoWrap
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 passedNettyServerContext
.- Parameters:
listenChannel
-Channel
to wrap.channelSetCloseable
-ChannelSet
to wrap.closeBefore
-Completable
which needs to closed first beforelistenChannel
will be closed.executionContext
-ExecutionContext
used by this server.- Returns:
- A new
NettyServerContext
instance.
-
listenAddress
Description copied from interface:ServerContext
Listen address for the server associated with this context.- Specified by:
listenAddress
in interfaceServerContext
- 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:- Linux: SOMAXCONN
- MacOS/BSD: kern.ipc.somaxconn / kern.ipc.soacceptqueue
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 interfaceServerListenContext
- Parameters:
accept
- Toggles the server's accepting connection ability.
-
executionContext
Description copied from interface:ServerContext
ReturnsExecutionContext
used by this server.- Specified by:
executionContext
in interfaceServerContext
- Returns:
ExecutionContext
used by this server.
-
closeAsync
Description copied from interface:AsyncCloseable
Used to close/shutdown a resource.- Specified by:
closeAsync
in interfaceAsyncCloseable
- Returns:
- A
Completable
that is notified once the close is complete.
-
closeAsyncGracefully
Description copied from interface:AsyncCloseable
Used 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:
closeAsyncGracefully
in interfaceAsyncCloseable
- Returns:
- A
Completable
that is notified once the close is complete.
-
onClose
Description copied from interface:ListenableAsyncCloseable
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.- Specified by:
onClose
in interfaceListenableAsyncCloseable
- Returns:
- the
Completable
that is notified on close.
-
onClosing
Description copied from interface:ListenableAsyncCloseable
Returns aCompletable
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 aconnection: 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 interfaceListenableAsyncCloseable
- Returns:
- a
Completable
that is notified when closing begins.
-