Top Description Inners Fields Constructors Methods
reactor.netty.udp

public abstract Class UdpServer

extends Transport<UdpServer, UdpServerConfig>
Class Inheritance
Known Direct Subclasses
reactor.netty.udp.UdpServerBind
Imports
java.net.SocketAddress, java.time.Duration, java.util.Objects, java.util.function.BiFunction, .Consumer, .Supplier, io.netty.channel.ChannelOption, .EventLoopGroup, io.netty.channel.socket.InternetProtocolFamily, io.netty.handler.logging.LogLevel, io.netty.util.AttributeKey, org.reactivestreams.Publisher, reactor.core.publisher.Mono, reactor.netty.Connection, .ConnectionObserver, reactor.netty.channel.ChannelMetricsRecorder, reactor.netty.resources.LoopResources, reactor.netty.transport.AddressUtils, .Transport, reactor.util.Logger, .Loggers, reactor.util.annotation.Nullable

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()

Authors
Stephane Maldini, Violeta Georgieva

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final <A> UdpServer
attr(AttributeKey<A>
the AttributeKey key
key
,
A
the AttributeKey value
value
)

Overrides reactor.netty.transport.Transport.attr.

Update the given attribute key or remove it if the value is null.
public abstract Mono<? extends Connection>

Returns:

a Mono of Connection
bind
()

Binds the UdpServer and returns a Mono of Connection.

public final UdpServer
bindAddress(Supplier<? extends SocketAddress>
A supplier of the address to bind to.
bindAddressSupplier
)

Overrides reactor.netty.transport.Transport.bindAddress.

Set a new local address to which this transport should bind on subscribe.
public final Connection

Returns:

a 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).

public final Connection

Returns:

a Connection
bindNow
(Duration
max startup timeout (resolution: ns)
timeout
)

Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires.

public static UdpServer

Returns:

a UdpServer
create
()

Prepare a UdpServer.

public final UdpServer

Returns:

a new UdpServer reference
doOnBind
(Consumer<? super UdpServerConfig>
a consumer observing connected events
doOnBind
)

Set or add a callback called when UdpServer is about to start listening for incoming traffic.

public final UdpServer

Returns:

a new UdpServer reference
doOnBound
(Consumer<? super Connection>
a consumer observing connected events
doOnBound
)

Set or add a callback called after UdpServer has been started.

public final UdpServer

Returns:

a new UdpServer reference
doOnUnbound
(Consumer<? super Connection>
a consumer observing unbound events
doOnUnbound
)

Set or add a callback called after UdpServer has been shutdown.

public final UdpServer

Returns:

a new UdpServer
handle
(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>>
an IO handler that can dispose underlying connection when Publisher terminates.
handler
)

Attach an IO handler to react on connected client.

public final UdpServer

Returns:

a new UdpServer reference
host
(String
the host to bind to.
host
)

The host to which this server should bind.

public final UdpServer
metrics(boolean
true enables metrics collection; false disables it
enable
)

Overrides reactor.netty.transport.Transport.metrics.

Whether to enable metrics to be collected and registered in Micrometer's globalRegistry.
public final UdpServer
metrics(boolean
if true enables the metrics on the Transport.
enable
,
Supplier<? extends ChannelMetricsRecorder>
a supplier for the ChannelMetricsRecorder
recorder
)

Overrides reactor.netty.transport.Transport.metrics.

Specifies whether the metrics are enabled on the Transport.
public final UdpServer
observe(ConnectionObserver
the ConnectionObserver to be set or add
observer
)

Overrides reactor.netty.transport.Transport.observe.

Set or add the given ConnectionObserver to observe the connection state changes.
public final <O> UdpServer
option(ChannelOption<O> key, O
the ChannelOption value or null
value
)

Overrides reactor.netty.transport.Transport.option.

Update the given option key or remove it if the value is null.
public final UdpServer

Returns:

a new UdpServer reference
port
(int
The port to bind to.
port
)

The port to which this server should bind.

public final UdpServer
runOn(EventLoopGroup
an eventLoopGroup to share
eventLoopGroup
)

Overrides reactor.netty.transport.Transport.runOn.

Run IO loops on the given EventLoopGroup.
public final UdpServer
runOn(LoopResources
a LoopResources accepting native runtime expectation and returning an eventLoopGroup
channelResources
)

Overrides reactor.netty.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container.
public final UdpServer

Returns:

a new UdpServer reference
runOn
(LoopResources
a new loop resources
loopResources
,
boolean
should prefer running on epoll, kqueue or similar instead of java NIO
preferNative
)

Overrides reactor.netty.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container.
public final UdpServer

Returns:

a new UdpServer reference
runOn
(LoopResources
a new loop resources
loopResources
,
InternetProtocolFamily
a specific InternetProtocolFamily to run with
family
)

