Class Transport<T extends Transport<T,C>,C extends TransportConfig>

java.lang.Object
reactor.netty.transport.Transport<T,C>
Type Parameters:
T - Transport implementation
C - Transport Config implementation
Direct Known Subclasses:
ClientTransport, QuicClient, QuicServer, ServerTransport, UdpServer

public abstract class Transport<T extends Transport<T,C>,C extends TransportConfig> extends Object
An immutable transport builder for clients and servers.
Since:
1.0.0
Author:
Stephane Maldini, Violeta Georgieva
  • Constructor Details

    • Transport

      public Transport()
  • Method Details

    • attr

      public <A> T attr(AttributeKey<A> key, @Nullable A value)
      Update the given attribute key or remove it if the value is null.
      Type Parameters:
      A - the attribute type
      Parameters:
      key - the AttributeKey key
      value - the AttributeKey value
      Returns:
      a new Transport reference
    • bindAddress

      public T bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier)
      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

      public T channelGroup(ChannelGroup channelGroup)
      Provide a ChannelGroup to hold all active connected channels.

      Graceful Shutdown:

      When a ChannelGroup is set, calls to DisposableChannel.disposeNow() and DisposableChannel.disposeNow(Duration) not only stop accepting new requests but also additionally wait for all active requests, in the ChannelGroup, to complete, within the given timeout.

      Parameters:
      channelGroup - a ChannelGroup
      Returns:
      a new Transport reference
    • configuration

      public abstract C configuration()
      Return a TransportConfig.
      Returns:
      a TransportConfig
    • doOnChannelInit

      public T doOnChannelInit(ChannelPipelineConfigurer 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

      protected T metrics(boolean enable)
      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 - true enables metrics collection; false disables it
      Returns:
      a new Transport reference
    • metrics

      public T metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder)
      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 - if true enables the metrics on the Transport.
      recorder - a supplier for the ChannelMetricsRecorder
      Returns:
      a new Transport reference
    • observe

      public T observe(ConnectionObserver observer)
      Set or add the given ConnectionObserver to observe the connection state changes.
      Parameters:
      observer - the ConnectionObserver to be set or add
      Returns:
      a new Transport reference
    • option

      public <O> T option(ChannelOption<O> key, @Nullable O value)
      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.
      Type Parameters:
      O - the option type
      Parameters:
      key - the ChannelOption key
      value - the ChannelOption value or null
      Returns:
      a new Transport reference
    • runOn

      public T runOn(EventLoopGroup eventLoopGroup)
      Run IO loops on the given EventLoopGroup.
      Parameters:
      eventLoopGroup - an eventLoopGroup to share
      Returns:
      a new Transport reference
    • runOn

      public T runOn(LoopResources channelResources)
      Run IO loops on a supplied EventLoopGroup from the LoopResources container. Will prefer native (epoll/io_uring/kqueue) implementation if available unless the environment property reactor.netty.native is set to false.
      Parameters:
      channelResources - a LoopResources accepting native runtime expectation and returning an eventLoopGroup
      Returns:
      a new Transport reference
    • runOn

      public T runOn(LoopResources loopResources, boolean preferNative)
      Run IO loops on a supplied EventLoopGroup from the LoopResources container.
      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
    • wiretap

      public T wiretap(boolean enable)
      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 - specifies whether the wire logger configuration will be added to the pipeline
      Returns:
      a new Transport reference
    • wiretap

      public T wiretap(String category)
      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 - the logger category
      Returns:
      a new Transport reference
    • wiretap

      public T wiretap(String category, LogLevel level)
      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 - the logger category
      level - the logger level
      Returns:
      a new Transport reference
    • wiretap

      public final T wiretap(String category, LogLevel level, AdvancedByteBufFormat format)
      Apply a wire logger configuration using the specified category (logger), logger level and ByteBuf format. Depending on the format: When AdvancedByteBufFormat.TEXTUAL is specified, Charset.defaultCharset() will be used.
      Parameters:
      category - the logger category
      level - the logger level
      format - the ByteBuf format
      Returns:
      a new Transport reference
    • 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 of AdvancedByteBufFormat.TEXTUAL and a different charset than Charset.defaultCharset() is required. Depending on the format:
      Parameters:
      category - the logger category
      level - the logger level
      format - the ByteBuf format
      charset - the charset
      Returns:
      a new Transport reference
    • duplicate

      protected abstract T duplicate()
      Return a new Transport inheriting the current configuration. This is a shallow copy.
      Returns:
      a new Transport inheriting the current configuration