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 DisposableServer
bindNow()
Starts the server in a blocking fashion, and waits for it to finish initializing or the startup timeout expires (the startup timeout is45
seconds).final DisposableServer
Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires.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.<A> T
childAttr
(AttributeKey<A> key, @Nullable A value) Injects default attribute to the future childChannel
connections.childObserve
(ConnectionObserver observer) Set or add the givenConnectionObserver
for each remote connection.<A> T
childOption
(ChannelOption<A> key, @Nullable A value) Injects default options to the future childChannel
connections.Set or add a callback called whenServerTransport
is about to start listening for incoming traffic.doOnBound
(Consumer<? super DisposableServer> doOnBound) Set or add a callback called afterDisposableServer
has 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 afterDisposableServer
has 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 aMono
that triggers: an initialization of the event loop groups loads the necessary native libraries for the transport By default, when method is not used, thebind operation
absorbs 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 theServerTransport
and returns aMono
ofDisposableServer
. IfMono
is cancelled, the underlying binding will be aborted. Once theDisposableServer
has been emitted and is not necessary anymore, disposing the main server loop must be done by the user viaDisposableChannel.dispose()
.- Returns:
- a
Mono
ofDisposableServer
-
bindNow
Starts the server in a blocking fashion, and waits for it to finish initializing or the startup timeout expires (the startup timeout is45
seconds). The returnedDisposableServer
offers simple server API, including toDisposableChannel.disposeNow()
shut it down in a blocking fashion.- Returns:
- a
Mono
ofConnection
-
bindNow
Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires. The returnedDisposableServer
offers 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 hook
is added by this method in order to properly disconnect the server upon receiving asigkill
signal.- Parameters:
timeout
- a timeout for server shutdownonStart
- an optional callback on server start
-
childAttr
Injects default attribute to the future childChannel
connections. It will be available viaAttributeMap.attr(AttributeKey)
. If thevalue
isnull
, the attribute of the specifiedkey
is removed.- Type Parameters:
A
- the attribute type- Parameters:
key
- the attribute keyvalue
- the attribute value - null to remove a key- Returns:
- a new
ServerTransport
reference - See Also:
-
childObserve
Set or add the givenConnectionObserver
for each remote connection.- Parameters:
observer
- theConnectionObserver
addition- Returns:
- a new
ServerTransport
reference
-
childOption
Injects default options to the future childChannel
connections. It will be available viaChannel.config()
. If thevalue
isnull
, the attribute of the specifiedkey
is removed. Note: SettingChannelOption.AUTO_READ
option 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
ServerTransport
reference - See Also:
-
doOnBind
Set or add a callback called whenServerTransport
is about to start listening for incoming traffic.- Parameters:
doOnBind
- a consumer observing connected events- Returns:
- a new
ServerTransport
reference
-
doOnBound
Set or add a callback called afterDisposableServer
has been started.- Parameters:
doOnBound
- a consumer observing connected events- Returns:
- a new
ServerTransport
reference
-
doOnConnection
Set or add a callback called on new remoteConnection
.- Parameters:
doOnConnection
- a consumer observing remote connections- Returns:
- a new
ServerTransport
reference
-
doOnUnbound
Set or add a callback called afterDisposableServer
has been shutdown.- Parameters:
doOnUnbound
- a consumer observing unbound events- Returns:
- a new
ServerTransport
reference
-
host
The host to which this server should bind.- Parameters:
host
- the host to bind to.- Returns:
- a new
ServerTransport
reference
-
port
The port to which this server should bind.- Parameters:
port
- The port to bind to.- Returns:
- a new
ServerTransport
reference
-
warmup
Based on the actual configuration, returns aMono
that triggers:- an initialization of the event loop groups
- loads the necessary native libraries for the transport
bind operation
absorbs the extra time needed to load resources.- Returns:
- a
Mono
representing the completion of the warmup - Since:
- 1.0.3
-