public abstract class UdpServer extends Object
bind(Bootstrap)
is ultimately called.
Internally, materialization happens in two phases, first configure()
is
called to retrieve a ready to use Bootstrap
then bind(Bootstrap)
is 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 |
---|---|
UdpServer |
addressSupplier(java.util.function.Supplier<? extends SocketAddress> bindingAddressSupplier)
The address to which this server should bind on subscribe.
|
<T> UdpServer |
attr(AttributeKey<T> key,
T value)
Inject default attribute to the future child
Channel connections. |
Mono<? extends Connection> |
bind()
|
protected abstract Mono<? extends Connection> |
bind(Bootstrap b)
|
Connection |
bindNow(java.time.Duration timeout)
Start a Server in a blocking fashion, and wait for it to finish initializing.
|
UdpServer |
bootstrap(java.util.function.Function<? super Bootstrap,? extends Bootstrap> bootstrapMapper)
Apply
Bootstrap configuration given mapper taking currently configured one
and returning a new one to be ultimately used for socket binding. |
protected Bootstrap |
configure()
Materialize a Bootstrap from the parent
UdpServer chain to use with bind(Bootstrap) or separately |
static UdpServer |
create()
Prepare a
UdpServer |
UdpServer |
doOnBind(java.util.function.Consumer<? super Bootstrap> doOnBind)
Setup a callback called when
Channel is about to
bind. |
UdpServer |
doOnBound(java.util.function.Consumer<? super Connection> doOnBound)
Setup a callback called when
Channel is
bound. |
UdpServer |
doOnLifecycle(java.util.function.Consumer<? super Bootstrap> onBind,
java.util.function.Consumer<? super Connection> onBound,
java.util.function.Consumer<? super Connection> onUnbound)
Setup all lifecycle callbacks called on or after
Channel
has been bound and after it has been unbound. |
UdpServer |
doOnUnbound(java.util.function.Consumer<? super Connection> doOnUnbound)
Setup a callback called when
Channel is
unbound. |
UdpServer |
handle(java.util.function.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 metricsEnabled)
Whether to enable metrics to be collected and registered in Micrometer's
globalRegistry
under the name Metrics.UDP_SERVER_PREFIX . |
UdpServer |
metrics(boolean metricsEnabled,
ChannelMetricsRecorder recorder)
Specifies whether the metrics are enabled on the
UdpServer . |
UdpServer |
observe(ConnectionObserver observer)
Setup all lifecycle callbacks called on or after
Channel
has been connected and after it has been disconnected. |
<T> UdpServer |
option(ChannelOption<T> key,
T value)
|
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 channelResources,
boolean preferNative)
Run IO loops on a supplied
EventLoopGroup from the LoopResources
container. |
UdpServer |
runOn(LoopResources channelResources,
InternetProtocolFamily family)
Run IO loops on a supplied
EventLoopGroup from the LoopResources
container. |
UdpServer |
wiretap(boolean enable)
Apply or remove a wire logger configuration using
UdpServer category
and DEBUG logger level |
UdpServer |
wiretap(String category)
Apply a wire logger configuration using the specified category
and
DEBUG logger level |
UdpServer |
wiretap(String category,
LogLevel level)
Apply a wire logger configuration using the specified category
and logger level
|
public final UdpServer addressSupplier(java.util.function.Supplier<? extends SocketAddress> bindingAddressSupplier)
bindingAddressSupplier
- A supplier of the address to bind to.UdpServer
public final <T> UdpServer attr(AttributeKey<T> key, T value)
Channel
connections. They
will be available via AttributeMap.attr(AttributeKey)
.T
- the attribute typekey
- the attribute keyvalue
- the attribute valueUdpServer
AbstractBootstrap.attr(AttributeKey, Object)
public final UdpServer bootstrap(java.util.function.Function<? super Bootstrap,? extends Bootstrap> bootstrapMapper)
Bootstrap
configuration given mapper taking currently configured one
and returning a new one to be ultimately used for socket binding. Configuration
will apply during configure()
phase.
bootstrapMapper
- A bootstrap mapping function to update configuration and return an
enriched bootstrap.UdpServer
public final Mono<? extends Connection> bind()
UdpServer
and return 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 main server
loop must be done by the user via DisposableChannel.dispose()
.
If update configuration phase fails, a Mono.error(Throwable)
will be returnedMono
of Connection
public final Connection bindNow(java.time.Duration timeout)
Connection
offers simple server API, including to DisposableChannel.disposeNow()
shut it down in a blocking fashion.timeout
- max startup timeoutConnection
public final UdpServer doOnBind(java.util.function.Consumer<? super Bootstrap> doOnBind)
Channel
is about to
bind.doOnBind
- a consumer observing server start eventUdpServer
public final UdpServer doOnBound(java.util.function.Consumer<? super Connection> doOnBound)
Channel
is
bound.doOnBound
- a consumer observing server started eventUdpServer
public final UdpServer doOnUnbound(java.util.function.Consumer<? super Connection> doOnUnbound)
Channel
is
unbound.doOnUnbound
- a consumer observing server stop eventUdpServer
public final UdpServer doOnLifecycle(java.util.function.Consumer<? super Bootstrap> onBind, java.util.function.Consumer<? super Connection> onBound, java.util.function.Consumer<? super Connection> onUnbound)
Channel
has been bound and after it has been unbound.onBind
- a consumer observing server start eventonBound
- a consumer observing server started eventonUnbound
- a consumer observing server stop eventUdpServer
public final UdpServer handle(java.util.function.BiFunction<? super UdpInbound,? super UdpOutbound,? extends Publisher<Void>> handler)
public final UdpServer host(String host)
host
- The host to bind to.UdpServer
public final UdpServer observe(ConnectionObserver observer)
Channel
has been connected and after it has been disconnected.observer
- a consumer observing state changesUdpServer
public final <T> UdpServer option(ChannelOption<T> key, T value)
ChannelOption
value for low level connection settings like SO_TIMEOUT
or SO_KEEPALIVE
. This will apply to each new channel from remote peer.T
- the option typekey
- the option keyvalue
- the option valueUdpServer
AbstractBootstrap.option(ChannelOption, Object)
public final UdpServer port(int port)
port
- The port to bind to.UdpServer
public final UdpServer runOn(EventLoopGroup eventLoopGroup)
EventLoopGroup
.eventLoopGroup
- an eventLoopGroup to shareUdpServer
public final UdpServer runOn(LoopResources channelResources)
EventLoopGroup
from the LoopResources
container. Will prefer native (epoll/kqueue) implementation if available unless the
environment property reactor.netty.native
is set to false
.channelResources
- a LoopResources
accepting native runtime
expectation and returning an eventLoopGroupUdpServer
public final UdpServer runOn(LoopResources channelResources, boolean preferNative)
EventLoopGroup
from the LoopResources
container.channelResources
- a LoopResources
accepting native runtime
expectation and returning an eventLoopGroup.preferNative
- Should the connector prefer native (epoll/kqueue) if available.UdpServer
public final UdpServer runOn(LoopResources channelResources, InternetProtocolFamily family)
EventLoopGroup
from the LoopResources
container.channelResources
- a LoopResources
accepting native runtime
expectation and returning an eventLoopGroup.family
- a specific InternetProtocolFamily
to run withUdpServer
public final UdpServer metrics(boolean metricsEnabled)
globalRegistry
under the name Metrics.UDP_SERVER_PREFIX
. Applications can
separately register their own
filters
associated with this name.
For example, to put an upper bound on the number of tags produced:
MeterFilter filter = ... ; Metrics.globalRegistry.config().meterFilter(MeterFilter.maximumAllowableTags(UDP_SERVER_PREFIX, 100, filter));
By default this is not enabled.
metricsEnabled
- true enables metrics collection; false disables itUdpServer
public final UdpServer metrics(boolean metricsEnabled, ChannelMetricsRecorder recorder)
UdpServer
.
All generated metrics are provided to the specified recorder.metricsEnabled
- if true enables the metrics on the server.recorder
- the ChannelMetricsRecorder
UdpServer
public final UdpServer wiretap(boolean enable)
UdpServer
category
and DEBUG
logger levelenable
- Specifies whether the wire logger configuration will be added to
the pipelineUdpServer
public final UdpServer wiretap(String category)
DEBUG
logger levelcategory
- the logger categoryUdpServer
public final UdpServer wiretap(String category, LogLevel level)
category
- the logger categorylevel
- the logger levelUdpServer
protected Bootstrap configure()
UdpServer
chain to use with bind(Bootstrap)
or separatelyBootstrap
protected abstract Mono<? extends Connection> bind(Bootstrap b)
b
- the Bootstrap
to bindMono
of Connection