Package reactor.netty.udp
Class UdpServer
A UdpServer allows building in a safe immutable way a UDP server that is materialized
and connecting when
bind() is ultimately called.
Example:
UdpServer.create()
.doOnBind(startMetrics)
.doOnBound(startedMetrics)
.doOnUnbind(stopMetrics)
.host("127.0.0.1")
.port(1234)
.bind()
.block()
- Author:
- Stephane Maldini, Violeta Georgieva
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <A> UdpServerattr(AttributeKey<A> key, @Nullable A value) Update the given attribute key or remove it if the value is null.abstract Mono<? extends Connection>bind()final UdpServerbindAddress(Supplier<? extends SocketAddress> bindAddressSupplier) Set a new local address to which this transport should bind on subscribe.final ConnectionbindNow()Starts the server in a blocking fashion, and waits for it to finish initializing or the startup timeout expires (the startup timeout is45seconds).final ConnectionStart the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires.static UdpServercreate()Prepare aUdpServer.final UdpServerdoOnBind(Consumer<? super UdpServerConfig> doOnBind) Set or add a callback called whenUdpServeris about to start listening for incoming traffic.final UdpServerdoOnBound(Consumer<? super Connection> doOnBound) Set or add a callback called afterUdpServerhas been started.final UdpServerdoOnUnbound(Consumer<? super Connection> doOnUnbound) Set or add a callback called afterUdpServerhas been shutdown.final UdpServerhandle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) Attach an IO handler to react on connected client.final UdpServerThe host to which this server should bind.final UdpServermetrics(boolean enable) Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry.final UdpServermetrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Specifies whether the metrics are enabled on theTransport.final UdpServerobserve(ConnectionObserver observer) Set or add the givenConnectionObserverto observe the connection state changes.final <O> UdpServeroption(ChannelOption<O> key, @Nullable O value) Update the given option key or remove it if the value is null.final UdpServerport(int port) The port to which this server should bind.final UdpServerrunOn(EventLoopGroup eventLoopGroup) Run IO loops on the givenEventLoopGroup.final UdpServerrunOn(LoopResources channelResources) Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.final UdpServerrunOn(LoopResources loopResources, boolean preferNative) Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.final UdpServerrunOn(LoopResources loopResources, InternetProtocolFamily family) Deprecated.as of 1.3.0.final UdpServerrunOn(LoopResources loopResources, SocketProtocolFamily family) Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.warmup()Based on the actual configuration, returns aMonothat triggers: an initialization of the event loop group loads the necessary native libraries for the transport By default, when method is not used, thebind operationabsorbs the extra time needed to load resources.final UdpServerwiretap(boolean enable) Apply or remove a wire logger configuration usingTransportcategory (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.final UdpServerApply a wire logger configuration using the specified category (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.final UdpServerApply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.Methods inherited from class reactor.netty.transport.Transport
channelGroup, configuration, doOnChannelInit, duplicate, wiretap, wiretap
-
Constructor Details
-
UdpServer
public UdpServer()
-
-
Method Details
-
create
Prepare aUdpServer.- Returns:
- a
UdpServer
-
attr
Description copied from class:TransportUpdate the given attribute key or remove it if the value is null.- Overrides:
attrin classTransport<UdpServer,UdpServerConfig> - Type Parameters:
A- the attribute type- Parameters:
key- theAttributeKeykeyvalue- theAttributeKeyvalue- Returns:
- a new
Transportreference
-
bind
Binds theUdpServerand returns aMonoofConnection. IfMonois cancelled, the underlying binding will be aborted. Once theConnectionhas been emitted and is not necessary anymore, disposing the main server loop must be done by the user viaDisposableChannel.dispose().- Returns:
- a
MonoofConnection
-
bindAddress
Description copied from class:TransportSet a new local address to which this transport should bind on subscribe.- Overrides:
bindAddressin classTransport<UdpServer,UdpServerConfig> - Parameters:
bindAddressSupplier- A supplier of the address to bind to.- Returns:
- a new
Transport
-
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 returnedConnectionoffers simple server API, including toDisposableChannel.disposeNow()shut it down in a blocking fashion.- Returns:
- a
Connection
-
bindNow
Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires. The returnedConnectionoffers simple server API, including toDisposableChannel.disposeNow()shut it down in a blocking fashion.- Parameters:
timeout- max startup timeout (resolution: ns)- Returns:
- a
Connection
-
doOnBind
Set or add a callback called whenUdpServeris about to start listening for incoming traffic.- Parameters:
doOnBind- a consumer observing connected events- Returns:
- a new
UdpServerreference
-
doOnBound
Set or add a callback called afterUdpServerhas been started.- Parameters:
doOnBound- a consumer observing connected events- Returns:
- a new
UdpServerreference
-
doOnUnbound
Set or add a callback called afterUdpServerhas been shutdown.- Parameters:
doOnUnbound- a consumer observing unbound events- Returns:
- a new
UdpServerreference
-
handle
public final UdpServer handle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) Attach an IO handler to react on connected client. -
host
The host to which this server should bind.- Parameters:
host- the host to bind to.- Returns:
- a new
UdpServerreference
-
metrics
Description copied from class:TransportWhether to enable metrics to be collected and registered in Micrometer'sglobalRegistry. Applications can separately register their ownfilters. For example, to put an upper bound on the number of tags produced:MeterFilter filter = ... ; Metrics.globalRegistry.config().meterFilter(MeterFilter.maximumAllowableTags(prefix, 100, filter));
By default this is not enabled.
- Overrides:
metricsin classTransport<UdpServer,UdpServerConfig> - Parameters:
enable- true enables metrics collection; false disables it- Returns:
- a new
Transportreference
-
metrics
Description copied from class:TransportSpecifies whether the metrics are enabled on theTransport. All generated metrics are provided to the specified recorder which is only instantiated if metrics are being enabled (the instantiation is not lazy, but happens immediately, while configuring theTransport).- Overrides:
metricsin classTransport<UdpServer,UdpServerConfig> - Parameters:
enable- if true enables the metrics on theTransport.recorder- a supplier for theChannelMetricsRecorder- Returns:
- a new
Transportreference
-
observe
Description copied from class:TransportSet or add the givenConnectionObserverto observe the connection state changes.- Overrides:
observein classTransport<UdpServer,UdpServerConfig> - Parameters:
observer- theConnectionObserverto be set or add- Returns:
- a new
Transportreference
-
option
Description copied from class:TransportUpdate the given option key or remove it if the value is null. Note: SettingChannelOption.AUTO_READoption will be ignored. It is configured to befalse.- Overrides:
optionin classTransport<UdpServer,UdpServerConfig> - Type Parameters:
O- the option type- Parameters:
key- theChannelOptionkeyvalue- theChannelOptionvalue or null- Returns:
- a new
Transportreference
-
port
The port to which this server should bind. If a port is not specified, the default port12012is used.Note: The port can be specified also with
PORTenvironment variable.- Parameters:
port- The port to bind to.- Returns:
- a new
UdpServerreference
-
runOn
Description copied from class:TransportRun IO loops on the givenEventLoopGroup.- Overrides:
runOnin classTransport<UdpServer,UdpServerConfig> - Parameters:
eventLoopGroup- an eventLoopGroup to share- Returns:
- a new
Transportreference
-
runOn
Description copied from class:TransportRun IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer. Will prefer native (epoll/io_uring/kqueue) implementation if available unless the environment propertyreactor.netty.nativeis set tofalse.- Overrides:
runOnin classTransport<UdpServer,UdpServerConfig> - Parameters:
channelResources- aLoopResourcesaccepting native runtime expectation and returning an eventLoopGroup- Returns:
- a new
Transportreference
-
runOn
Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.- Overrides:
runOnin classTransport<UdpServer,UdpServerConfig> - Parameters:
loopResources- a new loop resourcespreferNative- should prefer running on epoll, io_uring, kqueue or similar instead of java NIO- Returns:
- a new
UdpServerreference
-
runOn
@Deprecated public final UdpServer runOn(LoopResources loopResources, InternetProtocolFamily family) Deprecated.as of 1.3.0. PreferrunOn(LoopResources, SocketProtocolFamily). This method will be removed in version 1.4.0.Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.- Parameters:
loopResources- a new loop resourcesfamily- a specificInternetProtocolFamilyto run with- Returns:
- a new
UdpServerreference
-
runOn
Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.- Parameters:
loopResources- a new loop resourcesfamily- a specificSocketProtocolFamilyto run with- Returns:
- a new
UdpServerreference - Since:
- 1.3.0
-
warmup
Based on the actual configuration, returns aMonothat triggers:- an initialization of the event loop group
- 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
-
wiretap
Description copied from class:TransportApply or remove a wire logger configuration usingTransportcategory (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretapin classTransport<UdpServer,UdpServerConfig> - Parameters:
enable- specifies whether the wire logger configuration will be added to the pipeline- Returns:
- a new
Transportreference
-
wiretap
Description copied from class:TransportApply a wire logger configuration using the specified category (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretapin classTransport<UdpServer,UdpServerConfig> - Parameters:
category- the logger category- Returns:
- a new
Transportreference
-
wiretap
Description copied from class:TransportApply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretapin classTransport<UdpServer,UdpServerConfig> - Parameters:
category- the logger categorylevel- the logger level- Returns:
- a new
Transportreference
-