Class PythonPooledRuntime

java.lang.Object
io.micronaut.context.python.PythonPooledRuntime

@Internal public final class PythonPooledRuntime extends Object
The runtime entry points of a pooled bean that owns its per-context values.

A pooled bean usually needs none of this: the pool caches one instance per context per class, and every bean of that class is interchangeable. A bean needs its own values when it has constructor arguments, because two beans of one class can then hold different dependencies, or when it is AOP-proxied, because a Python proxy belongs to the context it was created in and a pooled bean exists in every context. Either way the values live in a PythonPooledInstance that the generated wrapper holds, and these are the methods the wrapper's generated code calls.

Each one that takes a @Nullable PythonPooledInstance override is the same entry point as its counterpart in PythonContextRuntime plus that holder: when it is absent the call takes the pool's per-class or per-module cache exactly as before, so a pooled type without advice and without arguments is on the path it has always been on.

They all consult PythonContextRuntime.enteredContext() before choosing a context, for the reason given there. PythonPool makes the same check before it borrows, which is what stops a new entry point here from reintroducing the deadlock that came of choosing twice.

Since:
5.2.10
Author:
graemerocher
  • Method Details

    • findPooledClass

      public static org.graalvm.polyglot.Value findPooledClass(@Nullable @Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference)
      A pooled class instance, or the per-context value of a holder that stands in for it.

      A pooled class with no constructor arguments is served from the pool's per-class cache, which is what the holder is null for. A holder appears when the bean is AOP-proxied: the proxy is one Python object per context, created around the class rather than being an instance of it, so it cannot live in that cache and the wrapper carries it instead. Without this the generated bridge would reach the unproxied instance and the advice -- a @Transactional boundary, for one -- would be skipped with nothing said.

      Parameters:
      override - The holder, or null to use the pool's per-class cache
      classReference - The Python class reference
      Returns:
      The value to call
      Since:
      5.2.10
    • findPooledClass

      public static org.graalvm.polyglot.Value findPooledClass(@Nullable @Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference, org.graalvm.polyglot.Context context)
      As findPooledClass(PythonPooledInstance, PythonClassReference), in a context the caller already owns.
      Parameters:
      override - The holder, or null to use the pool's per-class cache
      classReference - The Python class reference
      context - The context
      Returns:
      The value to call
      Since:
      5.2.10
    • invokePooled

      public static org.graalvm.polyglot.Value invokePooled(@Nullable @Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference, String methodName, Object... args)
      Invoke a method on a pooled class, or on the holder standing in for it.
      Parameters:
      override - The holder, or null to use the pool's per-class cache
      classReference - The Python class reference
      methodName - The method name
      args - Arguments
      Returns:
      The polyglot result
      Since:
      5.2.10
    • invokePooledAsync

      public static CompletionStage<?> invokePooledAsync(@Nullable @Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference, String methodName, Object... args)
      Parameters:
      override - The holder, or null to use the pool's per-class cache
      classReference - The Python class reference
      methodName - The method name
      args - Arguments
      Returns:
      The stage of the coroutine
      Since:
      5.2.10
    • invokePooledPublisher

      public static Publisher<?> invokePooledPublisher(@Nullable @Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference, String methodName, Object... args)
      Parameters:
      override - The holder, or null to use the pool's per-class cache
      classReference - The Python class reference
      methodName - The method name
      args - Arguments
      Returns:
      The publisher
      Since:
      5.2.10
    • findPooledInstance

      public static org.graalvm.polyglot.Value findPooledInstance(PythonPooledInstance instance)
      The calling context's instance of a pooled bean that has constructor arguments.

      Chooses the context exactly as

      invalid reference
      #findPooledClass(PythonClassReference)
      does, then asks the bean for its instance there. The instance belongs to the bean rather than to the pool because the pool's cache is keyed by class, and two pooled beans of one class can hold different dependencies.
      Parameters:
      instance - The pooled bean's per-context instances
      Returns:
      The instance for the calling context
      Since:
      5.2.10
    • findPooledInstance

      public static org.graalvm.polyglot.Value findPooledInstance(PythonPooledInstance instance, org.graalvm.polyglot.Context context)
      A pooled bean's instance in a context the caller already owns.
      Parameters:
      instance - The pooled bean's per-context instances
      context - The context
      Returns:
      The instance for that context
      Since:
      5.2.10
    • invokePooledInstance

      public static org.graalvm.polyglot.Value invokePooledInstance(PythonPooledInstance instance, String methodName, Object... args)
      Invoke a method on a pooled bean that has constructor arguments.
      Parameters:
      instance - The pooled bean's per-context instances
      methodName - The method name
      args - Arguments
      Returns:
      The polyglot result
      Since:
      5.2.10
    • invokePooledInstanceAsync

      public static CompletionStage<?> invokePooledInstanceAsync(PythonPooledInstance instance, String methodName, Object... args)
      Invoke an async method on a pooled bean that has constructor arguments, driving the coroutine while the context is still leased; see invokePooledAsync(PythonPooledInstance, PythonContextRuntime.PythonClassReference, String, Object...).
      Parameters:
      instance - The pooled bean's per-context instances
      methodName - The method name
      args - Arguments
      Returns:
      The stage of the coroutine
      Since:
      5.2.10
    • invokePooledInstancePublisher

      public static Publisher<?> invokePooledInstancePublisher(PythonPooledInstance instance, String methodName, Object... args)
      Invoke an async generator method on a pooled bean that has constructor arguments; see invokePooledPublisher(PythonPooledInstance, PythonContextRuntime.PythonClassReference, String, Object...).
      Parameters:
      instance - The pooled bean's per-context instances
      methodName - The method name
      args - Arguments
      Returns:
      The publisher
      Since:
      5.2.10
    • findPooledScript

      public static org.graalvm.polyglot.Value findPooledScript(@Nullable @Nullable PythonPooledInstance override, String packageName, String scriptName)
      A pooled module, or the per-context value of a holder that stands in for it.

      A route module is a pooled type like any other, and an AOP-proxied one carries a holder of one Python proxy per context for the same reason a class does; see findPooledClass(PythonPooledInstance, PythonClassReference).

      Parameters:
      override - The holder, or null to use the pool's per-module cache
      packageName - The Python package
      scriptName - The script/module name
      Returns:
      The value to call
      Since:
      5.2.10
    • findPooledScript

      public static org.graalvm.polyglot.Value findPooledScript(@Nullable @Nullable PythonPooledInstance override, String packageName, String scriptName, org.graalvm.polyglot.Context context)
      As findPooledScript(PythonPooledInstance, String, String), in a context the caller already owns.
      Parameters:
      override - The holder, or null to use the pool's per-module cache
      packageName - The Python package
      scriptName - The script/module name
      context - The context
      Returns:
      The value to call
      Since:
      5.2.10
    • invokePooledScript

      public static org.graalvm.polyglot.Value invokePooledScript(@Nullable @Nullable PythonPooledInstance override, String packageName, String scriptName, String methodName, Object... args)
      Invoke a module function, or the same function on the holder standing in for the module.
      Parameters:
      override - The holder, or null to use the pool's per-module cache
      packageName - The Python package
      scriptName - The script/module name
      methodName - The function name
      args - Arguments
      Returns:
      The polyglot result
      Since:
      5.2.10
    • invokePooledScriptAsync

      public static CompletionStage<?> invokePooledScriptAsync(@Nullable @Nullable PythonPooledInstance override, String packageName, String scriptName, String methodName, Object... args)
      Parameters:
      override - The holder, or null to use the pool's per-module cache
      packageName - The Python package
      scriptName - The script/module name
      methodName - The function name
      args - Arguments
      Returns:
      The stage of the coroutine
      Since:
      5.2.10
    • invokePooledScriptPublisher

      public static Publisher<?> invokePooledScriptPublisher(@Nullable @Nullable PythonPooledInstance override, String packageName, String scriptName, String methodName, Object... args)
      Parameters:
      override - The holder, or null to use the pool's per-module cache
      packageName - The Python package
      scriptName - The script/module name
      methodName - The function name
      args - Arguments
      Returns:
      The publisher
      Since:
      5.2.10