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> UdpServer
attr
(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 UdpServer
bindAddress
(Supplier<? extends SocketAddress> bindAddressSupplier) Set a new local address to which this transport should bind on subscribe.final Connection
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 Connection
Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires.static UdpServer
create()
Prepare aUdpServer
.final UdpServer
doOnBind
(Consumer<? super UdpServerConfig> doOnBind) Set or add a callback called whenUdpServer
is about to start listening for incoming traffic.final UdpServer
doOnBound
(Consumer<? super Connection> doOnBound) Set or add a callback called afterUdpServer
has been started.final UdpServer
doOnUnbound
(Consumer<? super Connection> doOnUnbound) Set or add a callback called afterUdpServer
has been shutdown.final UdpServer
handle
(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) Attach an IO handler to react on connected client.final UdpServer
The host to which this server should bind.final UdpServer
metrics
(boolean enable) Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
.final UdpServer
metrics
(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Specifies whether the metrics are enabled on theTransport
.final UdpServer
observe
(ConnectionObserver observer) Set or add the givenConnectionObserver
to observe the connection state changes.final <O> UdpServer
option
(ChannelOption<O> key, @Nullable O value) Update the given option key or remove it if the value is null.final UdpServer
port
(int port) The port to which this server should bind.final UdpServer
runOn
(EventLoopGroup eventLoopGroup) Run IO loops on the givenEventLoopGroup
.final UdpServer
runOn
(LoopResources channelResources) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.final UdpServer
runOn
(LoopResources loopResources, boolean preferNative) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.final UdpServer
runOn
(LoopResources loopResources, InternetProtocolFamily family) Deprecated.as of 1.3.0.final UdpServer
runOn
(LoopResources loopResources, SocketProtocolFamily family) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.warmup()
Based on the actual configuration, returns aMono
that triggers: an initialization of the event loop group 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.final UdpServer
wiretap
(boolean enable) Apply or remove a wire logger configuration usingTransport
category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.final UdpServer
Apply a wire logger configuration using the specified category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.final UdpServer
Apply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, 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:Transport
Update the given attribute key or remove it if the value is null.- Overrides:
attr
in classTransport<UdpServer,
UdpServerConfig> - Type Parameters:
A
- the attribute type- Parameters:
key
- theAttributeKey
keyvalue
- theAttributeKey
value- Returns:
- a new
Transport
reference
-
bind
Binds theUdpServer
and returns aMono
ofConnection
. IfMono
is cancelled, the underlying binding will be aborted. Once theConnection
has been emitted and is not necessary anymore, disposing the main server loop must be done by the user viaDisposableChannel.dispose()
.- Returns:
- a
Mono
ofConnection
-
bindAddress
Description copied from class:Transport
Set a new local address to which this transport should bind on subscribe.- Overrides:
bindAddress
in 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 is45
seconds). The returnedConnection
offers 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 returnedConnection
offers 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 whenUdpServer
is about to start listening for incoming traffic.- Parameters:
doOnBind
- a consumer observing connected events- Returns:
- a new
UdpServer
reference
-
doOnBound
Set or add a callback called afterUdpServer
has been started.- Parameters:
doOnBound
- a consumer observing connected events- Returns:
- a new
UdpServer
reference
-
doOnUnbound
Set or add a callback called afterUdpServer
has been shutdown.- Parameters:
doOnUnbound
- a consumer observing unbound events- Returns:
- a new
UdpServer
reference
-
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
UdpServer
reference
-
metrics
Description copied from class:Transport
Whether 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:
metrics
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
enable
- true enables metrics collection; false disables it- Returns:
- a new
Transport
reference
-
metrics
Description copied from class:Transport
Specifies 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:
metrics
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
enable
- if true enables the metrics on theTransport
.recorder
- a supplier for theChannelMetricsRecorder
- Returns:
- a new
Transport
reference
-
observe
Description copied from class:Transport
Set or add the givenConnectionObserver
to observe the connection state changes.- Overrides:
observe
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
observer
- theConnectionObserver
to be set or add- Returns:
- a new
Transport
reference
-
option
Description copied from class:Transport
Update the given option key or remove it if the value is null. Note: SettingChannelOption.AUTO_READ
option will be ignored. It is configured to befalse
.- Overrides:
option
in classTransport<UdpServer,
UdpServerConfig> - Type Parameters:
O
- the option type- Parameters:
key
- theChannelOption
keyvalue
- theChannelOption
value or null- Returns:
- a new
Transport
reference
-
port
The port to which this server should bind. If a port is not specified, the default port12012
is used.Note: The port can be specified also with
PORT
environment variable.- Parameters:
port
- The port to bind to.- Returns:
- a new
UdpServer
reference
-
runOn
Description copied from class:Transport
Run IO loops on the givenEventLoopGroup
.- Overrides:
runOn
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
eventLoopGroup
- an eventLoopGroup to share- Returns:
- a new
Transport
reference
-
runOn
Description copied from class:Transport
Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container. Will prefer native (epoll/io_uring/kqueue) implementation if available unless the environment propertyreactor.netty.native
is set tofalse
.- Overrides:
runOn
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
channelResources
- aLoopResources
accepting native runtime expectation and returning an eventLoopGroup- Returns:
- a new
Transport
reference
-
runOn
Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.- Overrides:
runOn
in 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
UdpServer
reference
-
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 suppliedEventLoopGroup
from theLoopResources
container.- Parameters:
loopResources
- a new loop resourcesfamily
- a specificInternetProtocolFamily
to run with- Returns:
- a new
UdpServer
reference
-
runOn
Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.- Parameters:
loopResources
- a new loop resourcesfamily
- a specificSocketProtocolFamily
to run with- Returns:
- a new
UdpServer
reference - Since:
- 1.3.0
-
warmup
Based on the actual configuration, returns aMono
that triggers:- an initialization of the event loop group
- 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
-
wiretap
Description copied from class:Transport
Apply or remove a wire logger configuration usingTransport
category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretap
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
enable
- specifies whether the wire logger configuration will be added to the pipeline- Returns:
- a new
Transport
reference
-
wiretap
Description copied from class:Transport
Apply a wire logger configuration using the specified category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretap
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
category
- the logger category- Returns:
- a new
Transport
reference
-
wiretap
Description copied from class:Transport
Apply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretap
in classTransport<UdpServer,
UdpServerConfig> - Parameters:
category
- the logger categorylevel
- the logger level- Returns:
- a new
Transport
reference
-