Class NettyPythonEventLoopProvider
java.lang.Object
io.micronaut.context.python.netty.NettyPythonEventLoopProvider
- All Implemented Interfaces:
PythonEventLoopProvider, GracefulShutdownCapable
@Internal
@Singleton
@Requires(property="micronaut.python.asyncio.enabled",
notEquals="false")
public final class NettyPythonEventLoopProvider
extends Object
implements PythonEventLoopProvider, GracefulShutdownCapable
Netty-backed Python event-loop provider.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidRun an operation with a Netty event loop bound as current.static <T, X extends Throwable>
Tbind(io.netty.channel.EventLoop eventLoop, ScopedValue.CallableOp<T, X> operation) Call an operation with a Netty event loop bound as current.current()Compatibility wrapper for callers that prefer Optional.@Nullable NettyPythonEventLoopFast path for code that only needs the active loop instance.Trigger a graceful shutdown.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GracefulShutdownCapable
reportActiveTasks
-
Constructor Details
-
NettyPythonEventLoopProvider
public NettyPythonEventLoopProvider()
-
-
Method Details
-
current
Description copied from interface:PythonEventLoopProviderCompatibility wrapper for callers that prefer Optional.- Specified by:
currentin interfacePythonEventLoopProvider- Returns:
- The current Python event loop, if one is active.
-
currentLoop
Description copied from interface:PythonEventLoopProviderFast path for code that only needs the active loop instance.- Specified by:
currentLoopin interfacePythonEventLoopProvider- Returns:
- The current Python event loop, or null when none is active.
-
shutdownGracefully
Description copied from interface:GracefulShutdownCapableTrigger a graceful shutdown. The returnedCompletionStagewill complete when the shutdown is complete.Note that the completion of the returned future may be user-dependent. If a user does not close their connection, the future may never terminate. Always add a timeout for a hard shutdown.
This method should not throw an exception, nor should the returned stage complete exceptionally. Just log an error instead.
- Specified by:
shutdownGracefullyin interfaceGracefulShutdownCapable- Returns:
- A future that completes when this bean is fully shut down
-
bind
Run an operation with a Netty event loop bound as current.- Parameters:
eventLoop- The Netty event loop.operation- The operation to run.
-
bind
public static <T, X extends Throwable> T bind(io.netty.channel.EventLoop eventLoop, ScopedValue.CallableOp<T, X> operation) throws XCall an operation with a Netty event loop bound as current.- Type Parameters:
T- The operation result type.X- The operation exception type.- Parameters:
eventLoop- The Netty event loop.operation- The operation to call.- Returns:
- The operation result.
- Throws:
X- If the operation fails.
-