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 Details

    • NettyPythonEventLoopProvider

      public NettyPythonEventLoopProvider()
  • Method Details

    • current

      public Optional<PythonEventLoop> current()
      Description copied from interface: PythonEventLoopProvider
      Compatibility wrapper for callers that prefer Optional.
      Specified by:
      current in interface PythonEventLoopProvider
      Returns:
      The current Python event loop, if one is active.
    • currentLoop

      public @Nullable NettyPythonEventLoop currentLoop()
      Description copied from interface: PythonEventLoopProvider
      Fast path for code that only needs the active loop instance.
      Specified by:
      currentLoop in interface PythonEventLoopProvider
      Returns:
      The current Python event loop, or null when none is active.
    • shutdownGracefully

      public CompletionStage<?> shutdownGracefully()
      Description copied from interface: GracefulShutdownCapable
      Trigger a graceful shutdown. The returned CompletionStage will 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:
      shutdownGracefully in interface GracefulShutdownCapable
      Returns:
      A future that completes when this bean is fully shut down
    • bind

      public static void bind(io.netty.channel.EventLoop eventLoop, Runnable operation)
      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 X
      Call 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.