Class ExecutionContextUtils

java.lang.Object
io.servicetalk.transport.netty.internal.ExecutionContextUtils

public final class ExecutionContextUtils extends Object
Provides utilities around Executors, ExecutionContexts and how they interact with netty Channels.
  • Method Details

    • fromChannel

      public static IoExecutor fromChannel(io.netty.channel.Channel channel, boolean isIoThreadSupported)
      Creates an IoExecutor around the Channel EventLoop.

      This method must only be called from inside the EventLoop, since for performance reasons it will cache the IoExecutor in a thread local and reuse it if present.

      Parameters:
      channel - the netty channel to pick the event loop from.
      isIoThreadSupported - if threads used by the IoExecutor are marked with IoThreadFactory.IoThread interface.
      Returns:
      The (potentially cached) IoExecutor wrapped around the Channel EventLoop.
    • channelExecutionContext

      public static <ES extends ExecutionStrategy> ExecutionContext<ES> channelExecutionContext(io.netty.channel.Channel channel, ExecutionContext<ES> builderExecutionContext)
      Utility that maps Channel.eventLoop() into IoExecutor and caches the result for future mappings to reduce allocations. Because IoExecutor implements ListenableAsyncCloseable interface, its allocation cost is relatively high.
      Type Parameters:
      ES - the execution strategy used inside the execution context.
      Parameters:
      channel - Channel registered for a single EventLoop thread
      builderExecutionContext - ExecutionContext pre-computed by the builder for new connections
      Returns:
      ExecutionContext which has IoExecutor backed by a single EventLoop thread associated with the passed Channel.
    • clearThreadLocal

      public static void clearThreadLocal()