Skip to content

Commit 262877a

Browse files
committed
Add asynchronous processing methods in PythonProcessor and update dependencies.
1 parent dbf1504 commit 262877a

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

common/python-executor-common/src/main/java/io/maksymuimanov/python/executor/InterpretablePythonExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected InterpretablePythonExecutor(PythonInterpreterFactory<I> interpreterFac
1616

1717
public <R> PythonExecutionResponse<R> execute(PythonScript script, @Nullable Class<? extends R> resultClass) {
1818
try (I interpreter = interpreterFactory.create()) {
19-
return execute(script, resultClass, interpreter);
19+
return this.execute(script, resultClass, interpreter);
2020
} catch (Exception e) {
2121
throw new PythonExecutionException(e);
2222
}

common/python-executor-common/src/main/java/io/maksymuimanov/python/processor/PythonProcessor.java

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import org.jspecify.annotations.Nullable;
99

1010
import java.util.Map;
11+
import java.util.concurrent.CompletableFuture;
12+
import java.util.concurrent.Executor;
13+
import java.util.concurrent.ForkJoinPool;
1114

1215
/**
1316
* Defines the contract for processing and executing Python scripts, acting as a bridge between
@@ -32,12 +35,77 @@
3235
* @since 1.0.0
3336
*/
3437
public interface PythonProcessor {
38+
default CompletableFuture<Void> processAsync(String script) {
39+
return this.processAsync(script, Map.of());
40+
}
41+
42+
default CompletableFuture<Void> processAsync(PythonScript script) {
43+
return this.processAsync(script, Map.of());
44+
}
45+
46+
default CompletableFuture<Void> processAsync(String script, Map<String, Object> arguments) {
47+
return this.processAsync(script, arguments, ForkJoinPool.commonPool());
48+
}
49+
50+
default CompletableFuture<Void> processAsync(PythonScript script, Map<String, Object> arguments) {
51+
return this.processAsync(script, arguments, ForkJoinPool.commonPool());
52+
}
53+
54+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(String script, @Nullable Class<? extends R> resultClass) {
55+
return this.processAsync(script, resultClass, Map.of());
56+
}
57+
58+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(PythonScript script, @Nullable Class<? extends R> resultClass) {
59+
return this.processAsync(script, resultClass, Map.of());
60+
}
61+
62+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(String script, @Nullable Class<? extends R> resultClass, Map<String, Object> arguments) {
63+
return this.processAsync(script, resultClass, arguments, ForkJoinPool.commonPool());
64+
}
65+
66+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(PythonScript script, @Nullable Class<? extends R> resultClass, Map<String, Object> arguments) {
67+
return this.processAsync(script, resultClass, arguments, ForkJoinPool.commonPool());
68+
}
69+
70+
default CompletableFuture<Void> processAsync(String script, Executor executor) {
71+
return this.processAsync(script, Map.of(), executor);
72+
}
73+
74+
default CompletableFuture<Void> processAsync(PythonScript script, Executor executor) {
75+
return this.processAsync(script, Map.of(), executor);
76+
}
77+
78+
default CompletableFuture<Void> processAsync(String script, Map<String, Object> arguments, Executor executor) {
79+
return CompletableFuture.runAsync(() -> this.process(script, arguments), executor);
80+
}
81+
82+
default CompletableFuture<Void> processAsync(PythonScript script, Map<String, Object> arguments, Executor executor) {
83+
return CompletableFuture.runAsync(() -> this.process(script, arguments), executor);
84+
}
85+
86+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(String script, @Nullable Class<? extends R> resultClass, Executor executor) {
87+
return this.processAsync(script, resultClass, Map.of(), executor);
88+
}
89+
90+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(PythonScript script, @Nullable Class<? extends R> resultClass, Executor executor) {
91+
return this.processAsync(script, resultClass, Map.of(), executor);
92+
}
93+
94+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(String script, @Nullable Class<? extends R> resultClass, Map<String, Object> arguments, Executor executor) {
95+
PythonScript pythonScript = new PythonScript(script);
96+
return this.processAsync(pythonScript, resultClass, arguments, executor);
97+
}
98+
99+
default <R> CompletableFuture<PythonExecutionResponse<R>> processAsync(PythonScript script, @Nullable Class<? extends R> resultClass, Map<String, Object> arguments, Executor executor) {
100+
return CompletableFuture.supplyAsync(() -> this.process(script, resultClass, arguments), executor);
101+
}
102+
35103
/**
36104
* Processes and executes a Python script without additional arguments or body mapping.
37105
*
38106
* @param script non-{@code null} Python script to execute
39107
*/
40-
default PythonExecutionResponse<?> process(String script) {
108+
default PythonExecutionResponse<Void> process(String script) {
41109
return this.process(script, null, Map.of());
42110
}
43111

@@ -46,7 +114,7 @@ default PythonExecutionResponse<?> process(String script) {
46114
*
47115
* @param script non-{@code null} Python script to execute
48116
*/
49-
default PythonExecutionResponse<?> process(PythonScript script) {
117+
default PythonExecutionResponse<Void> process(PythonScript script) {
50118
return this.process(script, null, Map.of());
51119
}
52120

@@ -56,7 +124,7 @@ default PythonExecutionResponse<?> process(PythonScript script) {
56124
* @param script non-{@code null} Python script to execute
57125
* @param arguments a map of arguments accessible to resolvers during preprocessing
58126
*/
59-
default PythonExecutionResponse<?> process(String script, Map<String, Object> arguments) {
127+
default PythonExecutionResponse<Void> process(String script, Map<String, Object> arguments) {
60128
return this.process(script, null, arguments);
61129
}
62130

@@ -66,7 +134,7 @@ default PythonExecutionResponse<?> process(String script, Map<String, Object> ar
66134
* @param script non-{@code null} Python script to execute
67135
* @param arguments a map of arguments accessible to resolvers during preprocessing
68136
*/
69-
default PythonExecutionResponse<?> process(PythonScript script, Map<String, Object> arguments) {
137+
default PythonExecutionResponse<Void> process(PythonScript script, Map<String, Object> arguments) {
70138
return this.process(script, null, arguments);
71139
}
72140

core/python-executor-spring-boot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</dependency>
5454
<dependency>
5555
<groupId>io.github.maksymuimanov</groupId>
56-
<artifactId>python-executor-jep-executor-spring-boot-starter</artifactId>
56+
<artifactId>python-executor-graalpy-executor-spring-boot-starter</artifactId>
5757
<version>${project.version}</version>
5858
</dependency>
5959
<dependency>

0 commit comments

Comments
 (0)