chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:17:40 +08:00
commit f1825c8ceb
10096 changed files with 2364182 additions and 0 deletions
+521
View File
@@ -0,0 +1,521 @@
load(
"@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl",
"jar_jar",
)
load("@rules_java//java:java_binary.bzl", "java_binary")
load("@rules_java//java:java_import.bzl", "java_import")
load("@rules_java//java:java_library.bzl", "java_library")
load("@rules_java//java:java_test.bzl", "java_test")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
load("@rules_proto_grpc//java:defs.bzl", "java_proto_compile")
load("@rules_python//python:defs.bzl", "py_binary")
load("//bazel:ray.bzl", "define_java_module", "native_java_library")
exports_files([
"testng.xml",
"checkstyle.xml",
"checkstyle-suppressions.xml",
])
all_modules = [
"api",
"runtime",
"serve",
]
all_modules_with_test = all_modules + [
"test",
"performance_test",
]
java_import(
name = "all_modules",
jars = [
"libio_ray_ray_" + module + ".jar"
for module in all_modules
] + [
"libio_ray_ray_" + module + "-src.jar"
for module in all_modules
],
deps = [
":io_ray_ray_" + module
for module in all_modules
],
)
java_import(
name = "all_modules_with_test",
testonly = 1,
jars = [
"libio_ray_ray_" + module + ".jar"
for module in all_modules_with_test
] + [
"libio_ray_ray_" + module + "-src.jar"
for module in all_modules_with_test
] + [
"all_tests_bin_deploy.jar",
"all_tests_bin_deploy-src.jar",
],
deps = [
":io_ray_ray_" + module
for module in all_modules_with_test
] + [
":all_tests",
],
)
define_java_module(
name = "api",
visibility = ["//visibility:public"],
deps = [
"@maven//:com_lmax_disruptor",
"@maven//:com_sun_xml_bind_jaxb_core",
"@maven//:com_sun_xml_bind_jaxb_impl",
"@maven//:javax_activation_activation",
"@maven//:javax_xml_bind_jaxb_api",
"@maven//:org_apache_logging_log4j_log4j_api",
"@maven//:org_apache_logging_log4j_log4j_core",
"@maven//:org_apache_logging_log4j_log4j_slf4j_impl",
"@maven//:org_slf4j_slf4j_api",
],
)
define_java_module(
name = "runtime",
additional_resources = [
":java_native_deps",
],
additional_srcs = [
":all_java_proto",
],
define_test_lib = True,
exclude_srcs = [
"runtime/src/main/java/io/ray/runtime/generated/*.java",
],
test_deps = [
":io_ray_ray_api",
":io_ray_ray_runtime",
"@maven//:commons_io_commons_io",
"@maven//:javax_xml_bind_jaxb_api",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_testng_testng",
],
visibility = ["//visibility:public"],
deps = [
":io_ray_ray_api",
"@maven//:com_fasterxml_jackson_core_jackson_databind",
"@maven//:com_github_java_json_tools_json_schema_validator",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:com_lmax_disruptor",
"@maven//:com_typesafe_config",
"@maven//:commons_io_commons_io",
"@maven//:de_ruedigermoeller_fst",
"@maven//:net_java_dev_jna_jna",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_apache_logging_log4j_log4j_api",
"@maven//:org_apache_logging_log4j_log4j_core",
"@maven//:org_apache_logging_log4j_log4j_slf4j_impl",
"@maven//:org_msgpack_msgpack_core",
"@maven//:org_ow2_asm_asm",
"@maven//:org_slf4j_slf4j_api",
"@maven//:org_testng_testng",
],
)
define_java_module(
name = "test",
# (WangTaoTheTonic)For cpp x-lang tests. See //cpp:cluster_mode_xlang_test.
visibility = ["//cpp:__subpackages__"],
deps = [
":io_ray_ray_api",
":io_ray_ray_runtime",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_lmax_disruptor",
"@maven//:com_sun_xml_bind_jaxb_core",
"@maven//:com_sun_xml_bind_jaxb_impl",
"@maven//:commons_io_commons_io",
"@maven//:javax_xml_bind_jaxb_api",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_apache_logging_log4j_log4j_api",
"@maven//:org_apache_logging_log4j_log4j_core",
"@maven//:org_apache_logging_log4j_log4j_slf4j_impl",
"@maven//:org_slf4j_slf4j_api",
"@maven//:org_testng_testng",
],
)
define_java_module(
name = "performance_test",
deps = [
":io_ray_ray_api",
":io_ray_ray_runtime",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
"@maven//:com_lmax_disruptor",
"@maven//:commons_io_commons_io",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_apache_logging_log4j_log4j_api",
"@maven//:org_apache_logging_log4j_log4j_core",
"@maven//:org_apache_logging_log4j_log4j_slf4j_impl",
"@maven//:org_slf4j_slf4j_api",
],
)
define_java_module(
name = "serve",
additional_srcs = [
":serve_java_proto",
],
define_test_lib = True,
exclude_srcs = [
"serve/src/main/java/io/ray/serve/generated/*.java",
],
test_deps = [
":io_ray_ray_api",
":io_ray_ray_runtime",
":io_ray_ray_serve",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:commons_io_commons_io",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_apache_httpcomponents_client5_httpclient5",
"@maven//:org_apache_httpcomponents_client5_httpclient5_fluent",
"@maven//:org_apache_httpcomponents_core5_httpcore5",
"@maven//:org_slf4j_slf4j_api",
"@maven//:org_testng_testng",
],
visibility = ["//visibility:public"],
deps = [
":io_ray_ray_api",
":io_ray_ray_runtime",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_apache_commons_commons_lang3",
"@maven//:org_apache_httpcomponents_core5_httpcore5",
"@maven//:org_slf4j_slf4j_api",
],
)
java_library(
name = "all_tests_lib",
runtime_deps = [
":io_ray_ray_performance_test",
":io_ray_ray_runtime_test",
":io_ray_ray_serve_test",
":io_ray_ray_test",
],
)
# This is a local java test rule. It needs generated files to be copied into
# the source tree before running. To build and generate ray core (gcs and
# raylet), run `bazelisk run //:gen_ray_pkg` first.
#
# This rule used to depend on local genrules, which are deprecated. Reason
# being that local genrules are build rules and do not capture changes in
# source tree, and hence cannot be cached by bazel remote cache. Using local
# genrule forces bazel to effectively disable caching globally to have a
# correct build.
#
# TODO(ray-ci): covert java tests to non-local, hermetic tests.
java_test(
name = "all_tests",
testonly = True,
args = ["java/testng.xml"],
data = [
"testng.xml",
"//:ray_pkg_zip",
],
main_class = "org.testng.TestNG",
resources = [
"//cpp:counter.so",
"//cpp:plus.so",
],
tags = ["local"],
runtime_deps = [
":all_tests_lib",
],
)
# java_test does not produce a _deploy.jar in Bazel 7+. Use a java_binary
# companion so that all_tests_bin_deploy.jar is available in both Bazel 6 and 7.
java_binary(
name = "all_tests_bin",
testonly = True,
main_class = "org.testng.TestNG",
resources = [
"//cpp:counter.so",
"//cpp:plus.so",
],
runtime_deps = [":all_tests_lib"],
)
# 0. `cp testng_custom_template.xml testng_custom.xml`
# 1. `bazel run //:gen_ray_pkg`
# 2. Specify test class/method in `testng_custom.xml`
# 3. `bazel test //java:custom_test --test_output=streamed`
java_test(
name = "custom_test",
args = ["java/testng_custom.xml"],
data = [
"testng_custom.xml",
"//:ray_pkg_zip",
],
main_class = "org.testng.TestNG",
tags = ["local"],
runtime_deps = [
":all_tests_lib",
],
)
# We'd better make resource files can be accessed from 3rd party library.
# More detail please see https://github.com/ray-project/ray/pull/21641.
java_proto_compile(
name = "common_java_proto",
deps = ["@io_ray//src/ray/protobuf:common_proto"],
)
java_proto_compile(
name = "runtime_env_common_java_proto",
deps = [
"@io_ray//src/ray/protobuf:runtime_env_common_proto",
"@io_ray//src/ray/protobuf/public:runtime_environment_proto",
],
)
java_proto_compile(
name = "gcs_java_proto",
deps = ["@io_ray//src/ray/protobuf:gcs_proto"],
)
java_proto_compile(
name = "serve_java_proto",
deps = ["@io_ray//src/ray/protobuf:serve_proto"],
)
filegroup(
name = "all_java_proto",
srcs = [
":common_java_proto",
":gcs_java_proto",
":runtime_env_common_java_proto",
],
)
native_java_library(
name = "core_worker_library_java",
module_name = "runtime",
native_library_name = "//src/ray/core_worker/lib/java:libcore_worker_library_java.so",
)
filegroup(
name = "java_native_deps",
srcs = [
":core_worker_library_java",
],
)
pkg_files(
name = "api_pom_files",
srcs = ["io_ray_ray_api_pom"],
prefix = "api/",
renames = {
"io_ray_ray_api_pom.xml": "pom.xml",
},
visibility = ["//visibility:private"],
)
pkg_files(
name = "runtime_pom_files",
srcs = ["io_ray_ray_runtime_pom"],
prefix = "runtime/",
renames = {
"io_ray_ray_runtime_pom.xml": "pom.xml",
},
visibility = ["//visibility:private"],
)
pkg_files(
name = "test_pom_files",
srcs = ["io_ray_ray_test_pom"],
prefix = "test/",
renames = {
"io_ray_ray_test_pom.xml": "pom.xml",
},
visibility = ["//visibility:private"],
)
pkg_files(
name = "performance_test_pom_files",
srcs = ["io_ray_ray_performance_test_pom"],
prefix = "performance_test/",
renames = {
"io_ray_ray_performance_test_pom.xml": "pom.xml",
},
visibility = ["//visibility:private"],
)
pkg_files(
name = "serve_pom_files",
srcs = ["io_ray_ray_serve_pom"],
prefix = "serve/",
renames = {
"io_ray_ray_serve_pom.xml": "pom.xml",
},
visibility = ["//visibility:private"],
)
pkg_zip(
name = "pom_files",
srcs = [
":api_pom_files",
":performance_test_pom_files",
":runtime_pom_files",
":serve_pom_files",
":test_pom_files",
],
visibility = ["//visibility:private"],
)
py_binary(
name = "gen_pom_files",
srcs = ["gen_pom_files.py"],
data = [":pom_files.zip"],
visibility = ["//visibility:private"],
deps = ["//bazel:gen_extract"],
)
# Generates the dependencies needed by maven.
genrule(
name = "proto_files",
srcs = [
":all_java_proto",
":serve_java_proto",
],
outs = ["proto_files.zip"],
cmd = """
set -euo pipefail
tmpdir=$$(mktemp -d)
mkdir -p "$$tmpdir/java/runtime/src/main/java/io/ray/runtime/generated"
for f in $(locations :all_java_proto); do
unzip -q "$$f" -x META-INF/MANIFEST.MF -d "$$tmpdir/java/runtime/src/main/java"
done
mkdir -p "$$tmpdir/java/serve/src/main/java/io/ray/serve/generated"
for f in $(locations :serve_java_proto); do
unzip -q "$$f" -x META-INF/MANIFEST.MF -d "$$tmpdir/java/serve/src/main/java"
done
(cd "$$tmpdir/java"; zip -0 -q -r out.zip runtime serve)
mv "$$tmpdir/java/out.zip" $@
rm -rf "$$tmpdir"
""",
visibility = ["//visibility:private"],
)
py_binary(
name = "gen_proto_files",
srcs = ["gen_proto_files.py"],
data = [":proto_files.zip"],
visibility = ["//visibility:private"],
deps = ["//bazel:gen_extract"],
)
pkg_files(
name = "maven_deps_files",
srcs = [
":java_native_deps",
],
attributes = pkg_attributes(mode = "755"),
prefix = select(
{
"@platforms//os:linux": "runtime/native_dependencies/native/linux",
"@platforms//os:macos": "runtime/native_dependencies/native/darwin",
},
no_match_error = "Unsupported platform",
),
visibility = ["//visibility:private"],
)
pkg_zip(
name = "maven_deps",
srcs = [
":maven_deps_files",
],
visibility = ["//visibility:private"],
)
py_binary(
name = "gen_maven_deps",
srcs = ["gen_maven_deps.py"],
data = [":maven_deps.zip"],
visibility = ["//visibility:private"],
deps = ["//bazel:gen_extract"],
)
java_binary(
name = "ray_dist",
# This rule is used to package all Ray Java code and the third-party dependencies into a
# fat jar file. It's not really an executable jar. So we set its `main_class` to empty.
main_class = "",
runtime_deps = [
"//java:io_ray_ray_api",
"//java:io_ray_ray_runtime",
"//java:io_ray_ray_serve",
],
)
jar_jar(
name = "ray_dist_shaded",
input_jar = "//java:ray_dist_deploy.jar",
rules = "//java:shade_rule",
)
# Shade dependencies in tests fat jar.
jar_jar(
name = "all_tests_shaded",
input_jar = "//java:all_tests_bin_deploy.jar",
rules = "//java:shade_rule",
)
pkg_files(
name = "ray_java_pkg_files",
srcs = [
":ray_dist_shaded.jar",
],
prefix = "ray/jars/",
renames = {
"ray_dist_shaded.jar": "ray_dist.jar",
},
)
pkg_zip(
name = "ray_java_pkg_zip",
srcs = [
":ray_java_pkg_files",
],
out = "ray_java_pkg.zip",
visibility = ["//visibility:private"],
)
py_binary(
name = "gen_ray_java_pkg",
srcs = ["gen_ray_java_pkg.py"],
data = [
":ray_java_pkg.zip",
],
visibility = ["//visibility:private"],
deps = [
"//bazel:gen_extract",
],
)
+16
View File
@@ -0,0 +1,16 @@
### Instructions on ray-java test
1. Install necessary executables
- `java` and `javac` is needed to run ray-java tests, and users need to make sure they're accessible in `$PATH`
- You could check whether they're installed by `which java` and `which javac`
- Install `java` with `sudo apt install openjdk-11-jre -y`
- Install `javac` with `sudo apt install openjdk-11-jdk -y`
- java-11 is the version we use on CI
2. Run java test with bazel
```sh
# To run ray tests.
bazel test //java:all_tests --test_output=streamed
# To run custom tests.
bazel test //java:custom_test --test_output=streamed
```
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
{auto_gen_header}
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>io.ray</groupId>
<artifactId>ray-superpom</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ray-api</artifactId>
<name>ray api</name>
<description>java api for ray</description>
<packaging>jar</packaging>
<dependencies>
{generated_bzl_deps}
</dependencies>
</project>
@@ -0,0 +1,655 @@
// Generated by `RayCallGenerator.java`. DO NOT EDIT.
package io.ray.api;
import io.ray.api.call.ActorTaskCaller;
import io.ray.api.call.VoidActorTaskCaller;
import io.ray.api.function.RayFunc1;
import io.ray.api.function.RayFunc2;
import io.ray.api.function.RayFunc3;
import io.ray.api.function.RayFunc4;
import io.ray.api.function.RayFunc5;
import io.ray.api.function.RayFunc6;
import io.ray.api.function.RayFuncVoid1;
import io.ray.api.function.RayFuncVoid2;
import io.ray.api.function.RayFuncVoid3;
import io.ray.api.function.RayFuncVoid4;
import io.ray.api.function.RayFuncVoid5;
import io.ray.api.function.RayFuncVoid6;
/**
* This class provides type-safe interfaces for remote actor calls.
**/
interface ActorCall<A> {
default <R> ActorTaskCaller<R> task(RayFunc1<A, R> f) {
Object[] args = new Object[]{};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default VoidActorTaskCaller task(RayFuncVoid1<A> f) {
Object[] args = new Object[]{};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, R> ActorTaskCaller<R> task(RayFunc2<A, T0, R> f, T0 t0) {
Object[] args = new Object[]{t0};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, R> ActorTaskCaller<R> task(RayFunc2<A, T0, R> f, ObjectRef<T0> t0) {
Object[] args = new Object[]{t0};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0> VoidActorTaskCaller task(RayFuncVoid2<A, T0> f, T0 t0) {
Object[] args = new Object[]{t0};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0> VoidActorTaskCaller task(RayFuncVoid2<A, T0> f, ObjectRef<T0> t0) {
Object[] args = new Object[]{t0};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, R> ActorTaskCaller<R> task(RayFunc3<A, T0, T1, R> f, T0 t0, T1 t1) {
Object[] args = new Object[]{t0, t1};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, R> ActorTaskCaller<R> task(RayFunc3<A, T0, T1, R> f, T0 t0, ObjectRef<T1> t1) {
Object[] args = new Object[]{t0, t1};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, R> ActorTaskCaller<R> task(RayFunc3<A, T0, T1, R> f, ObjectRef<T0> t0, T1 t1) {
Object[] args = new Object[]{t0, t1};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, R> ActorTaskCaller<R> task(RayFunc3<A, T0, T1, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1) {
Object[] args = new Object[]{t0, t1};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1> VoidActorTaskCaller task(RayFuncVoid3<A, T0, T1> f, T0 t0, T1 t1) {
Object[] args = new Object[]{t0, t1};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1> VoidActorTaskCaller task(RayFuncVoid3<A, T0, T1> f, T0 t0, ObjectRef<T1> t1) {
Object[] args = new Object[]{t0, t1};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1> VoidActorTaskCaller task(RayFuncVoid3<A, T0, T1> f, ObjectRef<T0> t0, T1 t1) {
Object[] args = new Object[]{t0, t1};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1> VoidActorTaskCaller task(RayFuncVoid3<A, T0, T1> f, ObjectRef<T0> t0, ObjectRef<T1> t1) {
Object[] args = new Object[]{t0, t1};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, T0 t0, T1 t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, T0 t0, T1 t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, T0 t0, ObjectRef<T1> t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, ObjectRef<T0> t0, T1 t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, R> ActorTaskCaller<R> task(RayFunc4<A, T0, T1, T2, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, T0 t0, T1 t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, T0 t0, T1 t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, T0 t0, ObjectRef<T1> t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, ObjectRef<T0> t0, T1 t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2> VoidActorTaskCaller task(RayFuncVoid4<A, T0, T1, T2> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2) {
Object[] args = new Object[]{t0, t1, t2};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, T1 t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, T1 t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, T1 t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, ObjectRef<T1> t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, T1 t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, T1 t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, R> ActorTaskCaller<R> task(RayFunc5<A, T0, T1, T2, T3, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, T1 t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, T1 t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, T1 t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, ObjectRef<T1> t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, T1 t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, T1 t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3> VoidActorTaskCaller task(RayFuncVoid5<A, T0, T1, T2, T3> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3) {
Object[] args = new Object[]{t0, t1, t2, t3};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4, R> ActorTaskCaller<R> task(RayFunc6<A, T0, T1, T2, T3, T4, R> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new ActorTaskCaller<>((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, T0 t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, T1 t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, T2 t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, T3 t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, T4 t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
default <T0, T1, T2, T3, T4> VoidActorTaskCaller task(RayFuncVoid6<A, T0, T1, T2, T3, T4> f, ObjectRef<T0> t0, ObjectRef<T1> t1, ObjectRef<T2> t2, ObjectRef<T3> t3, ObjectRef<T4> t4) {
Object[] args = new Object[]{t0, t1, t2, t3, t4};
return new VoidActorTaskCaller((ActorHandle) this, f, args);
}
}
@@ -0,0 +1,28 @@
package io.ray.api;
/**
* A handle to a Java actor.
*
* <p>A handle can be used to invoke a remote actor method, with the {@code "call"} method. For
* example:
*
* <pre>{@code
* class MyActor {
* public int echo(int x) {
* return x;
* }
* }
* // Create an actor, and get a handle.
* ActorHandle<MyActor> myActor = Ray.actor(MyActor::new).remote();
* // Call the `echo` method remotely.
* ObjectRef<Integer> result = myActor.task(MyActor::echo, 1).remote();
* // Get the result of the remote `echo` method.
* Assert.assertEqual(result.get(), 1);
* }</pre>
*
* <p>Note, the {@code "call"} method is defined in {@link ActorCall} interface, with multiple
* overloaded versions.
*
* @param <A> The type of the concrete actor class.
*/
public interface ActorHandle<A> extends BaseActorHandle, ActorCall<A> {}
@@ -0,0 +1,33 @@
package io.ray.api;
import io.ray.api.id.ActorId;
/**
* A handle to an actor.
*
* <p>A handle can be used to invoke a remote actor method.
*/
public interface BaseActorHandle {
/** Returns the id of this actor. */
ActorId getId();
/**
* Kill the actor immediately. This will cause any outstanding tasks submitted to the actor to
* fail and the actor to exit in the same way as if it crashed. The killed actor will not be
* restarted anymore.
*/
default void kill() {
Ray.internal().killActor(this, true);
}
/**
* Kill the actor immediately. This will cause any outstanding tasks submitted to the actor to
* fail and the actor to exit in the same way as if it crashed.
*
* @param noRestart If set to true, the killed actor will not be restarted anymore.
*/
default void kill(boolean noRestart) {
Ray.internal().killActor(this, noRestart);
}
}
@@ -0,0 +1,49 @@
// Generated by `RayCallGenerator.java`. DO NOT EDIT.
package io.ray.api;
import io.ray.api.call.CppActorTaskCaller;
import io.ray.api.function.CppActorMethod;
/** This class provides type-safe interfaces for remote actor calls. */
interface CppActorCall {
default <R> CppActorTaskCaller<R> task(CppActorMethod<R> cppActorMethod) {
Object[] args = new Object[] {};
return new CppActorTaskCaller<>((CppActorHandle) this, cppActorMethod, args);
}
default <R> CppActorTaskCaller<R> task(CppActorMethod<R> cppActorMethod, Object obj0) {
Object[] args = new Object[] {obj0};
return new CppActorTaskCaller<>((CppActorHandle) this, cppActorMethod, args);
}
default <R> CppActorTaskCaller<R> task(
CppActorMethod<R> cppActorMethod, Object obj0, Object obj1) {
Object[] args = new Object[] {obj0, obj1};
return new CppActorTaskCaller<>((CppActorHandle) this, cppActorMethod, args);
}
default <R> CppActorTaskCaller<R> task(
CppActorMethod<R> cppActorMethod, Object obj0, Object obj1, Object obj2) {
Object[] args = new Object[] {obj0, obj1, obj2};
return new CppActorTaskCaller<>((CppActorHandle) this, cppActorMethod, args);
}
default <R> CppActorTaskCaller<R> task(
CppActorMethod<R> cppActorMethod, Object obj0, Object obj1, Object obj2, Object obj3) {
Object[] args = new Object[] {obj0, obj1, obj2, obj3};
return new CppActorTaskCaller<>((CppActorHandle) this, cppActorMethod, args);
}
default <R> CppActorTaskCaller<R> task(
CppActorMethod<R> cppActorMethod,
Object obj0,
Object obj1,
Object obj2,
Object obj3,
Object obj4) {
Object[] args = new Object[] {obj0, obj1, obj2, obj3, obj4};
return new CppActorTaskCaller<>((CppActorHandle) this, cppActorMethod, args);
}
}
@@ -0,0 +1,24 @@
package io.ray.api;
/**
* Represents a reference to an object in the object store.
*
* @param <T> The object type.
*/
public interface ObjectRef<T> {
/**
* Fetch the object from the object store, this method will block until the object is locally
* available.
*/
T get();
/**
* Fetch the object from the object store, this method will block until the object is locally
* available.
*
* @param timeoutMs The maximum amount of time in milliseconds to wait before returning.
* @throws RayTimeoutException If it's timeout to get the object.
*/
T get(long timeoutMs);
}
@@ -0,0 +1,72 @@
package io.ray.api;
import io.ray.api.id.PlacementGroupId;
import io.ray.api.options.PlacementGroupCreationOptions;
import io.ray.api.placementgroup.PlacementGroup;
import java.util.List;
/** This class contains all public APIs of Placement Group. */
public class PlacementGroups {
/**
* Create a placement group. A placement group is used to place actors according to a specific
* strategy and resource constraints. It will sends a request to GCS to preallocate the specified
* resources, which is asynchronous. If the specified resource cannot be allocated, it will wait
* for the resource to be updated and rescheduled.
*
* @param creationOptions Creation options of the placement group.
* @return A handle to the created placement group.
*/
public static PlacementGroup createPlacementGroup(PlacementGroupCreationOptions creationOptions) {
return Ray.internal().createPlacementGroup(creationOptions);
}
/**
* Get a placement group by placement group Id.
*
* @param id placement group id.
* @return The placement group.
*/
public static PlacementGroup getPlacementGroup(PlacementGroupId id) {
return Ray.internal().getPlacementGroup(id);
}
/**
* Get a placement group by placement group name from the current namespace.
*
* @param name The placement group name.
* @return The placement group.
*/
public static PlacementGroup getPlacementGroup(String name) {
return Ray.internal().getPlacementGroup(name, null);
}
/**
* Get a placement group by placement group name from the given namespace.
*
* @param name The placement group name.
* @param namespace The namespace of the placement group.
* @return The placement group.
*/
public static PlacementGroup getPlacementGroup(String name, String namespace) {
return Ray.internal().getPlacementGroup(name, namespace);
}
/**
* Get all placement groups in this cluster.
*
* @return All placement groups.
*/
public static List<PlacementGroup> getAllPlacementGroups() {
return Ray.internal().getAllPlacementGroups();
}
/**
* Remove a placement group by id. Throw RayException if remove failed.
*
* @param id Id of the placement group.
*/
public static void removePlacementGroup(PlacementGroupId id) {
Ray.internal().removePlacementGroup(id);
}
}
@@ -0,0 +1,43 @@
// Generated by `RayCallGenerator.java`. DO NOT EDIT.
package io.ray.api;
import io.ray.api.call.PyActorTaskCaller;
import io.ray.api.function.PyActorMethod;
/**
* This class provides type-safe interfaces for remote actor calls.
**/
interface PyActorCall {
default <R> PyActorTaskCaller<R> task(PyActorMethod<R> pyActorMethod) {
Object[] args = new Object[]{};
return new PyActorTaskCaller<>((PyActorHandle)this, pyActorMethod, args);
}
default <R> PyActorTaskCaller<R> task(PyActorMethod<R> pyActorMethod, Object obj0) {
Object[] args = new Object[]{obj0};
return new PyActorTaskCaller<>((PyActorHandle)this, pyActorMethod, args);
}
default <R> PyActorTaskCaller<R> task(PyActorMethod<R> pyActorMethod, Object obj0, Object obj1) {
Object[] args = new Object[]{obj0, obj1};
return new PyActorTaskCaller<>((PyActorHandle)this, pyActorMethod, args);
}
default <R> PyActorTaskCaller<R> task(PyActorMethod<R> pyActorMethod, Object obj0, Object obj1, Object obj2) {
Object[] args = new Object[]{obj0, obj1, obj2};
return new PyActorTaskCaller<>((PyActorHandle)this, pyActorMethod, args);
}
default <R> PyActorTaskCaller<R> task(PyActorMethod<R> pyActorMethod, Object obj0, Object obj1, Object obj2, Object obj3) {
Object[] args = new Object[]{obj0, obj1, obj2, obj3};
return new PyActorTaskCaller<>((PyActorHandle)this, pyActorMethod, args);
}
default <R> PyActorTaskCaller<R> task(PyActorMethod<R> pyActorMethod, Object obj0, Object obj1, Object obj2, Object obj3, Object obj4) {
Object[] args = new Object[]{obj0, obj1, obj2, obj3, obj4};
return new PyActorTaskCaller<>((PyActorHandle)this, pyActorMethod, args);
}
}
@@ -0,0 +1,11 @@
package io.ray.api;
/** Handle of a Python actor. */
public interface PyActorHandle extends BaseActorHandle, PyActorCall {
/** Returns the module name of the Python actor class. */
String getModuleName();
/** Returns the name of the Python actor class. */
String getClassName();
}
+217
View File
@@ -0,0 +1,217 @@
package io.ray.api;
import io.ray.api.runtime.RayRuntime;
import io.ray.api.runtime.RayRuntimeFactory;
import io.ray.api.runtimecontext.RuntimeContext;
import java.util.List;
import java.util.Optional;
/** This class contains all public APIs of Ray. */
public final class Ray extends RayCall {
private static RayRuntime runtime = null;
/** Initialize Ray runtime with the default runtime implementation. */
public static void init() {
try {
Class clz = Class.forName("io.ray.runtime.DefaultRayRuntimeFactory");
RayRuntimeFactory factory = (RayRuntimeFactory) clz.newInstance();
init(factory);
} catch (Exception e) {
throw new RuntimeException("Failed to initialize Ray runtime.", e);
}
}
/**
* Initialize Ray runtime with a custom runtime implementation.
*
* @param factory A factory that produces the runtime instance.
*/
private static synchronized void init(RayRuntimeFactory factory) {
if (runtime == null) {
runtime = factory.createRayRuntime();
Runtime.getRuntime().addShutdownHook(new Thread(Ray::shutdown));
}
}
/** Shutdown Ray runtime. */
public static synchronized void shutdown() {
if (runtime != null) {
internal().shutdown();
runtime = null;
}
}
/**
* Check if {@link #init} has been called yet.
*
* @return True if {@link #init} has already been called and false otherwise.
*/
public static boolean isInitialized() {
return runtime != null;
}
/**
* Store an object in the object store.
*
* @param obj The Java object to be stored.
* @return A ObjectRef instance that represents the in-store object.
*/
public static <T> ObjectRef<T> put(T obj) {
return internal().put(obj);
}
/**
* Get an object by `ObjectRef` from the object store.
*
* @param objectRef The reference of the object to get.
* @param timeoutMs The maximum amount of time in milliseconds to wait before returning.
* @return The Java object.
* @throws RayTimeoutException If it's timeout to get the object.
*/
public static <T> T get(ObjectRef<T> objectRef, long timeoutMs) {
return internal().get(objectRef, timeoutMs);
}
/**
* Get an object by `ObjectRef` from the object store.
*
* @param objectRef The reference of the object to get.
* @return The Java object.
*/
public static <T> T get(ObjectRef<T> objectRef) {
return internal().get(objectRef);
}
/**
* Get a list of objects by `ObjectRef`s from the object store.
*
* @param objectList A list of object references.
* @param timeoutMs The maximum amount of time in milliseconds to wait before returning.
* @return A list of Java objects.
* @throws RayTimeoutException If it's timeout to get the object.
*/
public static <T> List<T> get(List<ObjectRef<T>> objectList, long timeoutMs) {
return internal().get(objectList, timeoutMs);
}
/**
* Get a list of objects by `ObjectRef`s from the object store.
*
* @param objectList A list of object references.
* @return A list of Java objects.
*/
public static <T> List<T> get(List<ObjectRef<T>> objectList) {
return internal().get(objectList);
}
/**
* Wait for a list of RayObjects to be available, until specified number of objects are ready, or
* specified timeout has passed.
*
* @param waitList A list of object references to wait for.
* @param numReturns The number of objects that should be returned.
* @param timeoutMs The maximum time in milliseconds to wait before returning.
* @param fetchLocal If true, wait for the object to be downloaded onto the local node before
* returning it as ready. If false, ray.wait() will not trigger fetching of objects to the
* local node and will return immediately once the object is available anywhere in the
* cluster.
* @return Two lists, one containing locally available objects, one containing the rest.
*/
public static <T> WaitResult<T> wait(
List<ObjectRef<T>> waitList, int numReturns, int timeoutMs, boolean fetchLocal) {
return internal().wait(waitList, numReturns, timeoutMs, fetchLocal);
}
/**
* Wait for a list of RayObjects to be locally available, until specified number of objects are
* ready, or specified timeout has passed.
*
* @param waitList A list of object references to wait for.
* @param numReturns The number of objects that should be returned.
* @param timeoutMs The maximum time in milliseconds to wait before returning.
* @return Two lists, one containing locally available objects, one containing the rest.
*/
public static <T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns, int timeoutMs) {
return wait(waitList, numReturns, timeoutMs, true);
}
/**
* Wait for a list of RayObjects to be locally available, until specified number of objects are
* ready.
*
* @param waitList A list of object references to wait for.
* @param numReturns The number of objects that should be returned.
* @return Two lists, one containing locally available objects, one containing the rest.
*/
public static <T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns) {
return wait(waitList, numReturns, Integer.MAX_VALUE);
}
/**
* Wait for a list of RayObjects to be locally available.
*
* @param waitList A list of object references to wait for.
* @return Two lists, one containing locally available objects, one containing the rest.
*/
public static <T> WaitResult<T> wait(List<ObjectRef<T>> waitList) {
return wait(waitList, waitList.size());
}
/**
* Get a handle to a named actor in current namespace.
*
* <p>Gets a handle to a named actor with the given name of current namespace. The actor must have
* been created with name specified.
*
* @param name The name of the named actor.
* @return an ActorHandle to the actor if the actor of specified name exists in current namespace
* or an Optional.empty()
* @throws RayException An exception is raised if timed out.
*/
public static <T extends BaseActorHandle> Optional<T> getActor(String name) {
return internal().getActor(name, null);
}
/**
* Get a handle to a named actor in the given namespace.
*
* <p>Gets a handle to a named actor with the given name of the given namespace. The actor must
* have been created with name specified.
*
* @param name The name of the named actor.
* @param namespace The namespace of the actor.
* @return an ActorHandle to the actor if the actor of specified name exists in current namespace
* or an Optional.empty()
* @throws RayException An exception is raised if timed out.
*/
public static <T extends BaseActorHandle> Optional<T> getActor(String name, String namespace) {
return internal().getActor(name, namespace);
}
/** Get the underlying runtime instance. */
public static RayRuntime internal() {
if (runtime == null) {
throw new IllegalStateException(
"Ray has not been started yet. You can start Ray with 'Ray.init()'");
}
return runtime;
}
/** Get the runtime context. */
public static RuntimeContext getRuntimeContext() {
return internal().getRuntimeContext();
}
/**
* Intentionally exit the current actor.
*
* <p>This method is used to disconnect an actor and exit the worker.
*
* @throws RuntimeException An exception is raised if this is a driver or this worker is not an
* actor.
*/
public static void exitActor() {
runtime.exitActor();
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,28 @@
package io.ray.api;
import java.util.List;
/**
* Represents the result of a Ray.wait call. It contains 2 lists, one containing the locally
* available objects, one containing the rest.
*/
public final class WaitResult<T> {
private final List<ObjectRef<T>> ready;
private final List<ObjectRef<T>> unready;
public WaitResult(List<ObjectRef<T>> ready, List<ObjectRef<T>> unready) {
this.ready = ready;
this.unready = unready;
}
/** Get the list of ready objects. */
public List<ObjectRef<T>> getReady() {
return ready;
}
/** Get the list of unready objects. */
public List<ObjectRef<T>> getUnready() {
return unready;
}
}
@@ -0,0 +1,63 @@
package io.ray.api.call;
import io.ray.api.ActorHandle;
import io.ray.api.Ray;
import io.ray.api.concurrencygroup.ConcurrencyGroup;
import io.ray.api.function.RayFuncR;
import io.ray.api.runtimeenv.RuntimeEnv;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* A helper to create java actor.
*
* @param <A> The type of the concrete actor class.
*/
public class ActorCreator<A> extends BaseActorCreator<ActorCreator<A>> {
private final RayFuncR<A> func;
private final Object[] args;
public ActorCreator(RayFuncR<A> func, Object[] args) {
this.func = func;
this.args = args;
/// Handle statically defined concurrency groups.
builder.setConcurrencyGroups(Ray.internal().extractConcurrencyGroups(this.func));
}
/**
* Set the JVM options for the Java worker that this actor is running in.
*
* <p>Note, if this is set, this actor won't share Java worker with other actors or tasks.
*
* @param jvmOptions JVM options for the Java worker that this actor is running in.
* @return self
* @see io.ray.api.options.ActorCreationOptions.Builder#setJvmOptions(List)
*/
public ActorCreator<A> setJvmOptions(List<String> jvmOptions) {
builder.setJvmOptions(jvmOptions);
return this;
}
/**
* Create a java actor remotely and return a handle to the created actor.
*
* @return a handle to the created java actor.
*/
public ActorHandle<A> remote() {
return Ray.internal().createActor(func, args, buildOptions());
}
/** Set the concurrency groups for this actor to declare how to perform tasks concurrently. */
public ActorCreator<A> setConcurrencyGroups(ConcurrencyGroup... groups) {
ArrayList<ConcurrencyGroup> list = new ArrayList<>();
Collections.addAll(list, groups);
builder.setConcurrencyGroups(list);
return this;
}
public ActorCreator<A> setRuntimeEnv(RuntimeEnv runtimeEnv) {
builder.setRuntimeEnv(runtimeEnv);
return this;
}
}
@@ -0,0 +1,45 @@
package io.ray.api.call;
import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncR;
import io.ray.api.options.CallOptions;
/**
* A helper to call java actor method.
*
* @param <R> The type of the java actor method return value
*/
public class ActorTaskCaller<R> {
private final ActorHandle actor;
private final RayFuncR<R> func;
private final Object[] args;
private CallOptions.Builder builder = new CallOptions.Builder();
public ActorTaskCaller(ActorHandle actor, RayFuncR<R> func, Object[] args) {
this.actor = actor;
this.func = func;
this.args = args;
}
public ActorTaskCaller<R> setConcurrencyGroup(String name) {
builder.setConcurrencyGroupName(name);
return self();
}
private ActorTaskCaller<R> self() {
return this;
}
/**
* Execute an java actor method remotely and return an object reference to the result object in
* the object store.
*
* @return an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().callActor(actor, func, args, builder.build());
}
}
@@ -0,0 +1,163 @@
package io.ray.api.call;
import io.ray.api.options.ActorCreationOptions;
import io.ray.api.options.ActorLifetime;
import io.ray.api.placementgroup.PlacementGroup;
import java.util.Map;
/**
* Base helper to create actor.
*
* @param <T> The type of the concrete actor creator
*/
public class BaseActorCreator<T extends BaseActorCreator> {
protected ActorCreationOptions.Builder builder = new ActorCreationOptions.Builder();
/**
* Set the actor name of a named actor.
*
* @param name The name of the named actor.
* @return self
* @see io.ray.api.options.ActorCreationOptions.Builder#setName(String)
*/
public T setName(String name) {
builder.setName(name);
return self();
}
/**
* Set the actor name along with a different namespace.
*
* @param name The name of the named actor.
* @param namespace The namespace that this actor will live in.
* @return self
*/
public T setName(String name, String namespace) {
builder.setName(name);
builder.setNamespace(namespace);
return self();
}
public T setLifetime(ActorLifetime lifetime) {
builder.setLifetime(lifetime);
return self();
}
/**
* Set a custom resource requirement to reserve for the lifetime of this actor. This method can be
* called multiple times. If the same resource is set multiple times, the latest quantity will be
* used.
*
* @param resourceName resource name
* @param resourceQuantity resource quantity
* @return self
* @see ActorCreationOptions.Builder#setResource(java.lang.String, java.lang.Double)
*/
public T setResource(String resourceName, Double resourceQuantity) {
builder.setResource(resourceName, resourceQuantity);
return self();
}
/**
* Set custom resource requirements to reserve for the lifetime of this actor. This method can be
* called multiple times. If the same resource is set multiple times, the latest quantity will be
* used.
*
* @param resources requirements for multiple resources.
* @return self
* @see BaseActorCreator#setResources(java.util.Map)
*/
public T setResources(Map<String, Double> resources) {
builder.setResources(resources);
return self();
}
/**
* This specifies the maximum number of times that the actor should be restarted when it dies
* unexpectedly. The minimum valid value is 0 (default), which indicates that the actor doesn't
* need to be restarted. A value of -1 indicates that an actor should be restarted indefinitely.
*
* @param maxRestarts max number of actor restarts
* @return self
* @see ActorCreationOptions.Builder#setMaxRestarts(int)
*/
public T setMaxRestarts(int maxRestarts) {
builder.setMaxRestarts(maxRestarts);
return self();
}
/**
* This specifies the maximum number of times that an actor task can be retried. The minimum valid
* value is 0 (default), which indicates that the actor task can't be retried. A value of -1
* indicates that an actor task can be retried indefinitely.
*
* @param maxTaskRetries max number of actor task retries
* @return self
* @see ActorCreationOptions.Builder#setMaxTaskRetries(int)
*/
public T setMaxTaskRetries(int maxTaskRetries) {
builder.setMaxTaskRetries(maxTaskRetries);
return self();
}
/**
* Set the max number of concurrent calls to allow for this actor.
*
* <p>The maximum concurrency defaults to 1 for threaded execution. Note that the execution order
* is not guaranteed when {@code max_concurrency > 1}.
*
* @param maxConcurrency The maximum number of concurrent calls to allow for this actor.
* @return self
* @see ActorCreationOptions.Builder#setMaxConcurrency(int)
*/
public T setMaxConcurrency(int maxConcurrency) {
builder.setMaxConcurrency(maxConcurrency);
return self();
}
/**
* Set the max number of pending calls allowed on the actor handle. When this value is exceeded,
* ray.exceptions.PendingCallsLimitExceededException will be thrown for further tasks. Note that
* this limit is counted per handle. -1 means that the number of pending calls is unlimited.
*
* @param maxPendingCalls The maximum number of pending calls for this actor.
* @return self
*/
public T setMaxPendingCalls(int maxPendingCalls) {
builder.setMaxPendingCalls(maxPendingCalls);
return self();
}
/**
* Set the placement group to place this actor in.
*
* @param group The placement group of the actor.
* @param bundleIndex The index of the bundle to place this actor in.
* @return self
* @see ActorCreationOptions.Builder#setPlacementGroup(PlacementGroup, int)
*/
public T setPlacementGroup(PlacementGroup group, int bundleIndex) {
builder.setPlacementGroup(group, bundleIndex);
return self();
}
/**
* Set the placement group to place this actor in, which may use any available bundle.
*
* @param group The placement group of the actor.
* @return self
* @see ActorCreationOptions.Builder#setPlacementGroup(PlacementGroup, int)
*/
public T setPlacementGroup(PlacementGroup group) {
return setPlacementGroup(group, -1);
}
@SuppressWarnings("unchecked")
private T self() {
return (T) this;
}
protected ActorCreationOptions buildOptions() {
return builder.build();
}
}
@@ -0,0 +1,98 @@
package io.ray.api.call;
import io.ray.api.options.CallOptions;
import io.ray.api.placementgroup.PlacementGroup;
import io.ray.api.runtimeenv.RuntimeEnv;
import java.util.Map;
/**
* Base helper to call remote function.
*
* @param <T> The type of the concrete task caller
*/
public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
private CallOptions.Builder builder = new CallOptions.Builder();
/**
* Set a name for this task.
*
* @param name task name
* @return self
* @see CallOptions.Builder#setName(java.lang.String)
*/
public T setName(String name) {
builder.setName(name);
return self();
}
/**
* Set a custom resource requirement for resource {@code name}. This method can be called multiple
* times. If the same resource is set multiple times, the latest quantity will be used.
*
* @param name resource name
* @param value resource capacity
* @return self
* @see CallOptions.Builder#setResource(java.lang.String, java.lang.Double)
*/
public T setResource(String name, Double value) {
builder.setResource(name, value);
return self();
}
/**
* Set custom requirements for multiple resources. This method can be called multiple times. If
* the same resource is set multiple times, the latest quantity will be used.
*
* @param resources requirements for multiple resources.
* @return self
* @see CallOptions.Builder#setResources(java.util.Map)
*/
public T setResources(Map<String, Double> resources) {
builder.setResources(resources);
return self();
}
/**
* Set the placement group to place this task in.
*
* @param group The placement group of the task.
* @param bundleIndex The index of the bundle to place this task in.
* @return self
* @see CallOptions.Builder#setPlacementGroup(PlacementGroup, int)
*/
public T setPlacementGroup(PlacementGroup group, int bundleIndex) {
builder.setPlacementGroup(group, bundleIndex);
return self();
}
/**
* Set the placement group to place this task in, which may use any available bundle.
*
* @param group The placement group of the task.
* @return self
* @see CallOptions.Builder#setPlacementGroup(PlacementGroup, int)
*/
public T setPlacementGroup(PlacementGroup group) {
return setPlacementGroup(group, -1);
}
/**
* Set the runtime env for this task to run the task in a specific environment.
*
* @param runtimeEnv The runtime env of this task.
* @return self
*/
public T setRuntimeEnv(RuntimeEnv runtimeEnv) {
builder.setRuntimeEnv(runtimeEnv);
return self();
}
@SuppressWarnings("unchecked")
private T self() {
return (T) this;
}
protected CallOptions buildOptions() {
return builder.build();
}
}
@@ -0,0 +1,25 @@
package io.ray.api.call;
import io.ray.api.CppActorHandle;
import io.ray.api.Ray;
import io.ray.api.function.CppActorClass;
/** A helper to create cpp actor. */
public class CppActorCreator extends BaseActorCreator<CppActorCreator> {
private final CppActorClass cppActorClass;
private final Object[] args;
public CppActorCreator(CppActorClass cppActorClass, Object[] args) {
this.cppActorClass = cppActorClass;
this.args = args;
}
/**
* Create a cpp actor remotely and return a handle to the created actor.
*
* @return a handle to the created cpp actor.
*/
public CppActorHandle remote() {
return Ray.internal().createActor(cppActorClass, args, buildOptions());
}
}
@@ -0,0 +1,34 @@
package io.ray.api.call;
import io.ray.api.CppActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.function.CppActorMethod;
/**
* A helper to call cppthon actor method.
*
* @param <R> The type of the cpp actor method return value
*/
public class CppActorTaskCaller<R> {
private final CppActorHandle actor;
private final CppActorMethod<R> method;
private final Object[] args;
public CppActorTaskCaller(CppActorHandle actor, CppActorMethod<R> method, Object[] args) {
this.actor = actor;
this.method = method;
this.args = args;
}
/**
* Execute a cpp actor method remotely and return an object reference to the result object in the
* object store.
*
* @return an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().callActor(actor, method, args);
}
}
@@ -0,0 +1,31 @@
package io.ray.api.call;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.function.CppFunction;
/**
* A helper to call cpp remote function.
*
* @param <R> The type of the cpp function return value
*/
public class CppTaskCaller<R> extends BaseTaskCaller<CppTaskCaller<R>> {
private final CppFunction<R> func;
private final Object[] args;
public CppTaskCaller(CppFunction<R> func, Object[] args) {
this.func = func;
this.args = args;
}
/**
* Execute a cpp function remotely and return an object reference to the result object in the
* object store.
*
* @return an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().call(func, args, buildOptions());
}
}
@@ -0,0 +1,30 @@
package io.ray.api.call;
import io.ray.api.PyActorHandle;
import io.ray.api.Ray;
import io.ray.api.function.PyActorClass;
/** A helper to create python actor. */
public class PyActorCreator extends BaseActorCreator<PyActorCreator> {
private final PyActorClass pyActorClass;
private final Object[] args;
public PyActorCreator(PyActorClass pyActorClass, Object[] args) {
this.pyActorClass = pyActorClass;
this.args = args;
}
public PyActorCreator setAsync(boolean isAsync) {
builder.setAsync(isAsync);
return this;
}
/**
* Create a python actor remotely and return a handle to the created actor.
*
* @return a handle to the created python actor.
*/
public PyActorHandle remote() {
return Ray.internal().createActor(pyActorClass, args, buildOptions());
}
}
@@ -0,0 +1,34 @@
package io.ray.api.call;
import io.ray.api.ObjectRef;
import io.ray.api.PyActorHandle;
import io.ray.api.Ray;
import io.ray.api.function.PyActorMethod;
/**
* A helper to call python actor method.
*
* @param <R> The type of the python actor method return value
*/
public class PyActorTaskCaller<R> {
private final PyActorHandle actor;
private final PyActorMethod<R> method;
private final Object[] args;
public PyActorTaskCaller(PyActorHandle actor, PyActorMethod<R> method, Object[] args) {
this.actor = actor;
this.method = method;
this.args = args;
}
/**
* Execute a python actor method remotely and return an object reference to the result object in
* the object store.
*
* @return an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().callActor(actor, method, args);
}
}
@@ -0,0 +1,31 @@
package io.ray.api.call;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.function.PyFunction;
/**
* A helper to call python remote function.
*
* @param <R> The type of the python function return value
*/
public class PyTaskCaller<R> extends BaseTaskCaller<PyTaskCaller<R>> {
private final PyFunction<R> func;
private final Object[] args;
public PyTaskCaller(PyFunction<R> func, Object[] args) {
this.func = func;
this.args = args;
}
/**
* Execute a python function remotely and return an object reference to the result object in the
* object store.
*
* @return an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().call(func, args, buildOptions());
}
}
@@ -0,0 +1,31 @@
package io.ray.api.call;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncR;
/**
* A helper to call java remote function.
*
* @param <R> The type of the java remote function return value
*/
public class TaskCaller<R> extends BaseTaskCaller<TaskCaller<R>> {
private final RayFuncR<R> func;
private final Object[] args;
public TaskCaller(RayFuncR<R> func, Object[] args) {
this.func = func;
this.args = args;
}
/**
* Execute a java function remotely and return an object reference to the result object in the
* object store.
*
* @return an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().call(func, args, buildOptions());
}
}
@@ -0,0 +1,34 @@
package io.ray.api.call;
import io.ray.api.ActorHandle;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncVoid;
import io.ray.api.options.CallOptions;
/** A helper to call java actor method which doesn't have a return value. */
public class VoidActorTaskCaller {
private final ActorHandle actor;
private final RayFuncVoid func;
private final Object[] args;
private CallOptions.Builder builder = new CallOptions.Builder();
public VoidActorTaskCaller(ActorHandle actor, RayFuncVoid func, Object[] args) {
this.actor = actor;
this.func = func;
this.args = args;
}
public VoidActorTaskCaller setConcurrencyGroup(String name) {
builder.setConcurrencyGroupName(name);
return self();
}
private VoidActorTaskCaller self() {
return this;
}
/** Execute a function remotely. */
public void remote() {
Ray.internal().callActor(actor, func, args, builder.build());
}
}
@@ -0,0 +1,20 @@
package io.ray.api.call;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncVoid;
/** A helper to call java remote function which doesn't have a return value. */
public class VoidTaskCaller extends BaseTaskCaller<VoidTaskCaller> {
private final RayFuncVoid func;
private final Object[] args;
public VoidTaskCaller(RayFuncVoid func, Object[] args) {
this.func = func;
this.args = args;
}
/** Execute a function remotely. */
public void remote() {
Ray.internal().call(func, args, buildOptions());
}
}
@@ -0,0 +1,74 @@
// Generated by `BaseConcurrencyGroupBuilderGenerator.java`. DO NOT EDIT.
package io.ray.api.concurrencygroup;
import io.ray.api.function.RayFunc;
import io.ray.api.function.RayFunc1;
import io.ray.api.function.RayFunc2;
import io.ray.api.function.RayFunc3;
import io.ray.api.function.RayFunc4;
import io.ray.api.function.RayFunc5;
import io.ray.api.function.RayFunc6;
import io.ray.api.function.RayFuncVoid1;
import io.ray.api.function.RayFuncVoid2;
import io.ray.api.function.RayFuncVoid3;
import io.ray.api.function.RayFuncVoid4;
import io.ray.api.function.RayFuncVoid5;
import io.ray.api.function.RayFuncVoid6;
/** This class provides type-safe interfaces for concurrency groups. */
abstract class BaseConcurrencyGroupBuilder<A> {
protected abstract ConcurrencyGroupBuilder<A> internalAddMethod(RayFunc func);
public <R> ConcurrencyGroupBuilder<A> addMethod(RayFunc1<A, R> f) {
return internalAddMethod(f);
}
public ConcurrencyGroupBuilder<A> addMethod(RayFuncVoid1<A> f) {
return internalAddMethod(f);
}
public <T0, R> ConcurrencyGroupBuilder<A> addMethod(RayFunc2<A, T0, R> f) {
return internalAddMethod(f);
}
public <T0> ConcurrencyGroupBuilder<A> addMethod(RayFuncVoid2<A, T0> f) {
return internalAddMethod(f);
}
public <T0, T1, R> ConcurrencyGroupBuilder<A> addMethod(RayFunc3<A, T0, T1, R> f) {
return internalAddMethod(f);
}
public <T0, T1> ConcurrencyGroupBuilder<A> addMethod(RayFuncVoid3<A, T0, T1> f) {
return internalAddMethod(f);
}
public <T0, T1, T2, R> ConcurrencyGroupBuilder<A> addMethod(RayFunc4<A, T0, T1, T2, R> f) {
return internalAddMethod(f);
}
public <T0, T1, T2> ConcurrencyGroupBuilder<A> addMethod(RayFuncVoid4<A, T0, T1, T2> f) {
return internalAddMethod(f);
}
public <T0, T1, T2, T3, R> ConcurrencyGroupBuilder<A> addMethod(
RayFunc5<A, T0, T1, T2, T3, R> f) {
return internalAddMethod(f);
}
public <T0, T1, T2, T3> ConcurrencyGroupBuilder<A> addMethod(RayFuncVoid5<A, T0, T1, T2, T3> f) {
return internalAddMethod(f);
}
public <T0, T1, T2, T3, T4, R> ConcurrencyGroupBuilder<A> addMethod(
RayFunc6<A, T0, T1, T2, T3, T4, R> f) {
return internalAddMethod(f);
}
public <T0, T1, T2, T3, T4> ConcurrencyGroupBuilder<A> addMethod(
RayFuncVoid6<A, T0, T1, T2, T3, T4> f) {
return internalAddMethod(f);
}
}
@@ -0,0 +1,4 @@
package io.ray.api.concurrencygroup;
/** The interface indicates concurrent executing in one thread pool. */
public interface ConcurrencyGroup {}
@@ -0,0 +1,35 @@
package io.ray.api.concurrencygroup;
import io.ray.api.Ray;
import io.ray.api.function.RayFunc;
import java.util.ArrayList;
import java.util.List;
public class ConcurrencyGroupBuilder<A> extends BaseConcurrencyGroupBuilder<A> {
private String name;
private int maxConcurrency;
private List<RayFunc> funcs = new ArrayList<>();
public ConcurrencyGroupBuilder<A> setName(String name) {
this.name = name;
return this;
}
public ConcurrencyGroupBuilder<A> setMaxConcurrency(int maxConcurrency) {
this.maxConcurrency = maxConcurrency;
return this;
}
public ConcurrencyGroup build() {
return Ray.internal().createConcurrencyGroup(this.name, this.maxConcurrency, funcs);
}
@Override
protected ConcurrencyGroupBuilder<A> internalAddMethod(RayFunc func) {
funcs.add(func);
return this;
}
}
@@ -0,0 +1,19 @@
package io.ray.api.concurrencygroup.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Inherited
@Repeatable(DefConcurrencyGroups.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface DefConcurrencyGroup {
public String name() default "";
public int maxConcurrency() default 1;
}
@@ -0,0 +1,14 @@
package io.ray.api.concurrencygroup.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface DefConcurrencyGroups {
DefConcurrencyGroup[] value();
}
@@ -0,0 +1,15 @@
package io.ray.api.concurrencygroup.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface UseConcurrencyGroup {
public String name() default "";
}
@@ -0,0 +1,8 @@
package io.ray.api.exception;
public class CrossLanguageException extends RayException {
public CrossLanguageException(String message) {
super(message);
}
}
@@ -0,0 +1,17 @@
package io.ray.api.exception;
import io.ray.api.id.ActorId;
/**
* Indicates that the back pressure occurs when submitting an actor task.
*
* <p>This exception could happen probably because the caller calls the callee too frequently.
*/
public class PendingCallsLimitExceededException extends RayException {
public ActorId actorId;
public PendingCallsLimitExceededException(String message) {
super(message);
}
}
@@ -0,0 +1,42 @@
package io.ray.api.exception;
import io.ray.api.id.ActorId;
/**
* Indicates that the actor died unexpectedly before finishing a task.
*
* <p>This exception could happen either because the actor process dies while executing a task, or
* because a task is submitted to a dead actor.
*
* <p>If the actor died because of an exception thrown in its creation tasks, RayActorError will
* contains this exception as the cause exception.
*/
public class RayActorException extends RayException {
public ActorId actorId;
public RayActorException() {
super("The actor died unexpectedly before finishing this task.");
}
public RayActorException(ActorId actorId) {
super(String.format("The actor %s died unexpectedly before finishing this task.", actorId));
this.actorId = actorId;
}
public RayActorException(int pid, String ipAddress, ActorId actorId, Throwable cause) {
super(
String.format(
"(pid=%d, ip=%s) The actor %s died because of it's creation task failed",
pid, ipAddress, actorId.toString()),
cause);
this.actorId = actorId;
}
public RayActorException(int pid, String ipAddress, Throwable cause) {
super(
String.format(
"(pid=%d, ip=%s) The actor died because of it's creation task failed", pid, ipAddress),
cause);
}
}
@@ -0,0 +1,12 @@
package io.ray.api.exception;
public class RayException extends RuntimeException {
public RayException(String message) {
super(message);
}
public RayException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,13 @@
package io.ray.api.exception;
/** The exception represents that there is an intentional system exit. */
public class RayIntentionalSystemExitException extends RuntimeException {
public RayIntentionalSystemExitException(String message) {
super(message);
}
public RayIntentionalSystemExitException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,12 @@
package io.ray.api.exception;
public class RayTaskException extends RayException {
public RayTaskException(String message) {
super(message);
}
public RayTaskException(int pid, String ipAddress, String message, Throwable cause) {
super(String.format("(pid=%d, ip=%s) %s", pid, ipAddress, message), cause);
}
}
@@ -0,0 +1,12 @@
package io.ray.api.exception;
/** Indicate that there are some thing have timed out, including `Ray.get()` or others. */
public class RayTimeoutException extends RayException {
public RayTimeoutException(String message) {
super(message);
}
public RayTimeoutException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,17 @@
package io.ray.api.exception;
/** Indicates that the worker died unexpectedly while executing a task. */
public class RayWorkerException extends RayException {
public RayWorkerException() {
super("The worker died unexpectedly while executing this task.");
}
public RayWorkerException(String message) {
super(message);
}
public RayWorkerException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,12 @@
package io.ray.api.exception;
public class RuntimeEnvException extends RayException {
public RuntimeEnvException(String message) {
super(message);
}
public RuntimeEnvException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,30 @@
package io.ray.api.exception;
import io.ray.api.id.ObjectId;
/**
* Indicates that an object is lost (either evicted or explicitly deleted) and cannot be restarted.
*
* <p>Note, this exception only happens for actor objects. If actor's current state is after
* object's creating task, the actor cannot re-run the task to reconstruct the object.
*/
public class UnreconstructableException extends RayException {
public ObjectId objectId;
public UnreconstructableException(ObjectId objectId) {
super(
String.format(
"Object %s is lost (either evicted or explicitly deleted) and cannot be reconstructed.",
objectId));
this.objectId = objectId;
}
public UnreconstructableException(String message) {
super(message);
}
public UnreconstructableException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,24 @@
package io.ray.api.function;
public class CppActorClass {
// The name of function creating the class.
public final String createFunctionName;
// The name of this actor class
public final String className;
private CppActorClass(String createFunctionName, String className) {
this.createFunctionName = createFunctionName;
this.className = className;
}
/**
* Create a cpp actor class.
*
* @param createFunctionName The name of function creating the class
* @param className The name of this actor class
* @return a cpp actor class
*/
public static CppActorClass of(String createFunctionName, String className) {
return new CppActorClass(createFunctionName, className);
}
}
@@ -0,0 +1,8 @@
package io.ray.api;
/** Handle of a Cpp actor. */
public interface CppActorHandle extends BaseActorHandle, CppActorCall {
/** Returns the name of the Cpp actor class. */
String getClassName();
}
@@ -0,0 +1,35 @@
package io.ray.api.function;
public class CppActorMethod<R> {
// The name of this actor method
public final String methodName;
// Type of the return value of this actor method
public final Class<R> returnType;
private CppActorMethod(String methodName, Class<R> returnType) {
this.methodName = methodName;
this.returnType = returnType;
}
/**
* Create a cppthon actor method.
*
* @param methodName The name of this actor method
* @return a cppthon actor method.
*/
public static CppActorMethod<Object> of(String methodName) {
return of(methodName, Object.class);
}
/**
* Create a cppthon actor method.
*
* @param methodName The name of this actor method
* @param returnType Class of the return value of this actor method
* @param <R> The type of the return value of this actor method
* @return a cppthon actor method.
*/
public static <R> CppActorMethod<R> of(String methodName, Class<R> returnType) {
return new CppActorMethod<>(methodName, returnType);
}
}
@@ -0,0 +1,35 @@
package io.ray.api.function;
public class CppFunction<R> {
// The name of this function
public final String functionName;
// Type of the return value of this function
public final Class<R> returnType;
private CppFunction(String functionName, Class<R> returnType) {
this.functionName = functionName;
this.returnType = returnType;
}
/**
* Create a cpp function.
*
* @param functionName The name of this function
* @return a cpp function.
*/
public static CppFunction<Object> of(String functionName) {
return of(functionName, Object.class);
}
/**
* Create a cpp function.
*
* @param functionName The name of this function
* @param returnType Class of the return value of this function
* @param <R> Type of the return value of this function
* @return a cpp function.
*/
public static <R> CppFunction<R> of(String functionName, Class<R> returnType) {
return new CppFunction<>(functionName, returnType);
}
}
@@ -0,0 +1,47 @@
package io.ray.api.function;
/**
* A class that represents a Python actor class.
*
* <pre>
* example_package/
* ├──__init__.py
* └──example_module.py
*
* in example_module.py there is an actor class A.
*
* \@ray.remote
* class A(object):
* def __init__(self, x):
* self.x = x
*
* we can create this Python actor from Java:
*
* {@code
* PyActorHandle actor = Ray.createActor(PyActorClass.of("example_package.example_module", "A"),
* "the value for x");
* }
* </pre>
*/
public class PyActorClass {
// The full module name of this actor class
public final String moduleName;
// The name of this actor class
public final String className;
private PyActorClass(String moduleName, String className) {
this.moduleName = moduleName;
this.className = className;
}
/**
* Create a python actor class.
*
* @param moduleName The full module name of this actor class
* @param className The name of this actor class
* @return a python actor class
*/
public static PyActorClass of(String moduleName, String className) {
return new PyActorClass(moduleName, className);
}
}
@@ -0,0 +1,64 @@
package io.ray.api.function;
/**
* A class that represents a method of a Python actor.
*
* <p>Note, information about the actor will be inferred from the actor handle, so it's not
* specified in this class.
*
* <pre>
* there is a Python actor class A.
*
* \@ray.remote
* class A(object):
* def foo(self):
* return "Hello world!"
*
* suppose we have got the Python actor class A's handle in Java
*
* {@code
* PyActorHandle actor = ...; // returned from Ray.createActor or passed from Python
* }
*
* then we can call the actor method:
*
* {@code
* // A.foo returns a string, so we have to set the returnType to String.class
* ObjectRef<String> res = actor.call(PyActorMethod.of("foo", String.class));
* String x = res.get();
* }
* </pre>
*/
public class PyActorMethod<R> {
// The name of this actor method
public final String methodName;
// Type of the return value of this actor method
public final Class<R> returnType;
private PyActorMethod(String methodName, Class<R> returnType) {
this.methodName = methodName;
this.returnType = returnType;
}
/**
* Create a python actor method.
*
* @param methodName The name of this actor method
* @return a python actor method.
*/
public static PyActorMethod<Object> of(String methodName) {
return of(methodName, Object.class);
}
/**
* Create a python actor method.
*
* @param methodName The name of this actor method
* @param returnType Class of the return value of this actor method
* @param <R> The type of the return value of this actor method
* @return a python actor method.
*/
public static <R> PyActorMethod<R> of(String methodName, Class<R> returnType) {
return new PyActorMethod<>(methodName, returnType);
}
}
@@ -0,0 +1,71 @@
package io.ray.api.function;
/**
* A class that represents a Python remote function.
*
* <pre>
* example_package/
* ├──__init__.py
* └──example_module.py
*
* in example_module.py there is a function.
*
* \@ray.remote
* def bar(v):
* return v
*
* then we can call the Python function bar:
*
* {@code
* // bar returns input, so we have to set the returnType to int.class if bar accepts an int
* ObjectRef<Integer> res = actor.call(
* PyFunction.of("example_package.example_module", "bar", Integer.class),
* 1);
* Integer value = res.get();
*
* // bar returns input, so we have to set the returnType to String.class if bar accepts a string
* ObjectRef<String> res = actor.call(
* PyFunction.of("example_package.example_module", "bar", String.class),
* "Hello world!");
* String value = res.get();
* }
* </pre>
*/
public class PyFunction<R> {
// The full module name of this function
public final String moduleName;
// The name of this function
public final String functionName;
// Type of the return value of this function
public final Class<R> returnType;
private PyFunction(String moduleName, String functionName, Class<R> returnType) {
this.moduleName = moduleName;
this.functionName = functionName;
this.returnType = returnType;
}
/**
* Create a python function.
*
* @param moduleName The full module name of this function
* @param functionName The name of this function
* @return a python function.
*/
public static PyFunction<Object> of(String moduleName, String functionName) {
return of(moduleName, functionName, Object.class);
}
/**
* Create a python function.
*
* @param moduleName The full module name of this function
* @param functionName The name of this function
* @param returnType Class of the return value of this function
* @param <R> Type of the return value of this function
* @return a python function.
*/
public static <R> PyFunction<R> of(String moduleName, String functionName, Class<R> returnType) {
return new PyFunction<>(moduleName, functionName, returnType);
}
}
@@ -0,0 +1,6 @@
package io.ray.api.function;
import java.io.Serializable;
/** Base interface of all Ray remote java functions. */
public interface RayFunc extends Serializable {}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 0 parameter. */
@FunctionalInterface
public interface RayFunc0<R> extends RayFuncR<R> {
R apply() throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 1 parameter. */
@FunctionalInterface
public interface RayFunc1<T0, R> extends RayFuncR<R> {
R apply(T0 t0) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 2 parameters. */
@FunctionalInterface
public interface RayFunc2<T0, T1, R> extends RayFuncR<R> {
R apply(T0 t0, T1 t1) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 3 parameters. */
@FunctionalInterface
public interface RayFunc3<T0, T1, T2, R> extends RayFuncR<R> {
R apply(T0 t0, T1 t1, T2 t2) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 4 parameters. */
@FunctionalInterface
public interface RayFunc4<T0, T1, T2, T3, R> extends RayFuncR<R> {
R apply(T0 t0, T1 t1, T2 t2, T3 t3) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 5 parameters. */
@FunctionalInterface
public interface RayFunc5<T0, T1, T2, T3, T4, R> extends RayFuncR<R> {
R apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 6 parameters. */
@FunctionalInterface
public interface RayFunc6<T0, T1, T2, T3, T4, T5, R> extends RayFuncR<R> {
R apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Exception;
}
@@ -0,0 +1,8 @@
package io.ray.api.function;
/**
* Interface of all Ray remote functions which have a return value.
*
* @param <R> Type of function return value
*/
public interface RayFuncR<R> extends RayFunc {}
@@ -0,0 +1,4 @@
package io.ray.api.function;
/** Interface of all `RayFuncVoidX` classes. */
public interface RayFuncVoid extends RayFunc {}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 0 parameter. */
@FunctionalInterface
public interface RayFuncVoid0 extends RayFuncVoid {
void apply() throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 1 parameter. */
@FunctionalInterface
public interface RayFuncVoid1<T0> extends RayFuncVoid {
void apply(T0 t0) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 2 parameters. */
@FunctionalInterface
public interface RayFuncVoid2<T0, T1> extends RayFuncVoid {
void apply(T0 t0, T1 t1) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 3 parameters. */
@FunctionalInterface
public interface RayFuncVoid3<T0, T1, T2> extends RayFuncVoid {
void apply(T0 t0, T1 t1, T2 t2) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 4 parameters. */
@FunctionalInterface
public interface RayFuncVoid4<T0, T1, T2, T3> extends RayFuncVoid {
void apply(T0 t0, T1 t1, T2 t2, T3 t3) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 5 parameters. */
@FunctionalInterface
public interface RayFuncVoid5<T0, T1, T2, T3, T4> extends RayFuncVoid {
void apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Exception;
}
@@ -0,0 +1,10 @@
// generated automatically, do not modify.
package io.ray.api.function;
/** Functional interface for a remote function that has 6 parameters. */
@FunctionalInterface
public interface RayFuncVoid6<T0, T1, T2, T3, T4, T5> extends RayFuncVoid {
void apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Exception;
}
@@ -0,0 +1,52 @@
package io.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
public class ActorId extends BaseId implements Serializable {
private static final int UNIQUE_BYTES_LENGTH = 12;
public static final int LENGTH = JobId.LENGTH + UNIQUE_BYTES_LENGTH;
public static final ActorId NIL = nil();
private ActorId(byte[] id) {
super(id);
}
public static ActorId fromByteBuffer(ByteBuffer bb) {
return new ActorId(byteBuffer2Bytes(bb));
}
public static ActorId fromBytes(byte[] bytes) {
return new ActorId(bytes);
}
/** Generate a nil ActorId. */
private static ActorId nil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
return new ActorId(b);
}
/** Generate an ActorId with random value. Used for local mode and test only. */
public static ActorId fromRandom() {
byte[] b = new byte[LENGTH];
new Random().nextBytes(b);
return new ActorId(b);
}
@Override
public int size() {
return LENGTH;
}
public JobId getJobId() {
byte[] actorBytes = getBytes();
ByteBuffer bf = ByteBuffer.wrap(actorBytes, UNIQUE_BYTES_LENGTH, JobId.LENGTH);
return JobId.fromByteBuffer(bf);
}
}
@@ -0,0 +1,96 @@
package io.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import javax.xml.bind.DatatypeConverter;
public abstract class BaseId implements Serializable {
private static final long serialVersionUID = 8588849129675565761L;
private final byte[] id;
private transient int hashCodeCache = 0;
private transient Boolean isNilCache = null;
/** Create a BaseId instance according to the input byte array. */
protected BaseId(byte[] id) {
if (id.length != size()) {
throw new IllegalArgumentException(
"Failed to construct BaseId, expect "
+ size()
+ " bytes, but got "
+ id.length
+ " bytes.");
}
this.id = id;
}
/** Get the byte data of this id. */
public byte[] getBytes() {
return id;
}
/** Convert the byte data to a ByteBuffer. */
public ByteBuffer toByteBuffer() {
return ByteBuffer.wrap(id);
}
/** Returns true if this id is nil. */
public boolean isNil() {
if (isNilCache == null) {
boolean localIsNil = true;
for (int i = 0; i < size(); ++i) {
if (id[i] != (byte) 0xff) {
localIsNil = false;
break;
}
}
isNilCache = localIsNil;
}
return isNilCache;
}
/**
* Derived class should implement this function.
*
* @return The length of this id in bytes.
*/
public abstract int size();
@Override
public int hashCode() {
// Lazy evaluation.
if (hashCodeCache == 0) {
hashCodeCache = Arrays.hashCode(id);
}
return hashCodeCache;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!this.getClass().equals(obj.getClass())) {
return false;
}
BaseId r = (BaseId) obj;
return Arrays.equals(id, r.id);
}
@Override
public String toString() {
return DatatypeConverter.printHexBinary(id).toLowerCase();
}
protected static byte[] hexString2Bytes(String hex) {
return DatatypeConverter.parseHexBinary(hex);
}
protected static byte[] byteBuffer2Bytes(ByteBuffer bb) {
byte[] id = new byte[bb.remaining()];
bb.get(id);
return id;
}
}
@@ -0,0 +1,60 @@
package io.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
/** Represents the id of a Ray job. */
public class JobId extends BaseId implements Serializable {
public static final int LENGTH = 4;
public static final JobId NIL = genNil();
/** Create a JobID instance according to the given bytes. */
private JobId(byte[] id) {
super(id);
}
/** Create a JobId from byte array. */
public static JobId fromBytes(byte[] bytes) {
return new JobId(bytes);
}
/** Create a JobId from a given hex string. */
public static JobId fromHexString(String hex) {
return new JobId(hexString2Bytes(hex));
}
/** Creates a JobId from the given ByteBuffer. */
public static JobId fromByteBuffer(ByteBuffer bb) {
return new JobId(byteBuffer2Bytes(bb));
}
public static JobId fromInt(int value) {
if (value > Math.pow(256, JobId.LENGTH)) {
throw new IllegalArgumentException(
"The integer value is invalid for a JobId. Value: " + value);
}
byte[] bytes = new byte[Integer.BYTES];
ByteBuffer wbb = ByteBuffer.wrap(bytes);
wbb.order(ByteOrder.LITTLE_ENDIAN);
wbb.putInt(value);
wbb.flip();
wbb.limit(JobId.LENGTH);
return JobId.fromByteBuffer(wbb);
}
/** Generate a nil JobId. */
private static JobId genNil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
return new JobId(b);
}
@Override
public int size() {
return LENGTH;
}
}
@@ -0,0 +1,38 @@
package io.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
/** Represents the id of a Ray object. */
public class ObjectId extends BaseId implements Serializable {
public static final int LENGTH = 28;
/** Create an ObjectId from a ByteBuffer. */
public static ObjectId fromByteBuffer(ByteBuffer bb) {
return new ObjectId(byteBuffer2Bytes(bb));
}
/** Generate an ObjectId with random value. */
public static ObjectId fromRandom() {
// This is tightly coupled with ObjectID definition in C++. If that changes,
// this must be changed as well.
// The following logic should be kept consistent with `ObjectID::FromRandom` in
// C++.
byte[] b = new byte[LENGTH];
new Random().nextBytes(b);
Arrays.fill(b, TaskId.LENGTH, LENGTH, (byte) 0);
return new ObjectId(b);
}
public ObjectId(byte[] id) {
super(id);
}
@Override
public int size() {
return LENGTH;
}
}
@@ -0,0 +1,49 @@
package io.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
/** Represents the id of a placement group. */
public class PlacementGroupId extends BaseId implements Serializable {
private static final int UNIQUE_BYTES_LENGTH = 14;
public static final int LENGTH = JobId.LENGTH + UNIQUE_BYTES_LENGTH;
public static final PlacementGroupId NIL = nil();
private PlacementGroupId(byte[] id) {
super(id);
}
/** Creates a PlacementGroupId from the given ByteBuffer. */
public static PlacementGroupId fromByteBuffer(ByteBuffer bb) {
return new PlacementGroupId(byteBuffer2Bytes(bb));
}
/** Create a PlacementGroupId instance according to the given bytes. */
public static PlacementGroupId fromBytes(byte[] bytes) {
return new PlacementGroupId(bytes);
}
/** Generate a nil PlacementGroupId. */
private static PlacementGroupId nil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
return new PlacementGroupId(b);
}
/** Generate an PlacementGroupId with random value. Used for local mode and test only. */
public static PlacementGroupId fromRandom() {
byte[] b = new byte[LENGTH];
new Random().nextBytes(b);
return new PlacementGroupId(b);
}
@Override
public int size() {
return LENGTH;
}
}
@@ -0,0 +1,46 @@
package io.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
/** Represents the id of a Ray task. */
public class TaskId extends BaseId implements Serializable {
public static final int UNIQUE_BYTES_LENGTH = 8;
public static final int LENGTH = ActorId.LENGTH + UNIQUE_BYTES_LENGTH;
public static final TaskId NIL = genNil();
/** Create a TaskId from a hex string. */
public static TaskId fromHexString(String hex) {
return new TaskId(hexString2Bytes(hex));
}
/** Creates a TaskId from a ByteBuffer. */
public static TaskId fromByteBuffer(ByteBuffer bb) {
return new TaskId(byteBuffer2Bytes(bb));
}
/** Creates a TaskId from given bytes. */
public static TaskId fromBytes(byte[] bytes) {
return new TaskId(bytes);
}
/** Generate a nil TaskId. */
private static TaskId genNil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
return new TaskId(b);
}
private TaskId(byte[] id) {
super(id);
}
@Override
public int size() {
return LENGTH;
}
}
@@ -0,0 +1,51 @@
package io.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
/** Represents a unique id of all Ray concepts, including workers, actors, checkpoints, etc. */
public class UniqueId extends BaseId implements Serializable {
public static final int LENGTH = 28;
public static final UniqueId NIL = genNil();
/** Create a UniqueId from a hex string. */
public static UniqueId fromHexString(String hex) {
return new UniqueId(hexString2Bytes(hex));
}
/** Creates a UniqueId from a ByteBuffer. */
public static UniqueId fromByteBuffer(ByteBuffer bb) {
return new UniqueId(byteBuffer2Bytes(bb));
}
/** Creates a UniqueId from bytes */
public static UniqueId fromBytes(byte[] bytes) {
return new UniqueId(bytes);
}
/** Generate a nil UniqueId. */
private static UniqueId genNil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
return new UniqueId(b);
}
/** Generate an UniqueId with random value. */
public static UniqueId randomId() {
byte[] b = new byte[LENGTH];
new Random().nextBytes(b);
return new UniqueId(b);
}
public UniqueId(byte[] id) {
super(id);
}
@Override
public int size() {
return LENGTH;
}
}
@@ -0,0 +1,295 @@
package io.ray.api.options;
import io.ray.api.Ray;
import io.ray.api.concurrencygroup.ConcurrencyGroup;
import io.ray.api.placementgroup.PlacementGroup;
import io.ray.api.runtimeenv.RuntimeEnv;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** The options for creating actor. */
public class ActorCreationOptions extends BaseTaskOptions {
public static final int NO_RESTART = 0;
public static final int INFINITE_RESTART = -1;
private final String name;
private final ActorLifetime lifetime;
private final int maxRestarts;
private final int maxTaskRetries;
private final List<String> jvmOptions;
private final int maxConcurrency;
private final PlacementGroup group;
private final int bundleIndex;
private final List<ConcurrencyGroup> concurrencyGroups;
private final String serializedRuntimeEnv;
private final String namespace;
private final int maxPendingCalls;
private final boolean isAsync;
private final boolean allowOutOfOrderExecution;
private ActorCreationOptions(Builder builder) {
super(builder.resources);
this.name = builder.name;
this.lifetime = builder.lifetime;
this.maxRestarts = builder.maxRestarts;
this.maxTaskRetries = builder.maxTaskRetries;
this.jvmOptions =
builder.jvmOptions != null
? java.util.Collections.unmodifiableList(builder.jvmOptions)
: null;
this.maxConcurrency = builder.maxConcurrency;
this.group = builder.group;
this.bundleIndex = builder.bundleIndex;
this.concurrencyGroups =
builder.concurrencyGroups != null
? java.util.Collections.unmodifiableList(builder.concurrencyGroups)
: null;
this.serializedRuntimeEnv =
builder.runtimeEnv != null ? builder.runtimeEnv.serializeToRuntimeEnvInfo() : "";
this.namespace = builder.namespace;
this.maxPendingCalls = builder.maxPendingCalls;
this.isAsync = builder.isAsync;
this.allowOutOfOrderExecution = builder.isAsync;
}
public String getName() {
return name;
}
public ActorLifetime getLifetime() {
return lifetime;
}
public int getMaxRestarts() {
return maxRestarts;
}
public int getMaxTaskRetries() {
return maxTaskRetries;
}
public List<String> getJvmOptions() {
return jvmOptions;
}
public int getMaxConcurrency() {
return maxConcurrency;
}
public PlacementGroup getGroup() {
return group;
}
public int getBundleIndex() {
return bundleIndex;
}
public List<ConcurrencyGroup> getConcurrencyGroups() {
return concurrencyGroups;
}
public String getSerializedRuntimeEnv() {
return serializedRuntimeEnv;
}
public String getNamespace() {
return namespace;
}
public int getMaxPendingCalls() {
return maxPendingCalls;
}
public boolean isAsync() {
return isAsync;
}
public boolean allowsOutOfOrderExecution() {
return allowOutOfOrderExecution;
}
/** The inner class for building ActorCreationOptions. */
public static class Builder {
private String name;
private ActorLifetime lifetime = null;
private final Map<String, Double> resources = new HashMap<>();
private int maxRestarts = 0;
private int maxTaskRetries = 0;
private List<String> jvmOptions = new ArrayList<>();
private int maxConcurrency = 1;
private PlacementGroup group;
private int bundleIndex;
private List<ConcurrencyGroup> concurrencyGroups = new ArrayList<>();
private RuntimeEnv runtimeEnv = null;
private String namespace = null;
private int maxPendingCalls = -1;
private boolean isAsync = false;
/**
* Set the actor name of a named actor. This named actor is accessible in this namespace by this
* name via {@link Ray#getActor(java.lang.String)} and in other namespaces via {@link
* Ray#getActor(java.lang.String, java.lang.String)}.
*
* @param name The name of the named actor.
* @return self
*/
public Builder setName(String name) {
this.name = name;
return this;
}
/** Declare the lifetime of this actor. */
public Builder setLifetime(ActorLifetime lifetime) {
this.lifetime = lifetime;
return this;
}
/**
* Set a custom resource requirement to reserve for the lifetime of this actor. This method can
* be called multiple times. If the same resource is set multiple times, the latest quantity
* will be used.
*
* @param resourceName resource name
* @param resourceQuantity resource quantity
* @return self
*/
public Builder setResource(String resourceName, Double resourceQuantity) {
this.resources.put(resourceName, resourceQuantity);
return this;
}
/**
* Set custom resource requirements to reserve for the lifetime of this actor. This method can
* be called multiple times. If the same resource is set multiple times, the latest quantity
* will be used.
*
* @param resources requirements for multiple resources.
* @return self
*/
public Builder setResources(Map<String, Double> resources) {
this.resources.putAll(resources);
return this;
}
/**
* This specifies the maximum number of times that the actor should be restarted when it dies
* unexpectedly. The minimum valid value is 0 (default), which indicates that the actor doesn't
* need to be restarted. A value of -1 indicates that an actor should be restarted indefinitely.
*
* @param maxRestarts max number of actor restarts
* @return self
*/
public Builder setMaxRestarts(int maxRestarts) {
this.maxRestarts = maxRestarts;
return this;
}
/**
* This specifies the maximum number of times that the actor task can be resubmitted. The
* minimum valid value is 0 (default), which indicates that the actor task can't be resubmited.
* A value of -1 indicates that an actor task can be resubmited indefinitely.
*
* @param maxTaskRetries max number of actor task retries
* @return self
*/
public Builder setMaxTaskRetries(int maxTaskRetries) {
this.maxTaskRetries = maxTaskRetries;
return this;
}
/**
* Set the JVM options for the Java worker that this actor is running in.
*
* <p>Note, if this is set, this actor won't share Java worker with other actors or tasks.
*
* @param jvmOptions JVM options for the Java worker that this actor is running in.
* @return self
*/
public Builder setJvmOptions(List<String> jvmOptions) {
this.jvmOptions = jvmOptions;
return this;
}
/**
* Set the max number of concurrent calls to allow for this actor.
*
* <p>The max concurrency defaults to 1 for threaded execution. Note that the execution order is
* not guaranteed when {@code max_concurrency > 1}.
*
* @param maxConcurrency The max number of concurrent calls to allow for this actor.
* @return self
*/
public Builder setMaxConcurrency(int maxConcurrency) {
if (maxConcurrency <= 0) {
throw new IllegalArgumentException("maxConcurrency must be greater than 0.");
}
this.maxConcurrency = maxConcurrency;
return this;
}
/**
* Set the max number of pending calls allowed on the actor handle. When this value is exceeded,
* ray.exceptions.PendingCallsLimitExceededException will be thrown for further tasks. Note that
* this limit is counted per handle. -1 means that the number of pending calls is unlimited.
*
* @param maxPendingCalls The maximum number of pending calls for this actor.
* @return self
*/
public Builder setMaxPendingCalls(int maxPendingCalls) {
if (maxPendingCalls < -1 || maxPendingCalls == 0) {
throw new IllegalArgumentException(
"maxPendingCalls must be greater than 0, or -1 to disable.");
}
this.maxPendingCalls = maxPendingCalls;
return this;
}
/**
* Mark the creating actor as async. If the Python actor is/is not async but it's marked
* async/not async in Java, it will result in RayActorError errors
*
* @return self
*/
public Builder setAsync(boolean isAsync) {
this.isAsync = isAsync;
return this;
}
/**
* Set the placement group to place this actor in.
*
* @param group The placement group of the actor.
* @param bundleIndex The index of the bundle to place this actor in.
* @return self
*/
public Builder setPlacementGroup(PlacementGroup group, int bundleIndex) {
this.group = group;
this.bundleIndex = bundleIndex;
return this;
}
/** Set the concurrency groups for this actor. */
public Builder setConcurrencyGroups(List<ConcurrencyGroup> concurrencyGroups) {
this.concurrencyGroups = concurrencyGroups;
return this;
}
public Builder setRuntimeEnv(RuntimeEnv runtimeEnv) {
this.runtimeEnv = runtimeEnv;
return this;
}
public Builder setNamespace(String namespace) {
this.namespace = namespace;
return this;
}
public ActorCreationOptions build() {
return new ActorCreationOptions(this);
}
}
}
@@ -0,0 +1,15 @@
package io.ray.api.options;
/** The enumeration class is used for declaring lifetime of actors. */
public enum ActorLifetime {
DETACHED("DETACHED", 0),
NON_DETACHED("NON_DETACHED", 1);
private String name;
private int value;
ActorLifetime(String name, int value) {
this.name = name;
this.value = value;
}
}
@@ -0,0 +1,70 @@
package io.ray.api.options;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/** The options class for RayCall or ActorCreation. */
public abstract class BaseTaskOptions implements Serializable {
private final Map<String, Double> resources;
public BaseTaskOptions(Map<String, Double> resources) {
if (resources == null) {
throw new IllegalArgumentException("Resources map should not be null!");
}
Map<String, Double> filteredResources = validateAndFilterResources(resources);
this.resources = Collections.unmodifiableMap(filteredResources);
}
private Map<String, Double> validateAndFilterResources(Map<String, Double> resources) {
Map<String, Double> filtered = new HashMap<>();
for (Map.Entry<String, Double> entry : resources.entrySet()) {
String name = entry.getKey();
Double value = entry.getValue();
validateResourceValue(name, value);
validateIntegerConstraint(name, value);
if (value != 0.0) {
filtered.put(name, value);
}
}
return filtered;
}
private void validateResourceValue(String name, Double value) {
if (name == null || value == null) {
throw new IllegalArgumentException(
String.format(
"Resource name and value should not be null. Specified resource: %s = %s.",
name, value));
} else if (value < 0.0) {
throw new IllegalArgumentException(
String.format(
"Resource values should be non negative. Specified resource: %s = %s.", name, value));
}
}
/**
* Validates that resource values greater than or equal to 1.0 are integers.
*
* @param name the name of the resource being validated
* @param value the value of the resource to validate
* @throws IllegalArgumentException if the value is >= 1.0 and not an integer
*/
private void validateIntegerConstraint(String name, Double value) {
if (value >= 1.0 && value % 1.0 != 0.0) {
throw new IllegalArgumentException(
String.format(
"A resource value should be an integer if it is greater than 1.0. Specified resource: %s = %s",
name, value));
}
}
public Map<String, Double> getResources() {
return resources;
}
}
@@ -0,0 +1,120 @@
package io.ray.api.options;
import io.ray.api.placementgroup.PlacementGroup;
import io.ray.api.runtimeenv.RuntimeEnv;
import java.util.HashMap;
import java.util.Map;
/** The options for RayCall. */
public class CallOptions extends BaseTaskOptions {
private final String name;
private final PlacementGroup group;
private final int bundleIndex;
private final String concurrencyGroupName;
private final String serializedRuntimeEnvInfo;
private CallOptions(Builder builder) {
super(builder.resources);
this.name = builder.name;
this.group = builder.group;
this.bundleIndex = builder.bundleIndex;
this.concurrencyGroupName = builder.concurrencyGroupName;
this.serializedRuntimeEnvInfo =
builder.runtimeEnv == null ? "" : builder.runtimeEnv.serializeToRuntimeEnvInfo();
}
public String getName() {
return name;
}
public PlacementGroup getGroup() {
return group;
}
public int getBundleIndex() {
return bundleIndex;
}
public String getConcurrencyGroupName() {
return concurrencyGroupName;
}
public String getSerializedRuntimeEnvInfo() {
return serializedRuntimeEnvInfo;
}
/** This inner class for building CallOptions. */
public static class Builder {
private String name;
private Map<String, Double> resources = new HashMap<>();
private PlacementGroup group;
private int bundleIndex;
private String concurrencyGroupName = "";
private RuntimeEnv runtimeEnv = null;
/**
* Set a name for this task.
*
* @param name task name
* @return self
*/
public Builder setName(String name) {
this.name = name;
return this;
}
/**
* Set a custom resource requirement for resource {@code name}. This method can be called
* multiple times. If the same resource is set multiple times, the latest quantity will be used.
*
* @param name resource name
* @param value resource capacity
* @return self
*/
public Builder setResource(String name, Double value) {
this.resources.put(name, value);
return this;
}
/**
* Set custom requirements for multiple resources. This method can be called multiple times. If
* the same resource is set multiple times, the latest quantity will be used.
*
* @param resources requirements for multiple resources.
* @return self
*/
public Builder setResources(Map<String, Double> resources) {
this.resources.putAll(resources);
return this;
}
/**
* Set the placement group to place this actor in.
*
* @param group The placement group of the actor.
* @param bundleIndex The index of the bundle to place this task in.
* @return self
*/
public Builder setPlacementGroup(PlacementGroup group, int bundleIndex) {
this.group = group;
this.bundleIndex = bundleIndex;
return this;
}
public Builder setConcurrencyGroupName(String concurrencyGroupName) {
this.concurrencyGroupName = concurrencyGroupName;
return this;
}
public Builder setRuntimeEnv(RuntimeEnv runtimeEnv) {
this.runtimeEnv = runtimeEnv;
return this;
}
public CallOptions build() {
return new CallOptions(this);
}
}
}
@@ -0,0 +1,106 @@
package io.ray.api.options;
import io.ray.api.Ray;
import io.ray.api.placementgroup.PlacementStrategy;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** The options for creating placement group. */
public class PlacementGroupCreationOptions {
private final String name;
private final List<Map<String, Double>> bundles;
private final PlacementStrategy strategy;
public PlacementGroupCreationOptions(
String name, List<Map<String, Double>> bundles, PlacementStrategy strategy) {
if (bundles == null || bundles.isEmpty()) {
throw new IllegalArgumentException(
"`Bundles` must be specified when creating a new placement group.");
}
boolean bundleResourceValid =
bundles.stream()
.allMatch(bundle -> bundle.values().stream().allMatch(resource -> resource > 0));
if (!bundleResourceValid) {
throw new IllegalArgumentException(
"Bundles cannot be empty or bundle's resource must be positive.");
}
if (strategy == null) {
throw new IllegalArgumentException(
"`PlacementStrategy` must be specified when creating a new placement group.");
}
this.name = name;
this.bundles =
Collections.unmodifiableList(
bundles.stream()
.map(bundle -> Collections.unmodifiableMap(new HashMap<>(bundle)))
.collect(Collectors.toList()));
this.strategy = strategy;
}
public String getName() {
return name;
}
public List<Map<String, Double>> getBundles() {
return bundles;
}
public PlacementStrategy getStrategy() {
return strategy;
}
/** The inner class for building PlacementGroupCreationOptions. */
public static class Builder {
private String name;
private List<Map<String, Double>> bundles;
private PlacementStrategy strategy;
/**
* Set the name of a named placement group. This named placement group is accessible in this
* namespace by this name via {@link Ray#getPlacementGroup(java.lang.String)} or in other
* namespaces via {@link PlacementGroups#getPlacementGroup(java.lang.String, java.lang.String)}.
*
* @param name The name of the named placement group.
* @return self
*/
public Builder setName(String name) {
if (this.name != null) {
throw new IllegalArgumentException("Repeated assignment of the name is not allowed!");
}
this.name = name;
return this;
}
/**
* Set the Pre-allocated resource list. Bundle is a collection of resources used to reserve
* resources on the raylet side.
*
* @param bundles The Pre-allocated resource list.
* @return self
*/
public Builder setBundles(List<Map<String, Double>> bundles) {
this.bundles = bundles;
return this;
}
/**
* Set the placement strategy used to control the placement relationship between bundles. More
* details refer to {@link PlacementStrategy}
*
* @param strategy The placement strategy between bundles.
* @return self
*/
public Builder setStrategy(PlacementStrategy strategy) {
this.strategy = strategy;
return this;
}
public PlacementGroupCreationOptions build() {
return new PlacementGroupCreationOptions(name, bundles, strategy);
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
package io.ray.api.parallelactor;
/**
* The `ParallelActor` is used for creating multiple execution instances in different threads, to
* execute the methods. The methods will be invoked on the instances in different threads.
*/
public class ParallelActor extends Call {}
@@ -0,0 +1,13 @@
package io.ray.api.parallelactor;
import io.ray.api.ObjectRef;
import io.ray.api.function.RayFunc;
import io.ray.api.function.RayFuncR;
public interface ParallelActorContext {
<A> ParallelActorHandle<A> createParallelActorExecutor(int parallelism, RayFuncR<A> ctorFunc);
<A, R> ObjectRef<R> submitTask(
ParallelActorHandle<A> parallelActorHandle, int instanceId, RayFunc func, Object[] args);
}
@@ -0,0 +1,28 @@
package io.ray.api.parallelactor;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncR;
public class ParallelActorCreator<A> {
private int parallelism = 1;
private RayFuncR<A> func;
private Object[] args;
public ParallelActorCreator(RayFuncR<A> func, Object[] args) {
this.func = func;
this.args = args;
}
public ParallelActorCreator<A> setParallelism(int parallelism) {
this.parallelism = parallelism;
return this;
}
public ParallelActorHandle<A> remote() {
ParallelActorContext ctx = Ray.internal().getParallelActorContext();
return ctx.createParallelActorExecutor(parallelism, this.func);
}
}
@@ -0,0 +1,16 @@
package io.ray.api.parallelactor;
import io.ray.api.ActorHandle;
/** The handle to a parallel actor. */
public interface ParallelActorHandle<A> {
/** Get an execution instance of the parallel actor by the given instance ID. */
ParallelActorInstance<A> getInstance(int instanceId);
/** Get the parallelism of this parallel actor. */
int getParallelism();
/** Get the real actor handle to use. */
ActorHandle<?> getHandle();
}
@@ -0,0 +1,21 @@
package io.ray.api.parallelactor;
public class ParallelActorInstance<A> implements ActorCall<A> {
private ParallelActorHandle<A> parallelActorHandle;
private int instanceId;
public ParallelActorInstance(ParallelActorHandle<A> parallelActorHandle, int instanceId) {
this.parallelActorHandle = parallelActorHandle;
this.instanceId = instanceId;
}
ParallelActorHandle<A> getActor() {
return parallelActorHandle;
}
int getInstanceId() {
return instanceId;
}
}
@@ -0,0 +1,25 @@
package io.ray.api.parallelactor;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncR;
public class ParallelActorTaskCaller<R> {
private ParallelActorInstance instance;
private RayFuncR<R> func;
private Object[] args;
public ParallelActorTaskCaller(ParallelActorInstance instance, RayFuncR<R> func, Object[] args) {
this.instance = instance;
this.func = func;
this.args = args;
}
public ObjectRef<R> remote() {
ParallelActorContext ctx = Ray.internal().getParallelActorContext();
return ctx.submitTask(instance.getActor(), instance.getInstanceId(), func, args);
}
}
@@ -0,0 +1,25 @@
package io.ray.api.parallelactor;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncVoid;
public class VoidParallelActorTaskCaller {
private ParallelActorInstance instance;
private RayFuncVoid func;
private Object[] args;
public VoidParallelActorTaskCaller(
ParallelActorInstance instance, RayFuncVoid func, Object[] args) {
this.instance = instance;
this.func = func;
this.args = args;
}
public void remote() {
ParallelActorContext ctx = Ray.internal().getParallelActorContext();
ctx.submitTask(instance.getActor(), instance.getInstanceId(), func, args);
}
}
@@ -0,0 +1,57 @@
package io.ray.api.placementgroup;
import io.ray.api.id.PlacementGroupId;
import java.util.List;
import java.util.Map;
/**
* A placement group is used to place interdependent actors according to a specific strategy {@link
* PlacementStrategy}. When a placement group is created, the corresponding actor slots and
* resources are preallocated. A placement group consists of one or more bundles plus a specific
* placement strategy.
*/
public interface PlacementGroup {
/**
* Get the id of current placement group.
*
* @return Id of current placement group.
*/
PlacementGroupId getId();
/**
* Get the name of current placement group.
*
* @return Name of current placement group.
*/
String getName();
/**
* Get all bundles which key is resource name and value is resource value.
*
* @return All bundles of current placement group.
*/
List<Map<String, Double>> getBundles();
/**
* Get the strategy of current placement group.
*
* @return Strategy of current placement group.
*/
PlacementStrategy getStrategy();
/**
* Get the state of current placement group.
*
* @return Creation state of current placement group.
*/
PlacementGroupState getState();
/**
* Wait for the placement group to be ready within the specified time.
*
* @param timeoutSeconds Timeout in seconds.
* @return True if the placement group is created. False otherwise.
*/
boolean wait(int timeoutSeconds);
}
@@ -0,0 +1,30 @@
package io.ray.api.placementgroup;
/** State of placement group. */
public enum PlacementGroupState {
/** Wait for resource to schedule. */
PENDING(0),
/** The placement group has created on some node. */
CREATED(1),
/** The placement group has removed. */
REMOVED(2),
/** The placement group is rescheduling. */
RESCHEDULING(3),
/** Unrecognized state. */
UNRECOGNIZED(-1);
private int value = 0;
PlacementGroupState(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}
@@ -0,0 +1,32 @@
package io.ray.api.placementgroup;
/** The actor placement strategy. */
public enum PlacementStrategy {
/** Packs Bundles close together inside nodes as tight as possible. */
PACK(0),
/** Places Bundles across distinct nodes as even as possible. */
SPREAD(1),
/** Packs Bundles into one node. The group is not allowed to span multiple nodes. */
STRICT_PACK(2),
/**
* Places Bundles across distinct nodes. The group is not allowed to deploy more than one bundle
* on a node.
*/
STRICT_SPREAD(3),
/** Unrecognized strategy. */
UNRECOGNIZED(-1);
private int value = 0;
PlacementStrategy(int value) {
this.value = value;
}
public int value() {
return this.value;
}
}
@@ -0,0 +1,293 @@
package io.ray.api.runtime;
import io.ray.api.ActorHandle;
import io.ray.api.BaseActorHandle;
import io.ray.api.CppActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.PyActorHandle;
import io.ray.api.WaitResult;
import io.ray.api.concurrencygroup.ConcurrencyGroup;
import io.ray.api.exception.RuntimeEnvException;
import io.ray.api.function.CppActorClass;
import io.ray.api.function.CppActorMethod;
import io.ray.api.function.CppFunction;
import io.ray.api.function.PyActorClass;
import io.ray.api.function.PyActorMethod;
import io.ray.api.function.PyFunction;
import io.ray.api.function.RayFunc;
import io.ray.api.function.RayFuncR;
import io.ray.api.id.ActorId;
import io.ray.api.id.PlacementGroupId;
import io.ray.api.id.UniqueId;
import io.ray.api.options.ActorCreationOptions;
import io.ray.api.options.CallOptions;
import io.ray.api.options.PlacementGroupCreationOptions;
import io.ray.api.parallelactor.ParallelActorContext;
import io.ray.api.placementgroup.PlacementGroup;
import io.ray.api.runtimecontext.ResourceValue;
import io.ray.api.runtimecontext.RuntimeContext;
import io.ray.api.runtimeenv.RuntimeEnv;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/** Base interface of a Ray runtime. */
public interface RayRuntime {
/** Shutdown the runtime. */
void shutdown();
/**
* Store an object in the object store.
*
* @param obj The Java object to be stored.
* @return A ObjectRef instance that represents the in-store object.
*/
<T> ObjectRef<T> put(T obj);
/**
* Get an object from the object store.
*
* @param objectRef The reference of the object to get.
* @return The Java object.
*/
<T> T get(ObjectRef<T> objectRef);
/**
* Get a list of objects from the object store.
*
* @param objectRefs The list of object references.
* @return A list of Java objects.
*/
<T> List<T> get(List<ObjectRef<T>> objectRefs);
/**
* Get an object from the object store.
*
* @param objectRef The reference of the object to get.
* @param timeoutMs The maximum amount of time in millseconds to wait before returning.
* @return The Java object.
* @throws RayTimeoutException If it's timeout to get the object.
*/
<T> T get(ObjectRef<T> objectRef, long timeoutMs);
/**
* Get a list of objects from the object store.
*
* @param objectRefs The list of object references.
* @param timeoutMs The maximum amount of time in millseconds to wait before returning.
* @return A list of Java objects.
* @throws RayTimeoutException If it's timeout to get the object.
*/
<T> List<T> get(List<ObjectRef<T>> objectRefs, long timeoutMs);
/**
* Wait for a list of RayObjects to be available, until specified number of objects are ready, or
* specified timeout has passed.
*
* @param waitList A list of ObjectRef to wait for.
* @param numReturns The number of objects that should be returned.
* @param timeoutMs The maximum time in milliseconds to wait before returning.
* @param fetchLocal If true, wait for the object to be downloaded onto the local node before
* returning it as ready. If false, ray.wait() will not trigger fetching of objects to the
* local node and will return immediately once the object is available anywhere in the
* cluster.
* @return Two lists, one containing locally available objects, one containing the rest.
*/
<T> WaitResult<T> wait(
List<ObjectRef<T>> waitList, int numReturns, int timeoutMs, boolean fetchLocal);
/**
* Free a list of objects from Plasma Store.
*
* @param objectRefs The object references to free.
* @param localOnly Whether only free objects for local object store or not.
*/
void free(List<ObjectRef<?>> objectRefs, boolean localOnly);
<T extends BaseActorHandle> T getActorHandle(ActorId actorId);
/**
* Get a handle to a named actor.
*
* <p>Gets a handle to a named actor with the given name. The actor must have been created with
* name specified.
*
* @param name The name of the named actor.
* @param namespace The namespace of the actor.
* @return ActorHandle to the actor.
*/
<T extends BaseActorHandle> Optional<T> getActor(String name, String namespace);
/**
* Kill the actor immediately.
*
* @param actor The actor to be killed.
* @param noRestart If set to true, the killed actor will not be restarted anymore.
*/
void killActor(BaseActorHandle actor, boolean noRestart);
/**
* Invoke a remote function.
*
* @param func The remote function to run.
* @param args The arguments of the remote function.
* @param options The options for this call.
* @return The result object.
*/
ObjectRef call(RayFunc func, Object[] args, CallOptions options);
/**
* Invoke a remote Python function.
*
* @param pyFunction The Python function.
* @param args Arguments of the function.
* @param options The options for this call.
* @return The result object.
*/
ObjectRef call(PyFunction pyFunction, Object[] args, CallOptions options);
ObjectRef call(CppFunction cppFunction, Object[] args, CallOptions options);
/**
* Invoke a remote function on an actor.
*
* @param actor A handle to the actor.
* @param func The remote function to run, it must be a method of the given actor.
* @param args The arguments of the remote function.
* @return The result object.
*/
ObjectRef callActor(ActorHandle<?> actor, RayFunc func, Object[] args, CallOptions options);
/**
* Invoke a remote Python function on an actor.
*
* @param pyActor A handle to the actor.
* @param pyActorMethod The actor method.
* @param args Arguments of the function.
* @return The result object.
*/
ObjectRef callActor(PyActorHandle pyActor, PyActorMethod pyActorMethod, Object[] args);
/**
* Invoke a remote Cpp function on an actor.
*
* @param cppActor A handle to the actor.
* @param cppActorMethod The actor method.
* @param args Arguments of the function.
* @return The result object.
*/
ObjectRef callActor(CppActorHandle cppActor, CppActorMethod cppActorMethod, Object[] args);
/**
* Create an actor on a remote node.
*
* @param actorFactoryFunc A remote function whose return value is the actor object.
* @param args The arguments for the remote function.
* @param <T> The type of the actor object.
* @param options The options for creating actor.
* @return A handle to the actor.
*/
<T> ActorHandle<T> createActor(
RayFunc actorFactoryFunc, Object[] args, ActorCreationOptions options);
/**
* Create a Python actor on a remote node.
*
* @param pyActorClass The Python actor class.
* @param args Arguments of the actor constructor.
* @param options The options for creating actor.
* @return A handle to the actor.
*/
PyActorHandle createActor(PyActorClass pyActorClass, Object[] args, ActorCreationOptions options);
/**
* Create a Cpp actor on a remote node.
*
* @param cppActorClass The Cpp actor class.
* @param args Arguments of the actor constructor.
* @param options The options for creating actor.
* @return A handle to the actor.
*/
CppActorHandle createActor(
CppActorClass cppActorClass, Object[] args, ActorCreationOptions options);
/**
* Create a placement group on remote nodes.
*
* @param creationOptions Creation options of the placement group.
* @return A handle to the created placement group.
*/
PlacementGroup createPlacementGroup(PlacementGroupCreationOptions creationOptions);
RuntimeContext getRuntimeContext();
/** Intentionally exit the current actor. */
void exitActor();
/**
* Get the resources available on this worker. Note that this API doesn't work on driver.
*
* @return The resource info of one node.
*/
Map<String, List<ResourceValue>> getAvailableResourceIds();
/** Get the namespace of this job. */
String getNamespace();
UniqueId getCurrentNodeId();
/**
* Get a placement group by id.
*
* @param id placement group id.
* @return The placement group.
*/
PlacementGroup getPlacementGroup(PlacementGroupId id);
/**
* Get a placement group by name.
*
* @param name The name of the placement group.
* @param namespace The namespace of the placement group.
* @return The placement group.
*/
PlacementGroup getPlacementGroup(String name, String namespace);
/**
* Get all placement groups in this cluster.
*
* @return All placement groups.
*/
List<PlacementGroup> getAllPlacementGroups();
/**
* Remove a placement group by id.
*
* @param id Id of the placement group.
*/
void removePlacementGroup(PlacementGroupId id);
/**
* Wait for the placement group to be ready within the specified time.
*
* @param id Id of placement group.
* @param timeoutSeconds Timeout in seconds.
* @return True if the placement group is created. False otherwise.
*/
boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutSeconds);
/** Create concurrency group instance at runtime. */
ConcurrencyGroup createConcurrencyGroup(String name, int maxConcurrency, List<RayFunc> funcs);
List<ConcurrencyGroup> extractConcurrencyGroups(RayFuncR<?> actorConstructorLambda);
/** Create runtime env instance at runtime. */
RuntimeEnv createRuntimeEnv();
/** Deserialize runtime env instance at runtime. */
RuntimeEnv deserializeRuntimeEnv(String serializedRuntimeEnv) throws RuntimeEnvException;
/// Get the parallel actor context at runtime.
ParallelActorContext getParallelActorContext();
}
@@ -0,0 +1,7 @@
package io.ray.api.runtime;
/** A factory that produces a RayRuntime instance. */
public interface RayRuntimeFactory {
RayRuntime createRayRuntime();
}
@@ -0,0 +1,24 @@
package io.ray.api.runtimecontext;
import io.ray.api.id.ActorId;
public class ActorInfo {
public final ActorId actorId;
public final ActorState state;
public final long numRestarts;
public final Address address;
public final String name;
public ActorInfo(
ActorId actorId, ActorState state, long numRestarts, Address address, String name) {
this.actorId = actorId;
this.state = state;
this.numRestarts = numRestarts;
this.address = address;
this.name = name;
}
}
@@ -0,0 +1,44 @@
package io.ray.api.runtimecontext;
/** The state of an actor. Note, this class should be aligned with the actor state of proto. */
public enum ActorState {
DEPENDENCIES_UNREADY("DEPENDENCIES_UNREADY", 0),
PENDING_CREATION("PENDING_CREATION", 1),
ALIVE("ALIVE", 2),
RESTARTING("RESTARTING", 3),
DEAD("DEAD", 4);
private String name;
private int value;
private ActorState(String name, int value) {
this.name = name;
this.value = value;
}
public static ActorState fromValue(int value) {
switch (value) {
case 0:
return DEPENDENCIES_UNREADY;
case 1:
return PENDING_CREATION;
case 2:
return ALIVE;
case 3:
return RESTARTING;
case 4:
return DEAD;
default:
throw new RuntimeException("Value out of range.");
}
}
public String getName() {
return name;
}
public int getValue() {
return value;
}
}
@@ -0,0 +1,35 @@
package io.ray.api.runtimecontext;
import io.ray.api.id.UniqueId;
import java.util.Objects;
public class Address {
public final UniqueId nodeId;
public final String ip;
public final int port;
public Address(UniqueId nodeId, String ip, int port) {
this.nodeId = nodeId;
this.ip = ip;
this.port = port;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!this.getClass().equals(obj.getClass())) {
return false;
}
Address other = (Address) obj;
return this.nodeId.equals(other.nodeId) && this.ip.equals(other.ip) && this.port == other.port;
}
@Override
public int hashCode() {
return Objects.hash(nodeId, ip, port);
}
}
@@ -0,0 +1,67 @@
package io.ray.api.runtimecontext;
import io.ray.api.id.UniqueId;
import java.util.Map;
/** A class that represents the information of a node. */
public class NodeInfo {
public final UniqueId nodeId;
public final String nodeAddress;
public final String nodeHostname;
public final int nodeManagerPort;
public final String objectStoreSocketName;
public final String rayletSocketName;
public final boolean isAlive;
public final Map<String, Double> resources;
public final Map<String, String> labels;
public NodeInfo(
UniqueId nodeId,
String nodeAddress,
String nodeHostname,
int nodeManagerPort,
String objectStoreSocketName,
String rayletSocketName,
boolean isAlive,
Map<String, Double> resources,
Map<String, String> labels) {
this.nodeId = nodeId;
this.nodeAddress = nodeAddress;
this.nodeHostname = nodeHostname;
this.nodeManagerPort = nodeManagerPort;
this.objectStoreSocketName = objectStoreSocketName;
this.rayletSocketName = rayletSocketName;
this.isAlive = isAlive;
this.resources = resources;
this.labels = labels;
}
public String toString() {
return "NodeInfo{"
+ "nodeId='"
+ nodeId
+ '\''
+ ", nodeAddress='"
+ nodeAddress
+ "\'"
+ ", nodeHostname'"
+ nodeHostname
+ "\'"
+ ", isAlive="
+ isAlive
+ ", resources="
+ resources
+ ", labels="
+ labels
+ "}";
}
}
@@ -0,0 +1,14 @@
package io.ray.api.runtimecontext;
/** A class that contains resource id and capacity of this resource. */
public class ResourceValue {
public final Long resourceId;
public final Double capacity;
ResourceValue(long resourceId, double capacity) {
this.resourceId = resourceId;
this.capacity = capacity;
}
}
@@ -0,0 +1,63 @@
package io.ray.api.runtimecontext;
import io.ray.api.BaseActorHandle;
import io.ray.api.id.ActorId;
import io.ray.api.id.JobId;
import io.ray.api.id.TaskId;
import io.ray.api.id.UniqueId;
import io.ray.api.runtimeenv.RuntimeEnv;
import java.util.List;
/** A class used for getting information of Ray runtime. */
public interface RuntimeContext {
/** Get the current Job ID. */
JobId getCurrentJobId();
/** Get current task ID. */
TaskId getCurrentTaskId();
/**
* Get the current actor ID.
*
* <p>Note, this can only be called in actors.
*/
ActorId getCurrentActorId();
/** Returns true if the current actor was restarted, otherwise false. */
boolean wasCurrentActorRestarted();
/** Returns true if Ray is running in local mode, false if Ray is running in cluster mode. */
boolean isLocalMode();
/** Get all node information in Ray cluster. */
List<NodeInfo> getAllNodeInfo();
/**
* Get all actor information of Ray cluster. Note that this will return all actor information of
* all jobs in this Ray cluster.
*/
List<ActorInfo> getAllActorInfo();
/** Get all actor information of Ray cluster filtered by job id or actor state. */
public List<ActorInfo> getAllActorInfo(JobId jobId, ActorState actorState);
/**
* Get the handle to the current actor itself. Note that this method must be invoked in an actor.
*/
<T extends BaseActorHandle> T getCurrentActorHandle();
/** Get available GPU(deviceIds) for this worker. */
List<Long> getGpuIds();
/** Get the namespace of this job. */
String getNamespace();
/** Get the node id of this worker. */
UniqueId getCurrentNodeId();
/**
* Get the runtime env of this worker. If it is a driver, job level runtime env will be returned.
*/
RuntimeEnv getCurrentRuntimeEnv();
}
@@ -0,0 +1,121 @@
package io.ray.api.runtimeenv;
import io.ray.api.Ray;
import io.ray.api.exception.RuntimeEnvException;
import io.ray.api.runtimeenv.types.RuntimeEnvName;
/** This class provides interfaces of setting runtime environments for job/actor/task. */
public interface RuntimeEnv {
/**
* Set a runtime env field by name and Object.
*
* @param name The build-in names or a runtime env plugin name.
* @see RuntimeEnvName
* @param value An object with primitive data type or plain old java object(POJO).
* @throws RuntimeEnvException
*/
void set(String name, Object value) throws RuntimeEnvException;
/**
* Set a runtime env field by name and json string.
*
* @param name The build-in names or a runtime env plugin name.
* @see RuntimeEnvName
* @param jsonStr A json string represents the runtime env field.
* @throws RuntimeEnvException
*/
public void setJsonStr(String name, String jsonStr) throws RuntimeEnvException;
/**
* Get the object of a runtime env field.
*
* @param name The build-in names or a runtime env plugin name.
* @param classOfT The class of a primitive data type or plain old java object(POJO) type.
* @return
* @param <T> A primitive data type or plain old java object(POJO) type.
* @throws RuntimeEnvException
*/
public <T> T get(String name, Class<T> classOfT) throws RuntimeEnvException;
/**
* Get the json string of a runtime env field.
*
* @param name The build-in names or a runtime env plugin name.
* @return A json string represents the runtime env field.
* @throws RuntimeEnvException
*/
public String getJsonStr(String name) throws RuntimeEnvException;
/**
* Whether a field is contained.
*
* @param name The runtime env plugin name.
* @return
*/
boolean contains(String name);
/**
* Remove a runtime env field by name.
*
* @param name The build-in names or a runtime env plugin name.
* @return true if remove an existing field, otherwise false.
* @throws RuntimeEnvException
*/
public boolean remove(String name) throws RuntimeEnvException;
/**
* Serialize the runtime env to string.
*
* @return The serialized runtime env string.
* @throws RuntimeEnvException
*/
public String serialize() throws RuntimeEnvException;
/**
* Whether the runtime env is empty.
*
* @return
*/
boolean isEmpty();
/**
* Serialize the runtime env to string of RuntimeEnvInfo.
*
* @return The serialized runtime env info string.
* @throws RuntimeEnvException
*/
public String serializeToRuntimeEnvInfo() throws RuntimeEnvException;
/**
* Deserialize the runtime env from string.
*
* @param serializedRuntimeEnv The serialized runtime env string.
* @return The deserialized RuntimeEnv instance.
* @throws RuntimeEnvException
*/
public static RuntimeEnv deserialize(String serializedRuntimeEnv) throws RuntimeEnvException {
return Ray.internal().deserializeRuntimeEnv(serializedRuntimeEnv);
}
/**
* Set runtime env config.
*
* @param runtimeEnvConfig
*/
public void setConfig(RuntimeEnvConfig runtimeEnvConfig);
/**
* Get runtime env config.
*
* @return The runtime env config.
*/
public RuntimeEnvConfig getConfig();
/** The builder which is used to generate a RuntimeEnv instance. */
public static class Builder {
public RuntimeEnv build() {
return Ray.internal().createRuntimeEnv();
}
}
}

Some files were not shown because too many files have changed in this diff Show More