diff --git a/java/api/src/main/java/io/ray/api/Ray.java b/java/api/src/main/java/io/ray/api/Ray.java index c29a9420d..c4044486e 100644 --- a/java/api/src/main/java/io/ray/api/Ray.java +++ b/java/api/src/main/java/io/ray/api/Ray.java @@ -7,6 +7,7 @@ import io.ray.api.runtime.RayRuntimeFactory; import io.ray.api.runtimecontext.RuntimeContext; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.concurrent.Callable; /** @@ -137,6 +138,34 @@ public final class Ray extends RayCall { return runtime.wait(waitList, waitList.size(), Integer.MAX_VALUE); } + /** + * Get a handle to a named actor of current job. + *
+ * 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.
+ * @return an ActorHandle to the actor if the actor of specified name exists or an
+ * Optional.empty()
+ */
+ public static
+ * Gets a handle to a global named actor with the given name. The actor must
+ * have been created with global name specified.
+ *
+ * @param name The global name of the named actor.
+ * @return an ActorHandle to the actor if the actor of specified name exists or an
+ * Optional.empty()
+ */
+ public static
* The max concurrency defaults to 1 for threaded execution.
* Note that the execution order is not guaranteed when max_concurrency > 1.
*
diff --git a/java/api/src/main/java/io/ray/api/options/ActorCreationOptions.java b/java/api/src/main/java/io/ray/api/options/ActorCreationOptions.java
index 53be5c6b4..363e915e9 100644
--- a/java/api/src/main/java/io/ray/api/options/ActorCreationOptions.java
+++ b/java/api/src/main/java/io/ray/api/options/ActorCreationOptions.java
@@ -1,5 +1,6 @@
package io.ray.api.options;
+import io.ray.api.Ray;
import java.util.HashMap;
import java.util.Map;
@@ -7,15 +8,17 @@ import java.util.Map;
* The options for creating actor.
*/
public class ActorCreationOptions extends BaseTaskOptions {
+ public final boolean global;
+ public final String name;
public final int maxRestarts;
-
public final String jvmOptions;
-
public final int maxConcurrency;
- private ActorCreationOptions(Map
* 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.
@@ -86,7 +119,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
/**
* Set the max number of concurrent calls to allow for this actor.
- *
+ *
* The max concurrency defaults to 1 for threaded execution.
* Note that the execution order is not guaranteed when max_concurrency > 1.
*
@@ -104,7 +137,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
public ActorCreationOptions build() {
return new ActorCreationOptions(
- resources, maxRestarts, jvmOptions, maxConcurrency);
+ global, name, resources, maxRestarts, jvmOptions, maxConcurrency);
}
}
diff --git a/java/api/src/main/java/io/ray/api/runtime/RayRuntime.java b/java/api/src/main/java/io/ray/api/runtime/RayRuntime.java
index 07222790e..318b880e8 100644
--- a/java/api/src/main/java/io/ray/api/runtime/RayRuntime.java
+++ b/java/api/src/main/java/io/ray/api/runtime/RayRuntime.java
@@ -9,12 +9,14 @@ 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.id.ActorId;
import io.ray.api.id.ObjectId;
import io.ray.api.id.UniqueId;
import io.ray.api.options.ActorCreationOptions;
import io.ray.api.options.CallOptions;
import io.ray.api.runtimecontext.RuntimeContext;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.Callable;
/**
@@ -82,6 +84,20 @@ public interface RayRuntime {
*/
void setResource(String resourceName, double capacity, UniqueId nodeId);
+
+ * 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 global Whether the named actor is global.
+ * @return ActorHandle to the actor.
+ */
+