Package reactor.netty.transport
Class Transport<T extends Transport<T,C>,C extends TransportConfig>
java.lang.Object
reactor.netty.transport.Transport<T,C>
- Type Parameters:
T
- Transport implementationC
- Transport Config implementation
- Direct Known Subclasses:
ClientTransport
,QuicClient
,QuicServer
,ServerTransport
,UdpServer
An immutable transport builder for clients and servers.
- Since:
- 1.0.0
- Author:
- Stephane Maldini, Violeta Georgieva
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<A> T
attr
(AttributeKey<A> key, @Nullable A value) Update the given attribute key or remove it if the value is null.bindAddress
(Supplier<? extends SocketAddress> bindAddressSupplier) Set a new local address to which this transport should bind on subscribe.channelGroup
(ChannelGroup channelGroup) Provide aChannelGroup
to hold all active connected channels.abstract C
Return aTransportConfig
.doOnChannelInit
(ChannelPipelineConfigurer doOnChannelInit) Configure the channel pipeline while initializing the channel.protected abstract T
Return a newTransport
inheriting the current configuration.protected T
metrics
(boolean enable) Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
.metrics
(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Specifies whether the metrics are enabled on theTransport
.observe
(ConnectionObserver observer) Set or add the givenConnectionObserver
to observe the connection state changes.<O> T
option
(ChannelOption<O> key, @Nullable O value) Update the given option key or remove it if the value is null.runOn
(EventLoopGroup eventLoopGroup) Run IO loops on the givenEventLoopGroup
.runOn
(LoopResources channelResources) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.runOn
(LoopResources loopResources, boolean preferNative) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.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.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.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.final T
wiretap
(String category, LogLevel level, AdvancedByteBufFormat format) Apply a wire logger configuration using the specified category (logger), logger level andByteBuf
format.final T
wiretap
(String category, LogLevel level, AdvancedByteBufFormat format, Charset charset) Apply a wire logger configuration using the specific category (logger), logger level,ByteBuf
format and charset.
-
Constructor Details
-
Transport
public Transport()
-
-
Method Details
-
attr
Update the given attribute key or remove it if the value is null.- Type Parameters:
A
- the attribute type- Parameters:
key
- theAttributeKey
keyvalue
- theAttributeKey
value- Returns:
- a new
Transport
reference
-
bindAddress
Set a new local address to which this transport should bind on subscribe.- Parameters:
bindAddressSupplier
- A supplier of the address to bind to.- Returns:
- a new
Transport
-
channelGroup
Provide aChannelGroup
to hold all active connected channels.Graceful Shutdown:
When a
ChannelGroup
is set, calls toDisposableChannel.disposeNow()
andDisposableChannel.disposeNow(Duration)
not only stop accepting new requests but also additionally wait for all active requests, in theChannelGroup
, to complete, within the given timeout.- Parameters:
channelGroup
- aChannelGroup
- Returns:
- a new
Transport
reference
-
configuration
Return aTransportConfig
.- Returns:
- a
TransportConfig
-
doOnChannelInit
Configure the channel pipeline while initializing the channel.- Parameters:
doOnChannelInit
- configure the channel pipeline while initializing the channel- Returns:
- a new
Transport
reference
-
metrics
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.
- Parameters:
enable
- true enables metrics collection; false disables it- Returns:
- a new
Transport
reference
-
metrics
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
).- Parameters:
enable
- if true enables the metrics on theTransport
.recorder
- a supplier for theChannelMetricsRecorder
- Returns:
- a new
Transport
reference
-
observe
Set or add the givenConnectionObserver
to observe the connection state changes.- Parameters:
observer
- theConnectionObserver
to be set or add- Returns:
- a new
Transport
reference
-
option
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
.- Type Parameters:
O
- the option type- Parameters:
key
- theChannelOption
keyvalue
- theChannelOption
value or null- Returns:
- a new
Transport
reference
-
runOn
Run IO loops on the givenEventLoopGroup
.- Parameters:
eventLoopGroup
- an eventLoopGroup to share- Returns:
- a new
Transport
reference
-
runOn
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
.- 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.- Parameters:
loopResources
- a new loop resourcespreferNative
- should prefer running on epoll, io_uring, kqueue or similar instead of java NIO- Returns:
- a new
Transport
reference
-
wiretap
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.- Parameters:
enable
- specifies whether the wire logger configuration will be added to the pipeline- Returns:
- a new
Transport
reference
-
wiretap
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.- Parameters:
category
- the logger category- Returns:
- a new
Transport
reference
-
wiretap
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.- Parameters:
category
- the logger categorylevel
- the logger level- Returns:
- a new
Transport
reference
-
wiretap
Apply a wire logger configuration using the specified category (logger), logger level andByteBuf
format. Depending on the format:AdvancedByteBufFormat.SIMPLE
- only the events will be loggedAdvancedByteBufFormat.HEX_DUMP
- both events and content will be logged, with content in hex formatAdvancedByteBufFormat.TEXTUAL
- both events and content will be logged, with content in plain text format
AdvancedByteBufFormat.TEXTUAL
is specified,Charset.defaultCharset()
will be used. -
wiretap
public final T wiretap(String category, LogLevel level, AdvancedByteBufFormat format, Charset charset) Apply a wire logger configuration using the specific category (logger), logger level,ByteBuf
format and charset. The charset is relevant in case ofAdvancedByteBufFormat.TEXTUAL
and a different charset thanCharset.defaultCharset()
is required. Depending on the format:AdvancedByteBufFormat.SIMPLE
- only the events will be loggedAdvancedByteBufFormat.HEX_DUMP
- both events and content will be logged, with content in hex formatAdvancedByteBufFormat.TEXTUAL
- both events and content will be logged, with content in plain text format
-
duplicate
Return a newTransport
inheriting the current configuration. This is a shallow copy.- Returns:
- a new
Transport
inheriting the current configuration
-