public abstract class UdpClient extends Object
connect(Bootstrap)
is ultimately called.
Internally, materialization happens in two phases, first configure()
is
called to retrieve a ready to use Bootstrap
then connect(Bootstrap)
is called.
Example:
UdpClient.create()
.doOnConnect(startMetrics)
.doOnConnected(startedMetrics)
.doOnDisconnected(stopMetrics)
.host("127.0.0.1")
.port(1234)
.connect()
.block()
Constructor and Description |
---|
UdpClient() |
Modifier and Type | Method and Description |
---|---|
UdpClient |
addressSupplier(java.util.function.Supplier<? extends SocketAddress> connectingAddressSupplier)
The address to which this client should connect on subscribe.
|
<T> UdpClient |
attr(AttributeKey<T> key,
T value)
Inject default attribute to the future child
Channel connections. |
UdpClient |
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
UdpClient chain to use with connect(Bootstrap) or separately |
Mono<? extends Connection> |
connect()
|
protected abstract Mono<? extends Connection> |
connect(Bootstrap b)
|
Connection |
connectNow(java.time.Duration timeout)
Block the
UdpClient and return a Connection . |
static UdpClient |
create()
Prepare a
UdpClient |
UdpClient |
doOnConnect(java.util.function.Consumer<? super Bootstrap> doOnConnect)
Setup a callback called when
Channel is about to
connect. |
UdpClient |
doOnConnected(java.util.function.Consumer<? super Connection> doOnConnected)
Setup a callback called when
Channel is
connected. |
UdpClient |
doOnDisconnected(java.util.function.Consumer<? super Connection> doOnDisconnected)
Setup a callback called when
Channel is
disconnected. |
UdpClient |
doOnLifecycle(java.util.function.Consumer<? super Bootstrap> doOnConnect,
java.util.function.Consumer<? super Connection> doOnConnected,
java.util.function.Consumer<? super Connection> doOnDisconnected)
Setup all lifecycle callbacks called on or after
Channel
has been connected and after it has been disconnected. |
UdpClient |
handle(java.util.function.BiFunction<? super UdpInbound,? super UdpOutbound,? extends Publisher<Void>> handler)
Attach an IO handler to react on connected client
|
UdpClient |
host(String host)
The host to which this client should connect.
|
UdpClient |
metrics(boolean metricsEnabled)
Specifies whether the metrics are enabled on the
UdpClient . |
UdpClient |
metrics(boolean metricsEnabled,
ChannelMetricsRecorder recorder)
Specifies whether the metrics are enabled on the
UdpClient . |
UdpClient |
observe(ConnectionObserver observer)
Setup all lifecycle callbacks called on or after
Channel
has been connected and after it has been disconnected. |
<T> UdpClient |
option(ChannelOption<T> key,
T value)
|
UdpClient |
port(int port)
The port to which this client should connect.
|
UdpClient |
runOn(EventLoopGroup eventLoopGroup)
Run IO loops on the given
EventLoopGroup . |
UdpClient |
runOn(LoopResources channelResources)
Run IO loops on a supplied
EventLoopGroup from the LoopResources
container. |
UdpClient |
runOn(LoopResources channelResources,
boolean preferNative)
Run IO loops on a supplied
EventLoopGroup from the LoopResources
container. |
UdpClient |
runOn(LoopResources channelResources,
InternetProtocolFamily family)
Run IO loops on a supplied
EventLoopGroup from the LoopResources
container. |
UdpClient |
wiretap(boolean enable)
Apply or remove a wire logger configuration using
UdpClient category
and DEBUG logger level |
UdpClient |
wiretap(String category)
Apply a wire logger configuration using the specified category
and
DEBUG logger level |
UdpClient |
wiretap(String category,
LogLevel level)
Apply a wire logger configuration using the specified category
and logger level
|
public final UdpClient addressSupplier(java.util.function.Supplier<? extends SocketAddress> connectingAddressSupplier)
connectingAddressSupplier
- A supplier of the address to connect to.UdpClient
public final <T> UdpClient 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 valueUdpClient
AbstractBootstrap.attr(AttributeKey, Object)
public final UdpClient 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.UdpClient
public final Mono<? extends Connection> connect()
UdpClient
and return a Mono
of Connection
. If
Mono
is cancelled, the underlying connection will be aborted. Once the Connection
has been emitted and is not necessary anymore, disposing main client
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 connectNow(java.time.Duration timeout)
UdpClient
and return a Connection
. Disposing must be
done by the user via DisposableChannel.dispose()
.timeout
- connect timeoutMono
of Connection
public final UdpClient doOnConnect(java.util.function.Consumer<? super Bootstrap> doOnConnect)
Channel
is about to
connect.doOnConnect
- a consumer observing client start eventUdpClient
public final UdpClient doOnConnected(java.util.function.Consumer<? super Connection> doOnConnected)
Channel
is
connected.doOnConnected
- a consumer observing client started eventUdpClient
public final UdpClient doOnDisconnected(java.util.function.Consumer<? super Connection> doOnDisconnected)
Channel
is
disconnected.doOnDisconnected
- a consumer observing client stop eventUdpClient
public final UdpClient doOnLifecycle(java.util.function.Consumer<? super Bootstrap> doOnConnect, java.util.function.Consumer<? super Connection> doOnConnected, java.util.function.Consumer<? super Connection> doOnDisconnected)
Channel
has been connected and after it has been disconnected.doOnConnect
- a consumer observing client start eventdoOnConnected
- a consumer observing client started eventdoOnDisconnected
- a consumer observing client stop eventUdpClient
public final UdpClient host(String host)
host
- The host to connect to.UdpClient
public final UdpClient handle(java.util.function.BiFunction<? super UdpInbound,? super UdpOutbound,? extends Publisher<Void>> handler)
public final UdpClient observe(ConnectionObserver observer)
Channel
has been connected and after it has been disconnected.observer
- a consumer observing state changesUdpClient
public final <T> UdpClient 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 valueUdpClient
AbstractBootstrap.option(ChannelOption, Object)
public final UdpClient port(int port)
port
- The port to connect to.UdpClient
public final UdpClient runOn(EventLoopGroup eventLoopGroup)
EventLoopGroup
.eventLoopGroup
- an eventLoopGroup to shareUdpClient
public final UdpClient 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 eventLoopGroupUdpClient
public final UdpClient 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.UdpClient
public final UdpClient 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 withUdpClient
public final UdpClient metrics(boolean metricsEnabled)
UdpClient
.
All generated metrics are registered in the Micrometer MeterRegistry,
assuming Micrometer is on the classpath.
if name
is NULL
- reactor.netty.udp.client
will be used as a name.metricsEnabled
- if true enables the metrics on the client.UdpClient
public final UdpClient metrics(boolean metricsEnabled, ChannelMetricsRecorder recorder)
UdpClient
.
All generated metrics are provided to the specified recorder.metricsEnabled
- if true enables the metrics on the client.recorder
- the ChannelMetricsRecorder
UdpClient
public final UdpClient wiretap(boolean enable)
UdpClient
category
and DEBUG
logger levelenable
- Specifies whether the wire logger configuration will be added to
the pipelineUdpClient
public final UdpClient wiretap(String category)
DEBUG
logger levelcategory
- the logger categoryUdpClient
public final UdpClient wiretap(String category, LogLevel level)
category
- the logger categorylevel
- the logger levelUdpClient
protected Bootstrap configure()
UdpClient
chain to use with connect(Bootstrap)
or separatelyBootstrap
protected abstract Mono<? extends Connection> connect(Bootstrap b)
b
- the Bootstrap
to connectMono
of Connection