Implementation:Ray project Ray PyActorMethod
| Knowledge Sources | |
|---|---|
| Domains | Distributed_Computing, Java_API |
| Last Updated | 2026-02-13 16:00 GMT |
Overview
Descriptor class representing a method on a Python actor for cross-language invocation provided by the Ray Java API.
Description
PyActorMethod<R> is a generic immutable class that stores the name and return type of a Python actor method for use in cross-language method invocation from Java. It provides static of() factory methods that package the Python method name and optional return type class. Actor information is inferred from the actor handle, so it is not specified in this class.
Usage
Use this class when you need to invoke a method on a Python actor from Java code. It enables type-safe cross-language actor communication by pairing a method name with its expected return type.
Code Reference
Source Location
- Repository: Ray
- File:
java/api/src/main/java/io/ray/api/function/PyActorMethod.java
Signature
public class PyActorMethod<R> {
public final String methodName;
public final Class<R> returnType;
public static PyActorMethod<Object> of(String methodName);
public static <R> PyActorMethod<R> of(String methodName, Class<R> returnType);
}
Import
import io.ray.api.function.PyActorMethod;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| methodName | String |
Yes | The name of the Python actor method to invoke |
| returnType | Class<R> |
No | The expected return type class (defaults to Object.class)
|
Outputs
| Name | Type | Description |
|---|---|---|
| pyActorMethod | PyActorMethod<R> |
An immutable descriptor for the Python actor method |
Usage Examples
// Given a Python actor class:
// @ray.remote
// class A(object):
// def foo(self):
// return "Hello world!"
// Get a handle to the Python actor
PyActorHandle actor = ...; // returned from Ray.createActor or passed from Python
// Call the actor method with a typed return
ObjectRef<String> res = actor.call(PyActorMethod.of("foo", String.class));
String result = res.get();
// Call with default Object return type
ObjectRef<Object> res2 = actor.call(PyActorMethod.of("bar"));