Class ExecutionContextUtils
java.lang.Object
io.servicetalk.transport.netty.internal.ExecutionContextUtils
Provides utilities around Executors, ExecutionContexts and how they interact with netty Channels.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <ES extends ExecutionStrategy>
ExecutionContext<ES>channelExecutionContext
(io.netty.channel.Channel channel, ExecutionContext<ES> builderExecutionContext) Utility that mapsChannel.eventLoop()
intoIoExecutor
and caches the result for future mappings to reduce allocations.static void
static IoExecutor
fromChannel
(io.netty.channel.Channel channel, boolean isIoThreadSupported) Creates anIoExecutor
around the ChannelEventLoop
.
-
Method Details
-
fromChannel
Creates anIoExecutor
around the ChannelEventLoop
.This method must only be called from inside the
EventLoop
, since for performance reasons it will cache theIoExecutor
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 theIoExecutor
are marked withIoThreadFactory.IoThread
interface.- Returns:
- The (potentially cached)
IoExecutor
wrapped around the ChannelEventLoop
.
-
channelExecutionContext
public static <ES extends ExecutionStrategy> ExecutionContext<ES> channelExecutionContext(io.netty.channel.Channel channel, ExecutionContext<ES> builderExecutionContext) Utility that mapsChannel.eventLoop()
intoIoExecutor
and caches the result for future mappings to reduce allocations. BecauseIoExecutor
implementsListenableAsyncCloseable
interface, its allocation cost is relatively high.- Type Parameters:
ES
- the execution strategy used inside the execution context.- Parameters:
channel
-Channel
registered for a singleEventLoop
threadbuilderExecutionContext
-ExecutionContext
pre-computed by the builder for new connections- Returns:
ExecutionContext
which hasIoExecutor
backed by a singleEventLoop
thread associated with the passedChannel
.
-
clearThreadLocal
public static void clearThreadLocal()
-