Package reactor.netty.transport
Class ClientTransport<T extends ClientTransport<T,CONF>,CONF extends ClientTransportConfig<CONF>>
java.lang.Object
reactor.netty.transport.Transport<T,CONF>
reactor.netty.transport.ClientTransport<T,CONF>
- Type Parameters:
T
- ClientTransport implementationCONF
- Client Configuration implementation
- Direct Known Subclasses:
HttpClient
,TcpClient
,UdpClient
public abstract class ClientTransport<T extends ClientTransport<T,CONF>,CONF extends ClientTransportConfig<CONF>>
extends Transport<T,CONF>
- Since:
- 1.0.0
- Author:
- Stephane Maldini, Violeta Georgieva
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An interface for selecting resolved addresses based on configuration and available socket addresses. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Mono<? extends Connection>
connect()
protected Connection
Block theClientTransport
and return aConnection
.protected Connection
connectNow
(Duration timeout) Block theClientTransport
and return aConnection
.final T
doAfterResolve
(BiConsumer<? super Connection, ? super SocketAddress> doAfterResolve) Set or add a callback called afterSocketAddress
is resolved successfully.doOnConnect
(Consumer<? super CONF> doOnConnect) Set or add a callback called whenClientTransport
is about to connect to the remote endpoint.doOnConnected
(Consumer<? super Connection> doOnConnected) Set or add a callback called afterConnection
has been connected.doOnDisconnected
(Consumer<? super Connection> doOnDisconnected) Set or add a callback called afterConnection
has been disconnected.final T
doOnResolve
(Consumer<? super Connection> doOnResolve) Set or add a callback called beforeSocketAddress
is resolved.final T
doOnResolveError
(BiConsumer<? super Connection, ? super Throwable> doOnResolveError) Set or add a callback called if an exception happens while resolving to aSocketAddress
.The host to which this client should connect.noProxy()
Remove any previously applied Proxy configuration customization.port
(int port) The port to which this client should connect.proxy
(Consumer<? super ProxyProvider.TypeSpec> proxyOptions) Apply a proxy configuration.final T
Set up a proxy from the java system properties.remoteAddress
(Supplier<? extends SocketAddress> remoteAddressSupplier) The address to which this client should connect on each subscribe.resolvedAddressesSelector
(ClientTransport.ResolvedAddressSelector<? super CONF> resolvedAddressesSelector) Determines the resolved addresses to which this client should connect for each subscription.resolver
(AddressResolverGroup<?> resolver) Assign anAddressResolverGroup
.resolver
(Consumer<NameResolverProvider.NameResolverSpec> nameResolverSpec) Apply a name resolver configuration.runOn
(LoopResources loopResources, boolean preferNative) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.warmup()
Based on the actual configuration, returns aMono
that triggers: an initialization of the event loop group an initialization of the host name resolver loads the necessary native libraries for the transport By default, when method is not used, theconnect operation
absorbs the extra time needed to initialize and load the resources.Methods inherited from class reactor.netty.transport.Transport
attr, bindAddress, channelGroup, configuration, doOnChannelInit, duplicate, metrics, metrics, observe, option, runOn, runOn, wiretap, wiretap, wiretap, wiretap, wiretap
-
Constructor Details
-
ClientTransport
public ClientTransport()
-
-
Method Details
-
connect
Connect theClientTransport
and return aMono
ofConnection
. IfMono
is cancelled, the underlying connection will be aborted. Once theConnection
has been emitted and is not necessary anymore, disposing must be done by the user viaDisposableChannel.dispose()
.- Returns:
- a
Mono
ofConnection
-
connectNow
Block theClientTransport
and return aConnection
. Disposing must be done by the user viaDisposableChannel.dispose()
. The max connection timeout is 45 seconds.- Returns:
- a
Connection
-
connectNow
Block theClientTransport
and return aConnection
. Disposing must be done by the user viaDisposableChannel.dispose()
.- Parameters:
timeout
- connect timeout (resolution: ns)- Returns:
- a
Connection
-
doOnConnect
Set or add a callback called whenClientTransport
is about to connect to the remote endpoint.- Parameters:
doOnConnect
- a consumer observing connect events- Returns:
- a new
ClientTransport
reference
-
doOnConnected
Set or add a callback called afterConnection
has been connected.- Parameters:
doOnConnected
- a consumer observing connected events- Returns:
- a new
ClientTransport
reference
-
doOnDisconnected
Set or add a callback called afterConnection
has been disconnected.- Parameters:
doOnDisconnected
- a consumer observing disconnected events- Returns:
- a new
ClientTransport
reference
-
doOnResolve
Set or add a callback called beforeSocketAddress
is resolved.- Parameters:
doOnResolve
- a consumer observing resolve events- Returns:
- a new
ClientTransport
reference - Since:
- 1.0.1
-
doAfterResolve
Set or add a callback called afterSocketAddress
is resolved successfully.- Parameters:
doAfterResolve
- a consumer observing resolved events- Returns:
- a new
ClientTransport
reference - Since:
- 1.0.1
-
doOnResolveError
Set or add a callback called if an exception happens while resolving to aSocketAddress
.- Parameters:
doOnResolveError
- a consumer observing resolve error events- Returns:
- a new
ClientTransport
reference - Since:
- 1.0.1
-
host
The host to which this client should connect.- Parameters:
host
- the host to connect to- Returns:
- a new
ClientTransport
reference
-
noProxy
Remove any previously applied Proxy configuration customization.- Returns:
- a new
ClientTransport
reference
-
port
The port to which this client should connect.- Parameters:
port
- the port to connect to- Returns:
- a new
ClientTransport
reference
-
proxy
Apply a proxy configuration.- Parameters:
proxyOptions
- the proxy configuration callback- Returns:
- a new
ClientTransport
reference
-
proxyWithSystemProperties
Set up a proxy from the java system properties. Supports http, https, socks4, socks5 proxies. List of supported system properties https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.htmlIf both
https.proxyHost
andhttp.proxyHost
are set it chooseshttps.proxyHost
overhttp.proxyHost
. Same with the http/https proxy port.If a
ClientTransport
instance already has a proxy set viaproxy(Consumer)
the new instance created by this method has all proxy settings replaced with proxy settings from the system properties only.If the system properties do not have a configuration for a proxy, the new instance returned by this method behaves as if there is no proxy settings, regardless of configuration of the original
ClientTransport
instance.- Returns:
- a new
ClientTransport
reference - Since:
- 1.0.8
-
remoteAddress
The address to which this client should connect on each subscribe.- Parameters:
remoteAddressSupplier
- A supplier of the address to connect to.- Returns:
- a new
ClientTransport
-
resolvedAddressesSelector
public T resolvedAddressesSelector(ClientTransport.ResolvedAddressSelector<? super CONF> resolvedAddressesSelector) Determines the resolved addresses to which this client should connect for each subscription.- Parameters:
resolvedAddressesSelector
- aClientTransport.ResolvedAddressSelector
invoked after resolving the remote address to determine which addresses should be used for the connection.- Returns:
- a new
ClientTransport
- Since:
- 1.2.5
-
resolver
Assign anAddressResolverGroup
.- Parameters:
resolver
- the newAddressResolverGroup
- Returns:
- a new
ClientTransport
reference
-
resolver
Apply a name resolver configuration.- Parameters:
nameResolverSpec
- the name resolver callback- Returns:
- a new
ClientTransport
reference
-
runOn
Description copied from class:Transport
Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.- Overrides:
runOn
in classTransport<T extends ClientTransport<T,
CONF>, CONF extends ClientTransportConfig<CONF>> - 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
-
warmup
Based on the actual configuration, returns aMono
that triggers:- an initialization of the event loop group
- an initialization of the host name resolver
- loads the necessary native libraries for the transport
connect operation
absorbs the extra time needed to initialize and load the resources.- Returns:
- a
Mono
representing the completion of the warmup - Since:
- 1.0.3
-