Package reactor.netty.transport
Class ServerTransport<T extends ServerTransport<T,CONF>,CONF extends ServerTransportConfig<CONF>>
java.lang.Object
reactor.netty.transport.Transport<T,CONF>
reactor.netty.transport.ServerTransport<T,CONF>
- Type Parameters:
T- ServerTransport implementationCONF- Server Configuration implementation
- Direct Known Subclasses:
HttpServer,TcpServer
public abstract class ServerTransport<T extends ServerTransport<T,CONF>,CONF extends ServerTransportConfig<CONF>>
extends Transport<T,CONF>
- Since:
- 1.0.0
- Author:
- Stephane Maldini, Violeta Georgieva
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMono<? extends DisposableServer>bind()final DisposableServerbindNow()Starts the server in a blocking fashion, and waits for it to finish initializing or the startup timeout expires (the startup timeout is45seconds).final DisposableServerStart the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires.final voidbindUntilJavaShutdown(Duration timeout, @Nullable Consumer<DisposableServer> onStart) Start the server in a fully blocking fashion, not only waiting for it to initialize but also blocking during the full lifecycle of the server.<A> TchildAttr(AttributeKey<A> key, @Nullable A value) Injects default attribute to the future childChannelconnections.childObserve(ConnectionObserver observer) Set or add the givenConnectionObserverfor each remote connection.<A> TchildOption(ChannelOption<A> key, @Nullable A value) Injects default options to the future childChannelconnections.Set or add a callback called whenServerTransportis about to start listening for incoming traffic.doOnBound(Consumer<? super DisposableServer> doOnBound) Set or add a callback called afterDisposableServerhas been started.doOnConnection(Consumer<? super Connection> doOnConnection) Set or add a callback called on new remoteConnection.doOnUnbound(Consumer<? super DisposableServer> doOnUnbound) Set or add a callback called afterDisposableServerhas been shutdown.The host to which this server should bind.port(int port) The port to which this server should bind.warmup()Based on the actual configuration, returns aMonothat triggers: an initialization of the event loop groups loads the necessary native libraries for the transport By default, when method is not used, thebind operationabsorbs the extra time needed to load resources.Methods inherited from class reactor.netty.transport.Transport
attr, bindAddress, channelGroup, configuration, doOnChannelInit, duplicate, metrics, metrics, observe, option, runOn, runOn, runOn, wiretap, wiretap, wiretap, wiretap, wiretap
-
Constructor Details
-
ServerTransport
public ServerTransport()
-
-
Method Details
-
bind
Binds theServerTransportand returns aMonoofDisposableServer. IfMonois cancelled, the underlying binding will be aborted. Once theDisposableServerhas been emitted and is not necessary anymore, disposing the main server loop must be done by the user viaDisposableChannel.dispose().- Returns:
- a
MonoofDisposableServer
-
bindNow
Starts the server in a blocking fashion, and waits for it to finish initializing or the startup timeout expires (the startup timeout is45seconds). The returnedDisposableServeroffers simple server API, including toDisposableChannel.disposeNow()shut it down in a blocking fashion.- Returns:
- a
MonoofConnection
-
bindNow
Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires. The returnedDisposableServeroffers simple server API, including toDisposableChannel.disposeNow()shut it down in a blocking fashion.- Parameters:
timeout- max startup timeout (resolution: ns)- Returns:
- a
DisposableServer
-
bindUntilJavaShutdown
public final void bindUntilJavaShutdown(Duration timeout, @Nullable Consumer<DisposableServer> onStart) Start the server in a fully blocking fashion, not only waiting for it to initialize but also blocking during the full lifecycle of the server. Since most servers will be long-lived, this is more adapted to running a server out of a main method, only allowing shutdown of the servers throughsigkill.Note:
JVM shutdown hookis added by this method in order to properly disconnect the server upon receiving asigkillsignal.- Parameters:
timeout- a timeout for server shutdownonStart- an optional callback on server start
-
childAttr
Injects default attribute to the future childChannelconnections. It will be available viaAttributeMap.attr(AttributeKey). If thevalueisnull, the attribute of the specifiedkeyis removed.- Type Parameters:
A- the attribute type- Parameters:
key- the attribute keyvalue- the attribute value - null to remove a key- Returns:
- a new
ServerTransportreference - See Also:
-
childObserve
Set or add the givenConnectionObserverfor each remote connection.- Parameters:
observer- theConnectionObserveraddition- Returns:
- a new
ServerTransportreference
-
childOption
Injects default options to the future childChannelconnections. It will be available viaChannel.config(). If thevalueisnull, the attribute of the specifiedkeyis removed. Note: SettingChannelOption.AUTO_READoption will be ignored. It is configured to befalse.- Type Parameters:
A- the option type- Parameters:
key- the option keyvalue- the option value - null to remove a key- Returns:
- a new
ServerTransportreference - See Also:
-
doOnBind
Set or add a callback called whenServerTransportis about to start listening for incoming traffic.- Parameters:
doOnBind- a consumer observing connected events- Returns:
- a new
ServerTransportreference
-
doOnBound
Set or add a callback called afterDisposableServerhas been started.- Parameters:
doOnBound- a consumer observing connected events- Returns:
- a new
ServerTransportreference
-
doOnConnection
Set or add a callback called on new remoteConnection.- Parameters:
doOnConnection- a consumer observing remote connections- Returns:
- a new
ServerTransportreference
-
doOnUnbound
Set or add a callback called afterDisposableServerhas been shutdown.- Parameters:
doOnUnbound- a consumer observing unbound events- Returns:
- a new
ServerTransportreference
-
host
The host to which this server should bind.- Parameters:
host- the host to bind to.- Returns:
- a new
ServerTransportreference
-
port
The port to which this server should bind.- Parameters:
port- The port to bind to.- Returns:
- a new
ServerTransportreference
-
warmup
Based on the actual configuration, returns aMonothat triggers:- an initialization of the event loop groups
- loads the necessary native libraries for the transport
bind operationabsorbs the extra time needed to load resources.- Returns:
- a
Monorepresenting the completion of the warmup - Since:
- 1.0.3
-