Implementation:Ray project Ray Ray Task Cross Language
| Knowledge Sources | |
|---|---|
| Domains | Distributed_Computing, Cross_Language_Interop |
| Last Updated | 2026-02-13 17:00 GMT |
Overview
Concrete tool for submitting tasks to foreign-language workers via function descriptors provided by the Ray Java SDK.
Description
When Ray.task() receives a PyFunction or CppFunction descriptor (instead of a Java method reference), AbstractRayRuntime.call() creates a PyFunctionDescriptor or CppFunctionDescriptor that implements FunctionDescriptor.getLanguage() returning Language.PYTHON or Language.CPP. The Raylet routes the task to the appropriate language worker, which loads the function from the code search path.
The same pattern applies to actors: Ray.actor() with PyActorClass or CppActorClass creates cross-language actor instances.
Usage
Use the same Ray.task() and Ray.actor() APIs with cross-language descriptors instead of Java method references.
Code Reference
Source Location
- Repository: ray-project/ray
- File: java/runtime/src/main/java/io/ray/runtime/AbstractRayRuntime.java (L1-456)
- File: java/runtime/src/main/java/io/ray/runtime/functionmanager/PyFunctionDescriptor.java (L9-55)
- File: java/runtime/src/main/java/io/ray/runtime/functionmanager/CppFunctionDescriptor.java (L9-55)
Signature
// Python function task
Ray.task(PyFunction<R> pyFunction, args...).remote() -> ObjectRef<R>
// C++ function task
Ray.task(CppFunction<R> cppFunction, args...).remote() -> ObjectRef<R>
// Python actor
Ray.actor(PyActorClass pyActorClass, args...).remote() -> PyActorHandle
// C++ actor
Ray.actor(CppActorClass cppActorClass, args...).remote() -> CppActorHandle
Import
import io.ray.api.Ray;
import io.ray.api.ObjectRef;
import io.ray.api.function.PyFunction;
import io.ray.api.function.CppFunction;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| descriptor | PyFunction/CppFunction/PyActorClass/CppActorClass | Yes | Cross-language function/actor descriptor |
| args | Object... | Depends | Arguments (must be MessagePack-compatible for cross-language) |
Outputs
| Name | Type | Description |
|---|---|---|
| result | ObjectRef<R> | Future reference to the cross-language result |
| actorHandle | PyActorHandle/CppActorHandle | Handle for cross-language actors |
Usage Examples
Call Python Function
import io.ray.api.Ray;
import io.ray.api.ObjectRef;
import io.ray.api.function.PyFunction;
System.setProperty("ray.job.code-search-path", "/path/to/python/code");
Ray.init();
// Call Python function
ObjectRef<byte[]> result = Ray.task(
PyFunction.of("my_module", "process_data"),
"input_data"
).remote();
byte[] output = result.get();
Ray.shutdown();
Create Python Actor
import io.ray.api.Ray;
import io.ray.api.PyActorHandle;
import io.ray.api.function.PyActorClass;
import io.ray.api.function.PyFunction;
PyActorHandle actor = Ray.actor(
PyActorClass.of("my_module", "Counter")
).remote();
// Call actor method
ObjectRef<Object> result = actor.task(
PyFunction.of("my_module", "Counter.increment")
).remote();