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 implementation
CONF - 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>
A generic client Transport that will connect() to a remote address and provide a Connection.
Since:
1.0.0
Author:
Stephane Maldini, Violeta Georgieva
  • Constructor Details

    • ClientTransport

      public ClientTransport()
  • Method Details

    • connect

      protected Mono<? extends Connection> connect()
      Connect the ClientTransport 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 must be done by the user via DisposableChannel.dispose().
      Returns:
      a Mono of Connection
    • connectNow

      protected Connection connectNow()
      Block the ClientTransport and return a Connection. Disposing must be done by the user via DisposableChannel.dispose(). The max connection timeout is 45 seconds.
      Returns:
      a Connection
    • connectNow

      protected Connection connectNow(Duration timeout)
      Block the ClientTransport and return a Connection. Disposing must be done by the user via DisposableChannel.dispose().
      Parameters:
      timeout - connect timeout (resolution: ns)
      Returns:
      a Connection
    • doOnConnect

      public T doOnConnect(Consumer<? super CONF> doOnConnect)
      Set or add a callback called when ClientTransport is about to connect to the remote endpoint.
      Parameters:
      doOnConnect - a consumer observing connect events
      Returns:
      a new ClientTransport reference
    • doOnConnected

      public T doOnConnected(Consumer<? super Connection> doOnConnected)
      Set or add a callback called after Connection has been connected.
      Parameters:
      doOnConnected - a consumer observing connected events
      Returns:
      a new ClientTransport reference
    • doOnDisconnected

      public T doOnDisconnected(Consumer<? super Connection> doOnDisconnected)
      Set or add a callback called after Connection has been disconnected.
      Parameters:
      doOnDisconnected - a consumer observing disconnected events
      Returns:
      a new ClientTransport reference
    • doOnResolve

      public final T doOnResolve(Consumer<? super Connection> doOnResolve)
      Set or add a callback called before SocketAddress is resolved.
      Parameters:
      doOnResolve - a consumer observing resolve events
      Returns:
      a new ClientTransport reference
      Since:
      1.0.1
    • doAfterResolve

      public final T doAfterResolve(BiConsumer<? super Connection,? super SocketAddress> doAfterResolve)
      Set or add a callback called after SocketAddress is resolved successfully.
      Parameters:
      doAfterResolve - a consumer observing resolved events
      Returns:
      a new ClientTransport reference
      Since:
      1.0.1
    • doOnResolveError

      public final T doOnResolveError(BiConsumer<? super Connection,? super Throwable> doOnResolveError)
      Set or add a callback called if an exception happens while resolving to a SocketAddress.
      Parameters:
      doOnResolveError - a consumer observing resolve error events
      Returns:
      a new ClientTransport reference
      Since:
      1.0.1
    • host

      public T host(String host)
      The host to which this client should connect.
      Parameters:
      host - the host to connect to
      Returns:
      a new ClientTransport reference
    • noProxy

      public T noProxy()
      Remove any previously applied Proxy configuration customization.
      Returns:
      a new ClientTransport reference
    • port

      public T port(int port)
      The port to which this client should connect.
      Parameters:
      port - the port to connect to
      Returns:
      a new ClientTransport reference
    • proxy

      public T proxy(Consumer<? super ProxyProvider.TypeSpec> proxyOptions)
      Apply a proxy configuration.
      Parameters:
      proxyOptions - the proxy configuration callback
      Returns:
      a new ClientTransport reference
    • proxyWithSystemProperties

      public final T 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.html

      If both https.proxyHost and http.proxyHost are set it chooses https.proxyHost over http.proxyHost. Same with the http/https proxy port.

      If a ClientTransport instance already has a proxy set via proxy(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

      public T remoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier)
      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 - a ClientTransport.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

      public T resolver(AddressResolverGroup<?> resolver)
      Parameters:
      resolver - the new AddressResolverGroup
      Returns:
      a new ClientTransport reference
    • resolver

      public T resolver(Consumer<NameResolverProvider.NameResolverSpec> nameResolverSpec)
      Apply a name resolver configuration.
      Parameters:
      nameResolverSpec - the name resolver callback
      Returns:
      a new ClientTransport reference
    • runOn

      public T runOn(LoopResources loopResources, boolean preferNative)
      Description copied from class: Transport
      Run IO loops on a supplied EventLoopGroup from the LoopResources container.
      Overrides:
      runOn in class Transport<T extends ClientTransport<T,CONF>,CONF extends ClientTransportConfig<CONF>>
      Parameters:
      loopResources - a new loop resources
      preferNative - should prefer running on epoll, io_uring, kqueue or similar instead of java NIO
      Returns:
      a new Transport reference
    • warmup

      public Mono<Void> warmup()
      Based on the actual configuration, returns a Mono 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, the 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