Class NettyPythonEventLoop
java.lang.Object
io.micronaut.context.python.netty.NettyPythonEventLoop
- All Implemented Interfaces:
PythonEventLoop
Python event loop backed by a Netty
EventLoop.
This class is intentionally a narrow bridge between Python's asyncio transport protocol APIs and Micronaut's Netty event loop. It does not try to expose raw Netty channels to Python callers. The public nested transport/server/facade types are GraalPy host objects whose method names are part of the Python-facing surface, including snake_case names that mirror asyncio. Do not rename those methods to satisfy Java style checks unless the Python shims and tests are updated at the same time.
All callbacks into Python protocols are made from the Netty event loop thread. When this loop is entered from a different Java thread, work is rescheduled onto Netty before touching channel state or invoking Python callbacks.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classNetty-backed datagram transport exposed to Python as a host object.static final classNetty-backed asyncio server exposed to Python as a host object.static final classSocket-like object for Python's server.sockets API.static final classSocket-like facade for transport extras.static final classNetty-backed stream transport exposed to Python as a host object.static final classSSL facade for Python transport extras. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconnectAcceptedSocket(org.graalvm.polyglot.Value protocolFactory, Object socket, @Nullable Object ssl, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Wrap a Netty channel accepted elsewhere as an asyncio TCP transport.createConnection(org.graalvm.polyglot.Value protocolFactory, String host, int port, @Nullable String localHost, int localPort, @Nullable Object ssl, @Nullable String serverHostname, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio TCP connection.createDatagramEndpoint(org.graalvm.polyglot.Value protocolFactory, @Nullable String localHost, int localPort, @Nullable String remoteHost, int remotePort, boolean allowBroadcast, boolean reusePort) Create a Netty-backed asyncio datagram endpoint.createServer(org.graalvm.polyglot.Value protocolFactory, @Nullable String host, int port, int backlog, boolean reuseAddress, boolean reusePort, boolean startServing, @Nullable Object ssl, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio TCP server.createUnixConnection(org.graalvm.polyglot.Value protocolFactory, String path, @Nullable Object ssl, @Nullable String serverHostname, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio Unix-domain socket connection.createUnixServer(org.graalvm.polyglot.Value protocolFactory, String path, int backlog, boolean startServing, @Nullable Object ssl, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio Unix-domain socket server.booleanio.netty.channel.EventLoopReturns the underlying Netty event loop.voidQueue a callback for serialized execution on the loop.inthashCode()booleanUsed to decide whether Python work can run immediately or must be queued.Queue a callback after the requested delay using loop time.doubletime()Returns the monotonic time base exposed to Python's asyncio APIs.
-
Constructor Details
-
NettyPythonEventLoop
public NettyPythonEventLoop(io.netty.channel.EventLoop eventLoop) - Parameters:
eventLoop- The Netty event loop.
-
-
Method Details
-
inEventLoop
public boolean inEventLoop()Description copied from interface:PythonEventLoopUsed to decide whether Python work can run immediately or must be queued.- Specified by:
inEventLoopin interfacePythonEventLoop- Returns:
- Whether the current thread is this event-loop thread.
-
execute
Description copied from interface:PythonEventLoopQueue a callback for serialized execution on the loop.- Specified by:
executein interfacePythonEventLoop- Parameters:
runnable- The callback.
-
schedule
Description copied from interface:PythonEventLoopQueue a callback after the requested delay using loop time.- Specified by:
schedulein interfacePythonEventLoop- Parameters:
runnable- The callback.delay- The delay.unit- The delay unit.- Returns:
- The scheduled future.
-
time
public double time()Description copied from interface:PythonEventLoopReturns the monotonic time base exposed to Python's asyncio APIs.- Specified by:
timein interfacePythonEventLoop- Returns:
- Event-loop time in seconds.
-
equals
-
hashCode
-
eventLoop
public io.netty.channel.EventLoop eventLoop()Returns the underlying Netty event loop.- Returns:
- The underlying Netty event loop.
-
createConnection
public CompletionStage<Object[]> createConnection(org.graalvm.polyglot.Value protocolFactory, String host, int port, @Nullable String localHost, int localPort, @Nullable Object ssl, @Nullable String serverHostname, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio TCP connection.- Parameters:
protocolFactory- The Python protocol factory.host- The remote host.port- The remote port.localHost- The local host, or null.localPort- The local port, or-1.ssl- TLS options.serverHostname- The TLS server hostname.sslHandshakeTimeout- The TLS handshake timeout in seconds.sslShutdownTimeout- The TLS shutdown timeout in seconds.- Returns:
- A stage completing with transport and protocol.
-
createServer
public CompletionStage<NettyPythonEventLoop.NettyServer> createServer(org.graalvm.polyglot.Value protocolFactory, @Nullable String host, int port, int backlog, boolean reuseAddress, boolean reusePort, boolean startServing, @Nullable Object ssl, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio TCP server.- Parameters:
protocolFactory- The Python protocol factory.host- The local host.port- The local port.backlog- The listen backlog.reuseAddress- Whether address reuse is enabled.reusePort- Whether port reuse is requested.startServing- Whether to start accepting connections immediately.ssl- TLS options.sslHandshakeTimeout- The TLS handshake timeout in seconds.sslShutdownTimeout- The TLS shutdown timeout in seconds.- Returns:
- A stage completing with the server.
-
connectAcceptedSocket
public CompletionStage<Object[]> connectAcceptedSocket(org.graalvm.polyglot.Value protocolFactory, Object socket, @Nullable Object ssl, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Wrap a Netty channel accepted elsewhere as an asyncio TCP transport.- Parameters:
protocolFactory- The Python protocol factory.socket- The accepted Netty channel or transport exposing one.ssl- TLS options.sslHandshakeTimeout- The TLS handshake timeout in seconds.sslShutdownTimeout- The TLS shutdown timeout in seconds.- Returns:
- A stage completing with transport and protocol.
-
createUnixConnection
public CompletionStage<Object[]> createUnixConnection(org.graalvm.polyglot.Value protocolFactory, String path, @Nullable Object ssl, @Nullable String serverHostname, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio Unix-domain socket connection.- Parameters:
protocolFactory- The Python protocol factory.path- The Unix-domain socket path.ssl- TLS options.serverHostname- The TLS server hostname.sslHandshakeTimeout- The TLS handshake timeout in seconds.sslShutdownTimeout- The TLS shutdown timeout in seconds.- Returns:
- A stage completing with transport and protocol.
-
createUnixServer
public CompletionStage<NettyPythonEventLoop.NettyServer> createUnixServer(org.graalvm.polyglot.Value protocolFactory, String path, int backlog, boolean startServing, @Nullable Object ssl, @Nullable Double sslHandshakeTimeout, @Nullable Double sslShutdownTimeout) Create a Netty-backed asyncio Unix-domain socket server.- Parameters:
protocolFactory- The Python protocol factory.path- The Unix-domain socket path.backlog- The listen backlog.startServing- Whether to start accepting connections immediately.ssl- TLS options.sslHandshakeTimeout- The TLS handshake timeout in seconds.sslShutdownTimeout- The TLS shutdown timeout in seconds.- Returns:
- A stage completing with the server.
-
createDatagramEndpoint
public CompletionStage<Object[]> createDatagramEndpoint(org.graalvm.polyglot.Value protocolFactory, @Nullable String localHost, int localPort, @Nullable String remoteHost, int remotePort, boolean allowBroadcast, boolean reusePort) Create a Netty-backed asyncio datagram endpoint.- Parameters:
protocolFactory- The Python protocol factory.localHost- The local host, or null.localPort- The local port, or-1.remoteHost- The remote host, or null.remotePort- The remote port, or-1.allowBroadcast- Whether broadcast is enabled.reusePort- Whether port reuse is requested.- Returns:
- A stage completing with transport and protocol.
-