Interface LoopResources

All Superinterfaces:
Disposable
All Known Implementing Classes:
HttpResources, QuicResources, TcpResources, UdpResources
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface LoopResources extends Disposable
An EventLoopGroup selector with associated Channel factories.
Since:
0.6
Author:
Stephane Maldini
  • Field Details

    • DEFAULT_IO_WORKER_COUNT

      static final int DEFAULT_IO_WORKER_COUNT
      Default worker thread count, fallback to available processor (but with a minimum value of 4).
    • DEFAULT_IO_SELECT_COUNT

      static final int DEFAULT_IO_SELECT_COUNT
      Default selector thread count, fallback to -1 (no selector thread).
    • DEFAULT_NATIVE

      static final boolean DEFAULT_NATIVE
      Default value whether the native transport (epoll, kqueue) will be preferred, fallback it will be preferred when available.
    • DEFAULT_SHUTDOWN_QUIET_PERIOD

      static final long DEFAULT_SHUTDOWN_QUIET_PERIOD
      Default quiet period that guarantees that the disposal of the underlying LoopResources will not happen, fallback to 2 seconds.
    • DEFAULT_SHUTDOWN_TIMEOUT

      static final long DEFAULT_SHUTDOWN_TIMEOUT
      Default maximum amount of time to wait until the disposal of the underlying LoopResources regardless if a task was submitted during the quiet period, fallback to 15 seconds.
  • Method Details

    • colocate

      static EventLoopGroup colocate(EventLoopGroup group)
      Create a delegating EventLoopGroup which reuse local event loop if already working inside one.
      Parameters:
      group - the EventLoopGroup to decorate
      Returns:
      a decorated EventLoopGroup that will colocate executions on the same thread stack
    • create

      static LoopResources create(String prefix)
      Create a simple LoopResources to provide automatically for EventLoopGroup and Channel factories.
      Parameters:
      prefix - the event loop thread name prefix
      Returns:
      a new LoopResources to provide automatically for EventLoopGroup and Channel factories
    • create

      static LoopResources create(String prefix, int workerCount, boolean daemon)
      Create a simple LoopResources to provide automatically for EventLoopGroup and Channel factories.
      Parameters:
      prefix - the event loop thread name prefix
      workerCount - number of worker threads
      daemon - should the thread be released on jvm shutdown
      Returns:
      a new LoopResources to provide automatically for EventLoopGroup and Channel factories
    • create

      static LoopResources create(String prefix, int selectCount, int workerCount, boolean daemon)
      Create a simple LoopResources to provide automatically for EventLoopGroup and Channel factories.
      Parameters:
      prefix - the event loop thread name prefix
      selectCount - number of selector threads
      workerCount - number of worker threads
      daemon - should the thread be released on jvm shutdown
      Returns:
      a new LoopResources to provide automatically for EventLoopGroup and Channel factories
    • create

      static LoopResources create(String prefix, int selectCount, int workerCount, boolean daemon, boolean colocate)
      Create a simple LoopResources to provide automatically for EventLoopGroup and Channel factories.
      Parameters:
      prefix - the event loop thread name prefix
      selectCount - number of selector threads. When -1 is specified, no selectors threads will be created, and worker threads will be also used as selector threads.
      workerCount - number of worker threads
      daemon - should the thread be released on jvm shutdown
      colocate - true means that EventLoopGroup created for clients will reuse current local event loop if already working inside one.
      Returns:
      a new LoopResources to provide automatically for EventLoopGroup and Channel factories
      Since:
      1.0.28
    • daemon

      default boolean daemon()
      return true if EventLoopGroup should not be shutdown.
      Returns:
      true if EventLoopGroup should not be shutdown
    • dispose

      default void dispose()
      Dispose the underlying LoopResources. This method is NOT blocking. It is implemented as fire-and-forget. Use disposeLater() 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.
      Specified by:
      dispose in interface Disposable
    • disposeLater

      default Mono<Void> disposeLater()
      Returns a Mono that triggers the disposal of the underlying LoopResources when subscribed to. The quiet period will be 2s and the timeout will be 15s
      Returns:
      a Mono representing the completion of the LoopResources disposal.
    • disposeLater

      default Mono<Void> disposeLater(Duration quietPeriod, Duration timeout)
      Returns a Mono that triggers the disposal of the underlying LoopResources when 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 representing the completion of the LoopResources disposal.
      Since:
      0.9.3
    • onChannel

      default <CHANNEL extends Channel> CHANNEL onChannel(Class<CHANNEL> channelType, EventLoopGroup group)
      Callback for a Channel selection.
      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

      default <CHANNEL extends Channel> Class<? extends CHANNEL> onChannelClass(Class<CHANNEL> channelType, EventLoopGroup group)
      Callback for a Channel class selection.
      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

      default EventLoopGroup onClient(boolean useNative)
      Callback for client EventLoopGroup creation.
      Parameters:
      useNative - should use native group if current environment supports it
      Returns:
      a new EventLoopGroup
    • onServer

      EventLoopGroup onServer(boolean useNative)
      Callback for server EventLoopGroup creation, this is the EventLoopGroup for the child channel.
      Parameters:
      useNative - should use native group if current environment supports it
      Returns:
      a new EventLoopGroup
    • onServerSelect

      default EventLoopGroup onServerSelect(boolean useNative)
      Callback for server select EventLoopGroup creation, this is the EventLoopGroup for the acceptor channel.
      Parameters:
      useNative - should use native group if current environment supports it
      Returns:
      a new EventLoopGroup
    • hasNativeSupport

      static boolean hasNativeSupport()
      Return true if environment supports native connections.
      Returns:
      true if environment supports native connections