Implementation:Ray project Ray RayCallGenerator
| Knowledge Sources | |
|---|---|
| Domains | Distributed_Computing, Java_Runtime |
| Last Updated | 2026-02-13 16:00 GMT |
Overview
The primary code generator for Ray's Java API that produces RayCall.java, ActorCall.java, PyActorCall.java, and CppActorCall.java with type-safe method overloads for remote function invocation.
Description
RayCallGenerator extends BaseGenerator to produce method overloads for 0 to MAX_PARAMETERS parameters across multiple call types including task callers, void task callers, actor creators, and actor task callers. It generates support for Java, Python, and C++ cross-language calls. Each variant uses the appropriate RayFunc generic interface to provide compile-time type safety for Ray.call(), Ray.createActor(), and actor.call().
Usage
Use RayCallGenerator as a build-time tool to regenerate the core Ray Java API source files. Run its main method to write the generated Java files to the API source directory. This is needed when the maximum parameter count changes, when new cross-language support is added, or when the API template is modified. It is the most critical code generator in the Ray Java project.
Code Reference
Source Location
- Repository: Ray
- File:
java/runtime/src/main/java/io/ray/runtime/util/generator/RayCallGenerator.java
Signature
public class RayCallGenerator extends BaseGenerator {
private String generateRayCallDotJava() { ... }
private String generateActorCallDotJava() { ... }
private String generatePyActorCallDotJava() { ... }
private String generateCppActorCallDotJava() { ... }
private void buildCalls(
int numParameters,
boolean forActor,
boolean forActorCreation,
boolean hasReturn) { ... }
private void buildPyCalls(
int numParameters,
boolean forActor,
boolean forActorCreation) { ... }
private void buildCppCalls(
int numParameters,
boolean forActor,
boolean forActorCreation) { ... }
public static void main(String[] args) throws IOException { ... }
}
Import
import io.ray.runtime.util.generator.RayCallGenerator;
I/O Contract
Input
| Parameter | Type | Description |
|---|---|---|
numParameters |
int |
Number of function parameters to generate overloads for (0 to MAX_PARAMETERS) |
forActor |
boolean |
Whether to generate actor.call style methods (true) or static Ray.call methods (false) |
forActorCreation |
boolean |
Whether to generate actor creation methods (true) or task invocation methods (false) |
hasReturn |
boolean |
Whether to generate methods for functions with a return value |
Output
| Output | Type | Description |
|---|---|---|
RayCall.java |
Generated source file | Type-safe interfaces for Ray.call(), Ray.createActor(), plus Python and C++ cross-language calls
|
ActorCall.java |
Generated source file | Type-safe default interface methods for Java actor task calls |
PyActorCall.java |
Generated source file | Type-safe interface for Python actor method calls |
CppActorCall.java |
Generated source file | Type-safe interface for C++ actor method calls |
Usage Examples
// Run the generator from the command line or build system
// This generates RayCall.java, ActorCall.java, PyActorCall.java, CppActorCall.java
RayCallGenerator.main(new String[]{
"../api/src/main/java/io/ray/api/"
});
// The generated RayCall.java produces methods like:
// public static <T0, T1, R> TaskCaller<R> call(RayFunc2<T0, T1, R> f, T0 t0, T1 t1) {
// Object[] args = new Object[]{t0, t1};
// return new TaskCaller<>(f, args);
// }
// The generated ActorCall.java produces methods like:
// default <T0, R> ActorTaskCaller<R> task(RayFunc2<A, T0, R> f, T0 t0) { ... }
// default <T0> VoidActorTaskCaller task(RayFuncVoid2<A, T0> f, T0 t0) { ... }