Run IO loops on a supplied EventLoopGroup from the LoopResources container.

public final Mono<Void>

Returns:

a Mono representing the completion of the warmup
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
public final UdpServer
wiretap(boolean
specifies whether the wire logger configuration will be added to the pipeline
enable
)

Overrides reactor.netty.transport.Transport.wiretap.

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.
public final UdpServer
wiretap(String
the logger category
category
)

Overrides reactor.netty.transport.Transport.wiretap.

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.
public final UdpServer
wiretap(String
the logger category
category
,
LogLevel
the logger level
level
)

Overrides reactor.netty.transport.Transport.wiretap.

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.
Inherited from reactor.netty.transport.Transport:
channelGroupconfigurationdoOnChannelInitduplicatewiretapwiretap

Field Detail

logback to summary
pack-priv static final Logger log

Hides reactor.netty.transport.Transport.log.

Constructor Detail

UdpServerback to summary
public UdpServer()

Method Detail

attrback to summary
public final <A> UdpServer attr(AttributeKey<A> key, A value)

Overrides reactor.netty.transport.Transport.attr.

Doc from reactor.netty.transport.Transport.attr.

Update the given attribute key or remove it if the value is null.

Parameters
<A>
the attribute type
key:AttributeKey<A>

the AttributeKey key

value:A

the AttributeKey value

Returns:UdpServer

a new Transport reference

Annotations
@Override
bindback to summary
public abstract Mono<? extends Connection> bind()

Binds the 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 Connection#dispose().

Returns:Mono<? extends Connection>

a Mono of Connection

bindAddressback to summary
public final UdpServer bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier)

Overrides reactor.netty.transport.Transport.bindAddress.

Doc from reactor.netty.transport.Transport.bindAddress.

Set a new local address to which this transport should bind on subscribe.

Parameters
bindAddressSupplier:Supplier<? extends SocketAddress>

A supplier of the address to bind to.

Returns:UdpServer

a new Transport

Annotations
@Override
bindNowback to summary
public 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 is 45 seconds). The returned Connection offers simple server API, including to Connection#disposeNow() shut it down in a blocking fashion.

Returns:Connection

a Connection

bindNowback to summary
public final Connection bindNow(Duration timeout)

Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires. The returned Connection offers simple server API, including to Connection#disposeNow() shut it down in a blocking fashion.

Parameters
timeout:Duration

max startup timeout (resolution: ns)

Returns:Connection

a Connection

createback to summary
public static UdpServer create()

Prepare a UdpServer.

Returns:UdpServer

a UdpServer

doOnBindback to summary
public final UdpServer doOnBind(Consumer<? super UdpServerConfig> doOnBind)

Set or add a callback called when UdpServer is about to start listening for incoming traffic.

Parameters
doOnBind:Consumer<? super UdpServerConfig>

a consumer observing connected events

Returns:UdpServer

a new UdpServer reference

doOnBoundback to summary
public final UdpServer doOnBound(Consumer<? super Connection> doOnBound)

Set or add a callback called after UdpServer has been started.

Parameters
doOnBound:Consumer<? super Connection>

a consumer observing connected events

Returns:UdpServer

a new UdpServer reference

doOnUnboundback to summary
public final UdpServer doOnUnbound(Consumer<? super Connection> doOnUnbound)

Set or add a callback called after UdpServer has been shutdown.

Parameters
doOnUnbound:Consumer<? super Connection>

a consumer observing unbound events

Returns:UdpServer

a new UdpServer reference

handleback to summary
public final UdpServer handle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler)

Attach an IO handler to react on connected client.

Parameters
handler:BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>>

an IO handler that can dispose underlying connection when Publisher terminates.

Returns:UdpServer

a new UdpServer

hostback to summary
public final UdpServer host(String host)

The host to which this server should bind.

Parameters
host:String

the host to bind to.

Returns:UdpServer

a new UdpServer reference

metricsback to summary
public final UdpServer metrics(boolean enable)

Overrides reactor.netty.transport.Transport.metrics.

Doc from reactor.netty.transport.Transport.metrics.

Whether to enable metrics to be collected and registered in Micrometer's 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.

Parameters
enable:boolean

true enables metrics collection; false disables it

Returns:UdpServer

a new Transport reference

Annotations
@Override
metricsback to summary
public final UdpServer metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder)

Overrides reactor.netty.transport.Transport.metrics.

Doc from reactor.netty.transport.Transport.metrics.

Specifies whether the metrics are enabled on the 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).

Parameters
enable:boolean

if true enables the metrics on the Transport.

recorder:Supplier<? extends ChannelMetricsRecorder>

a supplier for the ChannelMetricsRecorder

