public abstract class UdpServer extends Transport<UdpServer,UdpServerConfig>
bind()
is ultimately called.
Example:
UdpServer.create()
.doOnBind(startMetrics)
.doOnBound(startedMetrics)
.doOnUnbind(stopMetrics)
.host("127.0.0.1")
.port(1234)
.bind()
.block()
Constructor and Description |
---|
UdpServer() |
Modifier and Type | Method and Description |
---|---|
<A> UdpServer |
attr(AttributeKey<A> key,
A value)
Update the given attribute key or remove it if the value is null.
|
abstract Mono<? extends Connection> |
bind()
|
UdpServer |
bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier)
Set a new local address to which this transport should bind on subscribe.
|
Connection |
bindNow()
Starts the server in a blocking fashion, and waits for it to finish initializing
or the startup timeout expires (the startup timeout is
45 seconds). |
Connection |
bindNow(Duration timeout)
Start the server in a blocking fashion, and wait for it to finish initializing
or the provided startup timeout expires.
|
static UdpServer |
create()
Prepare a
UdpServer |
UdpServer |
doOnBind(Consumer<? super UdpServerConfig> doOnBind)
Set or add a callback called when
UdpServer is about to start listening for incoming traffic. |
UdpServer |
doOnBound(Consumer<? super Connection> doOnBound)
Set or add a callback called after
UdpServer has been started. |
UdpServer |
doOnUnbound(Consumer<? super Connection> doOnUnbound)
Set or add a callback called after
UdpServer has been shutdown. |
UdpServer |
handle(BiFunction<? super UdpInbound,? super UdpOutbound,? extends Publisher<Void>> handler)
Attach an IO handler to react on connected client
|
UdpServer |
host(String host)
The host to which this server should bind.
|
UdpServer |
metrics(boolean enable)
Whether to enable metrics to be collected and registered in Micrometer's
globalRegistry . |
UdpServer |
metrics(boolean enable,
Supplier<? extends ChannelMetricsRecorder> recorder)
Specifies whether the metrics are enabled on the
Transport . |
UdpServer |
observe(ConnectionObserver observer)
Set or add the given
ConnectionObserver to observe the connection state changes. |
<O> UdpServer |
option(ChannelOption<O> key,
O value)
Update the given option key or remove it if the value is null.
|
UdpServer |
port(int port)
The port to which this server should bind.
|
UdpServer |
runOn(EventLoopGroup eventLoopGroup)
Run IO loops on the given
EventLoopGroup . |
UdpServer |
runOn(LoopResources channelResources)
Run IO loops on a supplied
EventLoopGroup from the LoopResources container. |
UdpServer |
runOn(LoopResources loopResources,
boolean preferNative)
Run IO loops on a supplied
EventLoopGroup from the LoopResources container. |
UdpServer |
runOn(LoopResources loopResources,
InternetProtocolFamily family)
Run IO loops on a supplied
EventLoopGroup from the LoopResources container. |
Mono<Void> |
warmup()
Based on the actual configuration, returns a
Mono that triggers:
an initialization of the event loop group
loads the necessary native libraries for the transport
By default, when method is not used, the bind operation absorbs the extra time needed to load resources. |
UdpServer |
wiretap(boolean enable)
Apply or remove a wire logger configuration using
Transport category (logger),
DEBUG logger level and AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format. |
UdpServer |
wiretap(String category)
Apply a wire logger configuration using the specified category (logger),
DEBUG logger level and AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format. |
UdpServer |
wiretap(String category,
LogLevel level)
Apply a wire logger configuration using the specified category (logger),
logger level and
AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format. |
channelGroup, configuration, doOnChannelInit, duplicate, wiretap, wiretap
public final <A> UdpServer attr(AttributeKey<A> key, @Nullable A value)
Transport
attr
in class Transport<UdpServer,UdpServerConfig>
A
- the attribute typekey
- the AttributeKey
keyvalue
- the AttributeKey
valueTransport
referencepublic abstract Mono<? extends Connection> bind()
UdpServer
and returns a Mono
of Connection
. If
Mono
is cancelled, the underlying binding will be aborted. Once the Connection
has been emitted and is not necessary anymore, disposing the main server
loop must be done by the user via DisposableChannel.dispose()
.Mono
of Connection
public final UdpServer bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier)
Transport
bindAddress
in class Transport<UdpServer,UdpServerConfig>
bindAddressSupplier
- A supplier of the address to bind to.Transport
public final Connection bindNow()
45
seconds). The
returned Connection
offers simple server API, including to DisposableChannel.disposeNow()
shut it down in a blocking fashion.Connection
public final Connection bindNow(Duration timeout)
Connection
offers simple server API, including to DisposableChannel.disposeNow()
shut it down in a blocking fashion.timeout
- max startup timeout (resolution: ns)Connection
public final UdpServer doOnBind(Consumer<? super UdpServerConfig> doOnBind)
UdpServer
is about to start listening for incoming traffic.doOnBind
- a consumer observing connected eventsUdpServer
referencepublic final UdpServer doOnBound(Consumer<? super Connection> doOnBound)
UdpServer
has been started.doOnBound
- a consumer observing connected eventsUdpServer
referencepublic final UdpServer doOnUnbound(Consumer<? super Connection> doOnUnbound)
UdpServer
has been shutdown.doOnUnbound
- a consumer observing unbound eventsUdpServer
referencepublic final UdpServer handle(BiFunction<? super UdpInbound,? super UdpOutbound,? extends Publisher<Void>> handler)
public final UdpServer host(String host)
host
- the host to bind to.UdpServer
referencepublic final UdpServer metrics(boolean enable)
Transport
globalRegistry
.
Applications can separately register their own
filters
.
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.
metrics
in class Transport<UdpServer,UdpServerConfig>
enable
- true enables metrics collection; false disables itTransport
referencepublic final UdpServer metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder)
Transport
Transport
.
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 the Transport
).metrics
in class Transport<UdpServer,UdpServerConfig>
enable
- if true enables the metrics on the Transport
.recorder
- a supplier for the ChannelMetricsRecorder
Transport
referencepublic final UdpServer observe(ConnectionObserver observer)
Transport
ConnectionObserver
to observe the connection state changes.observe
in class Transport<UdpServer,UdpServerConfig>
observer
- the ConnectionObserver
to be set or addTransport
referencepublic final <O> UdpServer option(ChannelOption<O> key, @Nullable O value)
Transport
ChannelOption.AUTO_READ
option will be ignored. It is configured to be false
.option
in class Transport<UdpServer,UdpServerConfig>
O
- the option typekey
- the ChannelOption
keyvalue
- the ChannelOption
value or nullTransport
referencepublic final UdpServer port(int port)
port
- The port to bind to.UdpServer
referencepublic final UdpServer runOn(EventLoopGroup eventLoopGroup)
Transport
EventLoopGroup
.runOn
in class Transport<UdpServer,UdpServerConfig>
eventLoopGroup
- an eventLoopGroup to shareTransport
referencepublic final UdpServer runOn(LoopResources channelResources)
Transport
EventLoopGroup
from the LoopResources
container.
Will prefer native (epoll/kqueue) implementation if available
unless the environment property reactor.netty.native
is set to false
.runOn
in class Transport<UdpServer,UdpServerConfig>
channelResources
- a LoopResources
accepting native runtime expectation and
returning an eventLoopGroupTransport
referencepublic final UdpServer runOn(LoopResources loopResources, boolean preferNative)
EventLoopGroup
from the LoopResources
container.runOn
in class Transport<UdpServer,UdpServerConfig>
loopResources
- a new loop resourcespreferNative
- should prefer running on epoll, kqueue or similar instead of java NIOUdpServer
referencepublic final UdpServer runOn(LoopResources loopResources, InternetProtocolFamily family)
EventLoopGroup
from the LoopResources
container.loopResources
- a new loop resourcesfamily
- a specific InternetProtocolFamily
to run withUdpServer
referencepublic final Mono<Void> warmup()
Mono
that triggers:
bind operation
absorbs the extra time needed to load resources.Mono
representing the completion of the warmuppublic final UdpServer wiretap(boolean enable)
Transport
Transport
category (logger),
DEBUG
logger level and AdvancedByteBufFormat.HEX_DUMP
for ByteBuf
format,
which means both events and content will be logged and the content will be in hex format.wiretap
in class Transport<UdpServer,UdpServerConfig>
enable
- specifies whether the wire logger configuration will be added to the pipelineTransport
referencepublic final UdpServer wiretap(String category)
Transport
DEBUG
logger level and AdvancedByteBufFormat.HEX_DUMP
for ByteBuf
format,
which means both events and content will be logged and the content will be in hex format.wiretap
in class Transport<UdpServer,UdpServerConfig>
category
- the logger categoryTransport
referencepublic final UdpServer wiretap(String category, LogLevel level)
Transport
AdvancedByteBufFormat.HEX_DUMP
for ByteBuf
format,
which means both events and content will be logged and the content will be in hex format.wiretap
in class Transport<UdpServer,UdpServerConfig>
category
- the logger categorylevel
- the logger levelTransport
reference