Class UdpResources

java.lang.Object
reactor.netty.udp.UdpResources
All Implemented Interfaces:
Disposable, LoopResources

public class UdpResources extends Object implements LoopResources
Hold the default UDP resources.
Author:
Violeta Georgieva
  • Constructor Details

    • UdpResources

      protected UdpResources(LoopResources defaultLoops)
  • Method Details

    • get

      public static UdpResources get()
      Return the global UDP resources for pooling.
      Returns:
      the global UDP resources for pooling
    • reset

      public static UdpResources reset()
      Reset UDP resources to default and return its instance.
      Returns:
      the global UDP resources
    • set

      public static UdpResources set(LoopResources loops)
      Update event loops resources and return the global UDP resources. Note: The previous LoopResources will be disposed.
      Parameters:
      loops - a new LoopResources to replace the current
      Returns:
      the global UDP resources
    • shutdown

      public static void shutdown()
      Shutdown the global UdpResources without resetting them, effectively cleaning up associated resources without creating new ones. This method is NOT blocking. It is implemented as fire-and-forget. Use shutdownLater() when you need to observe the final status of the operation, combined with Mono.block() if you need to synchronously wait for the underlying resources to be disposed.
    • shutdownLater

      public static Mono<Void> shutdownLater()
      Prepare to shutdown the global UdpResources without resetting them, effectively cleaning up associated resources without creating new ones. This only occurs when the returned Mono is subscribed to. The quiet period will be 2s and the timeout will be 15s
      Returns:
      a Mono triggering the shutdown() when subscribed to.
    • shutdownLater

      public static Mono<Void> shutdownLater(Duration quietPeriod, Duration timeout)
      Prepare to shutdown the global UdpResources without resetting them, effectively cleaning up associated resources without creating new ones. This only occurs when the returned Mono is subscribed to. It is guaranteed that the disposal of the underlying LoopResources will not happen before quietPeriod is over. If a task is submitted during the quietPeriod, it is guaranteed to be accepted and the quietPeriod will start over.
      Parameters:
      quietPeriod - the quiet period as described above
      timeout - the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period
      Returns:
      a Mono triggering the shutdown() when subscribed to.
      Since:
      0.9.3
    • daemon

      public boolean daemon()
      Description copied from interface: LoopResources
      return true if EventLoopGroup should not be shutdown.
      Specified by:
      daemon in interface LoopResources
      Returns:
      true if EventLoopGroup should not be shutdown
    • dispose

      public void dispose()
      This has a NOOP implementation by default in order to prevent unintended disposal of the global UDP resources which has a longer lifecycle than regular LoopResources. If a disposal of the global UDP resources is needed, shutdown() should be used instead.
      Specified by:
      dispose in interface Disposable
      Specified by:
      dispose in interface LoopResources
    • disposeLater

      public Mono<Void> disposeLater()
      This has a NOOP implementation by default in order to prevent unintended disposal of the global UDP resources which has a longer lifecycle than regular LoopResources. If a disposal of the global UDP resources is needed, shutdownLater() should be used instead.
      Specified by:
      disposeLater in interface LoopResources
      Returns:
      a Mono representing the completion of the LoopResources disposal.
    • disposeLater

      public Mono<Void> disposeLater(Duration quietPeriod, Duration timeout)
      This has a NOOP implementation by default in order to prevent unintended disposal of the global UDP resources which has a longer lifecycle than regular LoopResources. If a disposal of the global UDP resources is needed, shutdownLater(Duration, Duration) should be used instead.
      Specified by:
      disposeLater in interface LoopResources
      Parameters:
      quietPeriod - the quiet period as described above
      timeout - the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period
      Returns:
      a Mono representing the completion of the LoopResources disposal.
    • isDisposed

      public boolean isDisposed()
      Specified by:
      isDisposed in interface Disposable
    • onChannel

      public <CHANNEL extends Channel> CHANNEL onChannel(Class<CHANNEL> channelType, EventLoopGroup group)
      Description copied from interface: LoopResources
      Callback for a Channel selection.
      Specified by:
      onChannel in interface LoopResources
      Type Parameters:
      CHANNEL - the Channel implementation
      Parameters:
      channelType - the channel type
      group - the source EventLoopGroup to assign a loop from
      Returns:
      a Channel instance
    • onChannelClass

      public <CHANNEL extends Channel> Class<? extends CHANNEL> onChannelClass(Class<CHANNEL> channelType, EventLoopGroup group)
      Description copied from interface: LoopResources
      Callback for a Channel class selection.
      Specified by:
      onChannelClass in interface LoopResources
      Type Parameters:
      CHANNEL - the Channel implementation
      Parameters:
      channelType - the channel type
      group - the source EventLoopGroup to assign a loop from
      Returns:
      a Channel class
    • onClient

      public EventLoopGroup onClient(boolean useNative)
      Description copied from interface: LoopResources
      Callback for client EventLoopGroup creation.
      Specified by:
      onClient in interface LoopResources
      Parameters:
      useNative - should use native group if current environment supports it
      Returns:
      a new EventLoopGroup
    • onServer

      public EventLoopGroup onServer(boolean useNative)
      Description copied from interface: LoopResources
      Callback for server EventLoopGroup creation, this is the EventLoopGroup for the child channel.
      Specified by:
      onServer in interface LoopResources
      Parameters:
      useNative - should use native group if current environment supports it
      Returns:
      a new EventLoopGroup
    • onServerSelect

      public EventLoopGroup onServerSelect(boolean useNative)
      Description copied from interface: LoopResources
      Callback for server select EventLoopGroup creation, this is the EventLoopGroup for the acceptor channel.
      Specified by:
      onServerSelect in interface LoopResources
      Parameters:
      useNative - should use native group if current environment supports it
      Returns:
      a new EventLoopGroup
    • _dispose

      protected void _dispose()
      Dispose underlying resources.
    • _disposeLater

      protected Mono<Void> _disposeLater(Duration quietPeriod, Duration timeout)
      Dispose underlying resources in a listenable fashion. It is guaranteed that the disposal of the underlying LoopResources will not happen before quietPeriod is over. If a task is submitted during the quietPeriod, it is guaranteed to be accepted and the quietPeriod will start over.
      Parameters:
      quietPeriod - the quiet period as described above
      timeout - the maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period
      Returns:
      the Mono that represents the end of disposal
    • getOrCreate

      protected static UdpResources getOrCreate(@Nullable LoopResources loops, Function<LoopResources,UdpResources> onNew, String name)
      Safely check if existing resource exist and proceed to update/cleanup if new resources references are passed.
      Parameters:
      loops - the eventual new LoopResources
      onNew - a UdpResources factory
      name - a name for resources
      Returns:
      an existing or new UdpResources