Returns:UdpServer

a new Transport reference

Annotations
@Override
observeback to summary
public final UdpServer observe(ConnectionObserver observer)

Overrides reactor.netty.transport.Transport.observe.

Doc from reactor.netty.transport.Transport.observe.

Set or add the given ConnectionObserver to observe the connection state changes.

Parameters
observer:ConnectionObserver

the ConnectionObserver to be set or add

Returns:UdpServer

a new Transport reference

Annotations
@Override
optionback to summary
public final <O> UdpServer option(ChannelOption<O> key, O value)

Overrides reactor.netty.transport.Transport.option.

Doc from reactor.netty.transport.Transport.option.

Update the given option key or remove it if the value is null.

Note

Setting ChannelOption#AUTO_READ option will be ignored. It is configured to be false.

Parameters
<O>
the option type
key:ChannelOption<O>

the ChannelOption key

value:O

the ChannelOption value or null

Returns:UdpServer

a new Transport reference

Annotations
@Override
portback to summary
public final UdpServer port(int port)

The port to which this server should bind.

Parameters
port:int

The port to bind to.

Returns:UdpServer

a new UdpServer reference

runOnback to summary
public final UdpServer runOn(EventLoopGroup eventLoopGroup)

Overrides reactor.netty.transport.Transport.runOn.

Doc from reactor.netty.transport.Transport.runOn.

Run IO loops on the given EventLoopGroup.

Parameters
eventLoopGroup:EventLoopGroup

an eventLoopGroup to share

Returns:UdpServer

a new Transport reference

Annotations
@Override
runOnback to summary
public final UdpServer runOn(LoopResources channelResources)

Overrides reactor.netty.transport.Transport.runOn.

Doc from reactor.netty.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container. Will prefer native (epoll/kqueue) implementation if available unless the environment property reactor.netty.native is set to false.

Parameters
channelResources:LoopResources

a LoopResources accepting native runtime expectation and returning an eventLoopGroup

Returns:UdpServer

a new Transport reference

Annotations
@Override
runOnback to summary
public final UdpServer runOn(LoopResources loopResources, boolean preferNative)

Overrides reactor.netty.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container.

Parameters
loopResources:LoopResources

a new loop resources

preferNative:boolean

should prefer running on epoll, kqueue or similar instead of java NIO

Returns:UdpServer

a new UdpServer reference

Annotations
@Override
runOnback to summary
public final UdpServer runOn(LoopResources loopResources, InternetProtocolFamily family)

Run IO loops on a supplied EventLoopGroup from the LoopResources container.

Parameters
loopResources:LoopResources

a new loop resources

family:InternetProtocolFamily

a specific InternetProtocolFamily to run with

Returns:UdpServer

a new UdpServer reference

warmupback to summary
public final 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.
Returns:Mono<Void>

a Mono representing the completion of the warmup

Since
1.0.3
wiretapback to summary
public final UdpServer wiretap(boolean enable)

Overrides reactor.netty.transport.Transport.wiretap.

Doc from reactor.netty.transport.Transport.wiretap.

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.

Parameters
enable:boolean

specifies whether the wire logger configuration will be added to the pipeline

Returns:UdpServer

a new Transport reference

Annotations
@Override
wiretapback to summary
public final UdpServer wiretap(String category)

Overrides reactor.netty.transport.Transport.wiretap.

Doc from reactor.netty.transport.Transport.wiretap.

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.

Parameters
category:String

the logger category

Returns:UdpServer

a new Transport reference

Annotations
@Override
wiretapback to summary
public final UdpServer wiretap(String category, LogLevel level)

Overrides reactor.netty.transport.Transport.wiretap.

Doc from reactor.netty.transport.Transport.wiretap.

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.

Parameters
category:String

the logger category

level:LogLevel

the logger level

Returns:UdpServer

a new Transport reference

Annotations
@Override
reactor.netty.udp back to summary

pack-priv final Class UdpServer.OnBoundHandle

extends Object
implements Consumer<Connection>
Class Inheritance
All Implemented Interfaces
java.util.function.Consumer

Field Summary

Modifier and TypeField and Description
pack-priv final BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>>

Constructor Summary

AccessConstructor and Description
pack-priv
OnBoundHandle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler)

Method Summary

Modifier and TypeMethod and Description
public void
accept(Connection
the input argument
c
)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlerback to summary
pack-priv final BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler

Constructor Detail

OnBoundHandleback to summary
pack-priv OnBoundHandle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler)

Method Detail

acceptback to summary
public void accept(Connection c)

Implements java.util.function.Consumer.accept.

Doc from java.util.function.Consumer.accept.

Performs this operation on the given argument.

Parameters
c:Connection

the input argument

Annotations
@Override