Class PythonPooledRuntime
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 Summary
Modifier and TypeMethodDescriptionstatic org.graalvm.polyglot.ValuefindPooledClass(@Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference) A pooled class instance, or the per-context value of a holder that stands in for it.static org.graalvm.polyglot.ValuefindPooledClass(@Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference, org.graalvm.polyglot.Context context) AsfindPooledClass(PythonPooledInstance, PythonClassReference), in a context the caller already owns.static org.graalvm.polyglot.ValuefindPooledInstance(PythonPooledInstance instance) The calling context's instance of a pooled bean that has constructor arguments.static org.graalvm.polyglot.ValuefindPooledInstance(PythonPooledInstance instance, org.graalvm.polyglot.Context context) A pooled bean's instance in a context the caller already owns.static org.graalvm.polyglot.ValuefindPooledScript(@Nullable PythonPooledInstance override, String packageName, String scriptName) A pooled module, or the per-context value of a holder that stands in for it.static org.graalvm.polyglot.ValuefindPooledScript(@Nullable PythonPooledInstance override, String packageName, String scriptName, org.graalvm.polyglot.Context context) AsfindPooledScript(PythonPooledInstance, String, String), in a context the caller already owns.static org.graalvm.polyglot.ValueinvokePooled(@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.static CompletionStage<?> invokePooledAsync(@Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference, String methodName, Object... args) AsinvokePooled(PythonPooledInstance, PythonClassReference, String, Object...), for an async method.static org.graalvm.polyglot.ValueinvokePooledInstance(PythonPooledInstance instance, String methodName, Object... args) Invoke a method on a pooled bean that has constructor arguments.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; seeinvokePooledAsync(PythonPooledInstance, PythonContextRuntime.PythonClassReference, String, Object...).static Publisher<?> invokePooledInstancePublisher(PythonPooledInstance instance, String methodName, Object... args) Invoke an async generator method on a pooled bean that has constructor arguments; seeinvokePooledPublisher(PythonPooledInstance, PythonContextRuntime.PythonClassReference, String, Object...).static Publisher<?> invokePooledPublisher(@Nullable PythonPooledInstance override, PythonContextRuntime.PythonClassReference classReference, String methodName, Object... args) AsinvokePooled(PythonPooledInstance, PythonClassReference, String, Object...), for an async generator method.static org.graalvm.polyglot.ValueinvokePooledScript(@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.static CompletionStage<?> invokePooledScriptAsync(@Nullable PythonPooledInstance override, String packageName, String scriptName, String methodName, Object... args) AsinvokePooledScript(PythonPooledInstance, String, String, String, Object...), for an async function.static Publisher<?> invokePooledScriptPublisher(@Nullable PythonPooledInstance override, String packageName, String scriptName, String methodName, Object... args) AsinvokePooledScript(PythonPooledInstance, String, String, String, Object...), for an async generator function.
-
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
@Transactionalboundary, for one -- would be skipped with nothing said.- Parameters:
override- The holder, ornullto use the pool's per-class cacheclassReference- 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) AsfindPooledClass(PythonPooledInstance, PythonClassReference), in a context the caller already owns.- Parameters:
override- The holder, ornullto use the pool's per-class cacheclassReference- The Python class referencecontext- 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, ornullto use the pool's per-class cacheclassReference- The Python class referencemethodName- The method nameargs- 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) AsinvokePooled(PythonPooledInstance, PythonClassReference, String, Object...), for an async method.- Parameters:
override- The holder, ornullto use the pool's per-class cacheclassReference- The Python class referencemethodName- The method nameargs- 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) AsinvokePooled(PythonPooledInstance, PythonClassReference, String, Object...), for an async generator method.- Parameters:
override- The holder, ornullto use the pool's per-class cacheclassReference- The Python class referencemethodName- The method nameargs- Arguments- Returns:
- The publisher
- Since:
- 5.2.10
-
findPooledInstance
The calling context's instance of a pooled bean that has constructor arguments.Chooses the context exactly as
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.invalid reference
#findPooledClass(PythonClassReference)- 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 instancescontext- 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 instancesmethodName- The method nameargs- 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; seeinvokePooledAsync(PythonPooledInstance, PythonContextRuntime.PythonClassReference, String, Object...).- Parameters:
instance- The pooled bean's per-context instancesmethodName- The method nameargs- 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; seeinvokePooledPublisher(PythonPooledInstance, PythonContextRuntime.PythonClassReference, String, Object...).- Parameters:
instance- The pooled bean's per-context instancesmethodName- The method nameargs- 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, ornullto use the pool's per-module cachepackageName- The Python packagescriptName- 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) AsfindPooledScript(PythonPooledInstance, String, String), in a context the caller already owns.- Parameters:
override- The holder, ornullto use the pool's per-module cachepackageName- The Python packagescriptName- The script/module namecontext- 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, ornullto use the pool's per-module cachepackageName- The Python packagescriptName- The script/module namemethodName- The function nameargs- 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) AsinvokePooledScript(PythonPooledInstance, String, String, String, Object...), for an async function.- Parameters:
override- The holder, ornullto use the pool's per-module cachepackageName- The Python packagescriptName- The script/module namemethodName- The function nameargs- 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) AsinvokePooledScript(PythonPooledInstance, String, String, String, Object...), for an async generator function.- Parameters:
override- The holder, ornullto use the pool's per-module cachepackageName- The Python packagescriptName- The script/module namemethodName- The function nameargs- Arguments- Returns:
- The publisher
- Since:
- 5.2.10
-