[Java] Format ray java code (#13056)

This commit is contained in:
chaokunyang
2020-12-29 10:36:16 +08:00
committed by GitHub
parent cc1c2c3dc9
commit d1dd3410c8
422 changed files with 4384 additions and 5035 deletions
@@ -1,11 +1,12 @@
package io.ray.api;
/**
* A handle to a Java actor. <p>
* A handle to a Java actor.
*
* A handle can be used to invoke a remote actor method, with the {@code "call"} method. For
* <p>A handle can be used to invoke a remote actor method, with the {@code "call"} method. For
* example:
* <pre> {@code
*
* <pre>{@code
* class MyActor {
* public int echo(int x) {
* return x;
@@ -19,11 +20,9 @@ package io.ray.api;
* Assert.assertEqual(result.get(), 1);
* }</pre>
*
* Note, the {@code "call"} method is defined in {@link ActorCall} interface, with multiple
* <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> {
}
public interface ActorHandle<A> extends BaseActorHandle, ActorCall<A> {}
@@ -3,15 +3,13 @@ package io.ray.api;
import io.ray.api.id.ActorId;
/**
* A handle to an actor. <p>
* A handle to an actor.
*
* A handle can be used to invoke a remote actor method.
* <p>A handle can be used to invoke a remote actor method.
*/
public interface BaseActorHandle {
/**
* @return The id of this actor.
*/
/** Returns the id of this actor. */
ActorId getId();
/**
@@ -2,15 +2,14 @@ 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.
* Fetch the object from the object store, this method will block until the object is locally
* available.
*/
T get();
}
@@ -1,18 +1,11 @@
package io.ray.api;
/**
* Handle of a Python actor.
*/
/** Handle of a Python actor. */
public interface PyActorHandle extends BaseActorHandle, PyActorCall {
/**
* @return Module name of the Python actor class.
*/
/** Returns the module name of the Python actor class. */
String getModuleName();
/**
* @return Name of the Python actor class.
*/
/** Returns the name of the Python actor class. */
String getClassName();
}
+59 -83
View File
@@ -12,16 +12,12 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
/**
* This class contains all public APIs of Ray.
*/
/** 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.
*/
/** Initialize Ray runtime with the default runtime implementation. */
public static void init() {
try {
Class clz = Class.forName("io.ray.runtime.DefaultRayRuntimeFactory");
@@ -30,7 +26,6 @@ public final class Ray extends RayCall {
} catch (Exception e) {
throw new RuntimeException("Failed to initialize Ray runtime.", e);
}
}
/**
@@ -45,9 +40,7 @@ public final class Ray extends RayCall {
}
}
/**
* Shutdown Ray runtime.
*/
/** Shutdown Ray runtime. */
public static synchronized void shutdown() {
if (runtime != null) {
internal().shutdown();
@@ -57,7 +50,8 @@ public final class Ray extends RayCall {
/**
* Check if {@link #init} has been called yet.
* @return True if {@link #init} has already been called and false otherwise.
*
* <p>Returns True if {@link #init} has already been called and false otherwise.
*/
public static boolean isInitialized() {
return runtime != null;
@@ -66,8 +60,8 @@ public final class Ray extends RayCall {
/**
* 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.
* @param obj The Java object to be stored. Returns A ObjectRef instance that represents the
* in-store object.
*/
public static <T> ObjectRef<T> put(T obj) {
return internal().put(obj);
@@ -76,8 +70,7 @@ public final class Ray extends RayCall {
/**
* Get an object by `ObjectRef` from the object store.
*
* @param objectRef The reference of the object to get.
* @return The Java object.
* @param objectRef The reference of the object to get. Returns The Java object.
*/
public static <T> T get(ObjectRef<T> objectRef) {
return internal().get(objectRef);
@@ -86,45 +79,43 @@ public final class Ray extends RayCall {
/**
* 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.
* @param objectList A list of object references. Returns 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 locally available,
* until specified number of objects are ready, or specified timeout has passed.
* 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.
* @param timeoutMs The maximum time in milliseconds to wait before returning. Returns 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) {
public static <T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns, int timeoutMs) {
return internal().wait(waitList, numReturns, timeoutMs);
}
/**
* A convenient helper method for Ray.wait. It will wait infinitely until
* specified number of objects are locally available.
* A convenient helper method for Ray.wait. It will wait infinitely until specified number of
* objects are locally available.
*
* @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.
* @param numReturns The number of objects that should be returned. Returns Two lists, one
* containing locally available objects, one containing the rest.
*/
public static <T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns) {
return internal().wait(waitList, numReturns, Integer.MAX_VALUE);
}
/**
* A convenient helper method for Ray.wait. It will wait infinitely until
* all objects are locally available.
* A convenient helper method for Ray.wait. It will wait infinitely until all objects are locally
* available.
*
* @param waitList A list of object references to wait for.
* @return Two lists, one containing locally available objects, one containing the rest.
* @param waitList A list of object references to wait for. Returns Two lists, one containing
* locally available objects, one containing the rest.
*/
public static <T> WaitResult<T> wait(List<ObjectRef<T>> waitList) {
return internal().wait(waitList, waitList.size(), Integer.MAX_VALUE);
@@ -132,13 +123,12 @@ public final class Ray extends RayCall {
/**
* Get a handle to a named actor of current job.
* <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.
* @return an ActorHandle to the actor if the actor of specified name exists or an
* Optional.empty()
* <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. Returns an ActorHandle to the actor if the actor of
* specified name exists or an Optional.empty()
*/
public static <T extends BaseActorHandle> Optional<T> getActor(String name) {
return internal().getActor(name, false);
@@ -146,13 +136,12 @@ public final class Ray extends RayCall {
/**
* Get a handle to a global named actor.
* <p>
* 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()
* <p>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. Returns an ActorHandle to the actor if the
* actor of specified name exists or an Optional.empty()
*/
public static <T extends BaseActorHandle> Optional<T> getGlobalActor(String name) {
return internal().getActor(name, true);
@@ -162,7 +151,7 @@ public final class Ray extends RayCall {
* If users want to use Ray API in their own threads, call this method to get the async context
* and then call {@link #setAsyncContext} at the beginning of the new thread.
*
* @return The async context.
* <p>Returns The async context.
*/
public static Object getAsyncContext() {
return internal().getAsyncContext();
@@ -186,8 +175,7 @@ public final class Ray extends RayCall {
* If users want to use Ray API in their own threads, they should wrap their {@link Runnable}
* objects with this method.
*
* @param runnable The runnable to wrap.
* @return The wrapped runnable.
* @param runnable The runnable to wrap. Returns The wrapped runnable.
*/
public static Runnable wrapRunnable(Runnable runnable) {
return internal().wrapRunnable(runnable);
@@ -197,16 +185,13 @@ public final class Ray extends RayCall {
* If users want to use Ray API in their own threads, they should wrap their {@link Callable}
* objects with this method.
*
* @param callable The callable to wrap.
* @return The wrapped callable.
* @param callable The callable to wrap. Returns The wrapped callable.
*/
public static <T> Callable<T> wrapCallable(Callable<T> callable) {
return internal().wrapCallable(callable);
}
/**
* Get the underlying runtime instance.
*/
/** Get the underlying runtime instance. */
public static RayRuntime internal() {
if (runtime == null) {
throw new IllegalStateException(
@@ -215,59 +200,49 @@ public final class Ray extends RayCall {
return runtime;
}
/**
* Update the resource for the specified client.
* Set the resource for the specific node.
*/
/** Update the resource for the specified client. Set the resource for the specific node. */
public static void setResource(UniqueId nodeId, String resourceName, double capacity) {
internal().setResource(resourceName, capacity, nodeId);
}
/**
* Set the resource for local node.
*/
/** Set the resource for local node. */
public static void setResource(String resourceName, double capacity) {
internal().setResource(resourceName, capacity, UniqueId.NIL);
}
/**
* Get the runtime context.
*/
/** Get the runtime context. */
public static RuntimeContext getRuntimeContext() {
return internal().getRuntimeContext();
}
/**
* 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.
* This function only works when gcs actor manager is turned on.
* 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. This function only works when gcs actor manager
* is turned on.
*
* @param name Name of the placement group.
* @param bundles Pre-allocated resource list.
* @param strategy Actor placement strategy.
* @return A handle to the created placement group.
* @param strategy Actor placement strategy. Returns A handle to the created placement group.
*/
public static PlacementGroup createPlacementGroup(String name,
List<Map<String, Double>> bundles, PlacementStrategy strategy) {
public static PlacementGroup createPlacementGroup(
String name, List<Map<String, Double>> bundles, PlacementStrategy strategy) {
return internal().createPlacementGroup(name, bundles, strategy);
}
public static PlacementGroup createPlacementGroup(List<Map<String, Double>> bundles,
PlacementStrategy strategy) {
public static PlacementGroup createPlacementGroup(
List<Map<String, Double>> bundles, PlacementStrategy strategy) {
return internal().createPlacementGroup(bundles, strategy);
}
/**
* 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.
* <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();
@@ -275,8 +250,8 @@ public final class Ray extends RayCall {
/**
* Get a placement group by placement group Id.
* @param id placement group id.
* @return The placement group.
*
* @param id placement group id. Returns The placement group.
*/
public static PlacementGroup getPlacementGroup(PlacementGroupId id) {
return internal().getPlacementGroup(id);
@@ -284,15 +259,16 @@ public final class Ray extends RayCall {
/**
* Get all placement groups in this cluster.
* @return All placement groups.
*
* <p>Returns All placement groups.
*/
public static List<PlacementGroup> getAllPlacementGroups() {
return internal().getAllPlacementGroups();
}
/**
* Remove a placement group by id.
* Throw RayException if remove failed.
* Remove a placement group by id. Throw RayException if remove failed.
*
* @param id Id of the placement group.
*/
public static void removePlacementGroup(PlacementGroupId id) {
@@ -3,8 +3,8 @@ 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.
* 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> {
@@ -16,18 +16,13 @@ public final class WaitResult<T> {
this.unready = unready;
}
/**
* Get the list of ready objects.
*/
/** Get the list of ready objects. */
public List<ObjectRef<T>> getReady() {
return ready;
}
/**
* Get the list of unready objects.
*/
/** Get the list of unready objects. */
public List<ObjectRef<T>> getUnready() {
return unready;
}
}
@@ -21,10 +21,9 @@ public class ActorCreator<A> extends BaseActorCreator<ActorCreator<A>> {
/**
* Set the JVM options for the Java worker that this actor is running in.
*
* Note, if this is set, this actor won't share Java worker with other actors or tasks.
* <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
* @param jvmOptions JVM options for the Java worker that this actor is running in. Returns self
* @see io.ray.api.options.ActorCreationOptions.Builder#setJvmOptions(java.lang.String)
*/
public ActorCreator<A> setJvmOptions(String jvmOptions) {
@@ -35,10 +34,9 @@ public class ActorCreator<A> extends BaseActorCreator<ActorCreator<A>> {
/**
* Create a java actor remotely and return a handle to the created actor.
*
* @return a handle to the created java actor.
* <p>Returns a handle to the created java actor.
*/
public ActorHandle<A> remote() {
return Ray.internal().createActor(func, args, buildOptions());
}
}
@@ -25,11 +25,10 @@ public class ActorTaskCaller<R> {
* 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.
* <p>Returns an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().callActor(actor, func, args);
}
}
@@ -14,13 +14,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
protected ActorCreationOptions.Builder builder = new ActorCreationOptions.Builder();
/**
* Set the actor name of a named actor.
* This named actor is only accessible from this job by this name via
* {@link Ray#getActor(java.lang.String)}. If you want create a named actor that is accessible
* from all jobs, use {@link BaseActorCreator#setGlobalName(java.lang.String)} instead.
* Set the actor name of a named actor. This named actor is only accessible from this job by this
* name via {@link Ray#getActor(java.lang.String)}. If you want create a named actor that is
* accessible from all jobs, use {@link BaseActorCreator#setGlobalName(java.lang.String)} instead.
*
* @param name The name of the named actor.
* @return self
* @param name The name of the named actor. Returns self
* @see io.ray.api.options.ActorCreationOptions.Builder#setName(String)
*/
public T setName(String name) {
@@ -29,12 +27,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
}
/**
* Set the name of this actor. This actor will be accessible from all jobs by this name via
* {@link Ray#getGlobalActor(java.lang.String)}. If you want to create a named actor that is
* only accessible from this job, use {@link BaseActorCreator#setName(java.lang.String)} instead.
* Set the name of this actor. This actor will be accessible from all jobs by this name via {@link
* Ray#getGlobalActor(java.lang.String)}. If you want to create a named actor that is only
* accessible from this job, use {@link BaseActorCreator#setName(java.lang.String)} instead.
*
* @param name The name of the named actor.
* @return self
* @param name The name of the named actor. Returns self
* @see io.ray.api.options.ActorCreationOptions.Builder#setGlobalName(String)
*/
public T setGlobalName(String name) {
@@ -43,13 +40,12 @@ public class BaseActorCreator<T extends BaseActorCreator> {
}
/**
* 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.
* 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
* @param resourceQuantity resource quantity Returns self
* @see ActorCreationOptions.Builder#setResource(java.lang.String, java.lang.Double)
*/
public T setResource(String resourceName, Double resourceQuantity) {
@@ -58,12 +54,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
}
/**
* 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.
* 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
* @param resources requirements for multiple resources. Returns self
* @see BaseActorCreator#setResources(java.util.Map)
*/
public T setResources(Map<String, Double> resources) {
@@ -76,8 +71,7 @@ public class BaseActorCreator<T extends BaseActorCreator> {
* 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
* @param maxRestarts max number of actor restarts Returns self
* @see ActorCreationOptions.Builder#setMaxRestarts(int)
*/
public T setMaxRestarts(int maxRestarts) {
@@ -87,12 +81,11 @@ public class BaseActorCreator<T extends BaseActorCreator> {
/**
* 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
* <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. Returns self
* @see ActorCreationOptions.Builder#setMaxConcurrency(int)
*/
public T setMaxConcurrency(int maxConcurrency) {
@@ -104,8 +97,7 @@ public class BaseActorCreator<T extends BaseActorCreator> {
* 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
* @param bundleIndex The index of the bundle to place this actor in. Returns self
* @see ActorCreationOptions.Builder#setPlacementGroup(PlacementGroup, int)
*/
public T setPlacementGroup(PlacementGroup group, int bundleIndex) {
@@ -121,5 +113,4 @@ public class BaseActorCreator<T extends BaseActorCreator> {
protected ActorCreationOptions buildOptions() {
return builder.build();
}
}
@@ -14,8 +14,7 @@ public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
/**
* Set a name for this task.
*
* @param name task name
* @return self
* @param name task name Returns self
* @see CallOptions.Builder#setName(java.lang.String)
*/
public T setName(String name) {
@@ -28,8 +27,7 @@ public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
* 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
* @param value resource capacity Returns self
* @see CallOptions.Builder#setResource(java.lang.String, java.lang.Double)
*/
public T setResource(String name, Double value) {
@@ -41,8 +39,7 @@ public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
* 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
* @param resources requirements for multiple resources. Returns self
* @see CallOptions.Builder#setResources(java.util.Map)
*/
public T setResources(Map<String, Double> resources) {
@@ -4,9 +4,7 @@ import io.ray.api.PyActorHandle;
import io.ray.api.Ray;
import io.ray.api.function.PyActorClass;
/**
* A helper to create python actor.
*/
/** A helper to create python actor. */
public class PyActorCreator extends BaseActorCreator<PyActorCreator> {
private final PyActorClass pyActorClass;
private final Object[] args;
@@ -19,7 +17,7 @@ public class PyActorCreator extends BaseActorCreator<PyActorCreator> {
/**
* Create a python actor remotely and return a handle to the created actor.
*
* @return a handle to the created python actor.
* <p>Returns a handle to the created python actor.
*/
public PyActorHandle remote() {
return Ray.internal().createActor(pyActorClass, args, buildOptions());
@@ -25,11 +25,10 @@ public class PyActorTaskCaller<R> {
* 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.
* <p>Returns an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().callActor(actor, method, args);
}
}
@@ -22,11 +22,10 @@ public class PyTaskCaller<R> extends BaseTaskCaller<PyTaskCaller<R>> {
* 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.
* <p>Returns an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
return Ray.internal().call(func, args, buildOptions());
}
}
@@ -22,7 +22,7 @@ public class TaskCaller<R> extends BaseTaskCaller<TaskCaller<R>> {
* 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.
* <p>Returns an object reference to an object in the object store.
*/
@SuppressWarnings("unchecked")
public ObjectRef<R> remote() {
@@ -4,9 +4,7 @@ import io.ray.api.ActorHandle;
import io.ray.api.Ray;
import io.ray.api.function.RayFuncVoid;
/**
* A helper to call java actor method which doesn't have a return value.
*/
/** 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;
@@ -18,11 +16,8 @@ public class VoidActorTaskCaller {
this.args = args;
}
/**
* Execute a function remotely.
*/
/** Execute a function remotely. */
public void remote() {
Ray.internal().callActor(actor, func, args);
}
}
@@ -3,9 +3,7 @@ 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.
*/
/** 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;
@@ -15,11 +13,8 @@ public class VoidTaskCaller extends BaseTaskCaller<VoidTaskCaller> {
this.args = args;
}
/**
* Execute a function remotely.
*/
/** Execute a function remotely. */
public void remote() {
Ray.internal().call(func, args, buildOptions());
}
}
@@ -38,11 +38,9 @@ public class PyActorClass {
* 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
* @param className The name of this actor class Returns a python actor class
*/
public static PyActorClass of(String moduleName, String className) {
return new PyActorClass(moduleName, className);
}
}
@@ -2,9 +2,9 @@ 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.
*
* <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.
@@ -43,8 +43,7 @@ public class PyActorMethod<R> {
/**
* Create a python actor method.
*
* @param methodName The name of this actor method
* @return a python actor method.
* @param methodName The name of this actor method Returns a python actor method.
*/
public static PyActorMethod<Object> of(String methodName) {
return of(methodName, Object.class);
@@ -55,11 +54,9 @@ public class PyActorMethod<R> {
*
* @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.
* @param <R> The type of the return value of this actor method Returns a python actor method.
*/
public static <R> PyActorMethod<R> of(String methodName, Class<R> returnType) {
return new PyActorMethod<>(methodName, returnType);
}
}
@@ -49,11 +49,9 @@ public class PyFunction<R> {
* Create a python function.
*
* @param moduleName The full module name of this function
* @param functionName The name of this function
* @return a python function.
* @param functionName The name of this function Returns a python function.
*/
public static PyFunction<Object> of(
String moduleName, String functionName) {
public static PyFunction<Object> of(String moduleName, String functionName) {
return of(moduleName, functionName, Object.class);
}
@@ -63,12 +61,9 @@ public class PyFunction<R> {
* @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.
* @param <R> Type of the return value of this function Returns a python function.
*/
public static <R> PyFunction<R> of(
String moduleName, String functionName, Class<R> returnType) {
public static <R> PyFunction<R> of(String moduleName, String functionName, Class<R> returnType) {
return new PyFunction<>(moduleName, functionName, returnType);
}
}
@@ -2,8 +2,5 @@ package io.ray.api.function;
import java.io.Serializable;
/**
* Base interface of all Ray remote java functions.
*/
public interface RayFunc extends Serializable {
}
/** Base interface of all Ray remote java functions. */
public interface RayFunc extends Serializable {}
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 0 parameter.
*/
/** Functional interface for a remote function that has 0 parameter. */
@FunctionalInterface
public interface RayFunc0<R> extends RayFuncR<R> {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 1 parameter.
*/
/** Functional interface for a remote function that has 1 parameter. */
@FunctionalInterface
public interface RayFunc1<T0, R> extends RayFuncR<R> {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 2 parameters.
*/
/** Functional interface for a remote function that has 2 parameters. */
@FunctionalInterface
public interface RayFunc2<T0, T1, R> extends RayFuncR<R> {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 3 parameters.
*/
/** Functional interface for a remote function that has 3 parameters. */
@FunctionalInterface
public interface RayFunc3<T0, T1, T2, R> extends RayFuncR<R> {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 4 parameters.
*/
/** Functional interface for a remote function that has 4 parameters. */
@FunctionalInterface
public interface RayFunc4<T0, T1, T2, T3, R> extends RayFuncR<R> {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 5 parameters.
*/
/** Functional interface for a remote function that has 5 parameters. */
@FunctionalInterface
public interface RayFunc5<T0, T1, T2, T3, T4, R> extends RayFuncR<R> {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 6 parameters.
*/
/** Functional interface for a remote function that has 6 parameters. */
@FunctionalInterface
public interface RayFunc6<T0, T1, T2, T3, T4, T5, R> extends RayFuncR<R> {
@@ -1,10 +1,8 @@
package io.ray.api.function;
/**
* Interface of all Ray remote functions which have a return value
* Interface of all Ray remote functions which have a return value.
*
* @param <R> Type of function return value
*/
public interface RayFuncR<R> extends RayFunc {
}
public interface RayFuncR<R> extends RayFunc {}
@@ -1,8 +1,4 @@
package io.ray.api.function;
/**
* Interface of all `RayFuncVoidX` classes.
*/
public interface RayFuncVoid extends RayFunc {
}
/** Interface of all `RayFuncVoidX` classes. */
public interface RayFuncVoid extends RayFunc {}
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 0 parameter.
*/
/** Functional interface for a remote function that has 0 parameter. */
@FunctionalInterface
public interface RayFuncVoid0 extends RayFuncVoid {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 1 parameter.
*/
/** Functional interface for a remote function that has 1 parameter. */
@FunctionalInterface
public interface RayFuncVoid1<T0> extends RayFuncVoid {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 2 parameters.
*/
/** Functional interface for a remote function that has 2 parameters. */
@FunctionalInterface
public interface RayFuncVoid2<T0, T1> extends RayFuncVoid {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 3 parameters.
*/
/** Functional interface for a remote function that has 3 parameters. */
@FunctionalInterface
public interface RayFuncVoid3<T0, T1, T2> extends RayFuncVoid {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 4 parameters.
*/
/** Functional interface for a remote function that has 4 parameters. */
@FunctionalInterface
public interface RayFuncVoid4<T0, T1, T2, T3> extends RayFuncVoid {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 5 parameters.
*/
/** Functional interface for a remote function that has 5 parameters. */
@FunctionalInterface
public interface RayFuncVoid5<T0, T1, T2, T3, T4> extends RayFuncVoid {
@@ -2,9 +2,7 @@
package io.ray.api.function;
/**
* Functional interface for a remote function that has 6 parameters.
*/
/** Functional interface for a remote function that has 6 parameters. */
@FunctionalInterface
public interface RayFuncVoid6<T0, T1, T2, T3, T4, T5> extends RayFuncVoid {
@@ -25,18 +25,14 @@ public class ActorId extends BaseId implements Serializable {
return new ActorId(bytes);
}
/**
* Generate a nil ActorId.
*/
/** 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.
*/
/** 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);
@@ -11,34 +11,30 @@ public abstract class BaseId implements Serializable {
private int hashCodeCache = 0;
private Boolean isNilCache = null;
/**
* Create a BaseId instance according to the input byte array.
*/
/** 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.");
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.
*/
/** Get the byte data of this id. */
public byte[] getBytes() {
return id;
}
/**
* Convert the byte data to a ByteBuffer.
*/
/** Convert the byte data to a ByteBuffer. */
public ByteBuffer toByteBuffer() {
return ByteBuffer.wrap(id);
}
/**
* @return True if this id is nil.
*/
/** Returns true if this id is nil. */
public boolean isNil() {
if (isNilCache == null) {
boolean localIsNil = true;
@@ -55,7 +51,8 @@ public abstract class BaseId implements Serializable {
/**
* Derived class should implement this function.
* @return The length of this id in bytes.
*
* <p>Returns The length of this id in bytes.
*/
public abstract int size();
@@ -96,5 +93,4 @@ public abstract class BaseId implements Serializable {
bb.get(id);
return id;
}
}
@@ -5,32 +5,24 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
/**
* Represents the id of a Ray job.
*/
/** 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.
*/
/** Create a JobID instance according to the given bytes. */
private JobId(byte[] id) {
super(id);
}
/**
* Create a JobId from a given hex string.
*/
/** 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.
*/
/** Creates a JobId from the given ByteBuffer. */
public static JobId fromByteBuffer(ByteBuffer bb) {
return new JobId(byteBuffer2Bytes(bb));
}
@@ -49,9 +41,7 @@ public class JobId extends BaseId implements Serializable {
return JobId.fromByteBuffer(wbb);
}
/**
* Generate a nil JobId.
*/
/** Generate a nil JobId. */
private static JobId genNil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
@@ -5,23 +5,17 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
/**
* Represents the id of a Ray object.
*/
/** 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.
*/
/** Create an ObjectId from a ByteBuffer. */
public static ObjectId fromByteBuffer(ByteBuffer bb) {
return new ObjectId(byteBuffer2Bytes(bb));
}
/**
* Generate an ObjectId with random value.
*/
/** 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.
@@ -41,5 +35,4 @@ public class ObjectId extends BaseId implements Serializable {
public int size() {
return LENGTH;
}
}
@@ -5,9 +5,7 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Random;
/**
* Represents the id of a placement group.
*/
/** Represents the id of a placement group. */
public class PlacementGroupId extends BaseId implements Serializable {
public static final int LENGTH = 16;
@@ -18,32 +16,24 @@ public class PlacementGroupId extends BaseId implements Serializable {
super(id);
}
/**
* Creates a PlacementGroupId from the given ByteBuffer.
*/
/** 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.
*/
/** Create a PlacementGroupId instance according to the given bytes. */
public static PlacementGroupId fromBytes(byte[] bytes) {
return new PlacementGroupId(bytes);
}
/**
* Generate a nil PlacementGroupId.
*/
/** 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.
*/
/** 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);
@@ -4,9 +4,7 @@ import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
/**
* Represents the id of a Ray task.
*/
/** Represents the id of a Ray task. */
public class TaskId extends BaseId implements Serializable {
public static final int UNIQUE_BYTES_LENGTH = 8;
@@ -15,30 +13,22 @@ public class TaskId extends BaseId implements Serializable {
public static final TaskId NIL = genNil();
/**
* Create a TaskId from a hex string.
*/
/** Create a TaskId from a hex string. */
public static TaskId fromHexString(String hex) {
return new TaskId(hexString2Bytes(hex));
}
/**
* Creates a TaskId from a ByteBuffer.
*/
/** Creates a TaskId from a ByteBuffer. */
public static TaskId fromByteBuffer(ByteBuffer bb) {
return new TaskId(byteBuffer2Bytes(bb));
}
/**
* Creates a TaskId from given bytes.
*/
/** Creates a TaskId from given bytes. */
public static TaskId fromBytes(byte[] bytes) {
return new TaskId(bytes);
}
/**
* Generate a nil TaskId.
*/
/** Generate a nil TaskId. */
private static TaskId genNil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
@@ -5,41 +5,30 @@ 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.
*/
/** 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.
*/
/** Create a UniqueId from a hex string. */
public static UniqueId fromHexString(String hex) {
return new UniqueId(hexString2Bytes(hex));
}
/**
* Creates a UniqueId from a ByteBuffer.
*/
/** Creates a UniqueId from a ByteBuffer. */
public static UniqueId fromByteBuffer(ByteBuffer bb) {
return new UniqueId(byteBuffer2Bytes(bb));
}
/**
* Generate a nil UniqueId.
*/
/** 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.
*/
/** Generate an UniqueId with random value. */
public static UniqueId randomId() {
byte[] b = new byte[LENGTH];
new Random().nextBytes(b);
@@ -5,9 +5,7 @@ import io.ray.api.placementgroup.PlacementGroup;
import java.util.HashMap;
import java.util.Map;
/**
* The options for creating actor.
*/
/** The options for creating actor. */
public class ActorCreationOptions extends BaseTaskOptions {
public final boolean global;
public final String name;
@@ -17,9 +15,15 @@ public class ActorCreationOptions extends BaseTaskOptions {
public final PlacementGroup group;
public final int bundleIndex;
private ActorCreationOptions(boolean global, String name, Map<String, Double> resources,
int maxRestarts, String jvmOptions, int maxConcurrency,
PlacementGroup group, int bundleIndex) {
private ActorCreationOptions(
boolean global,
String name,
Map<String, Double> resources,
int maxRestarts,
String jvmOptions,
int maxConcurrency,
PlacementGroup group,
int bundleIndex) {
super(resources);
this.global = global;
this.name = name;
@@ -30,9 +34,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
this.bundleIndex = bundleIndex;
}
/**
* The inner class for building ActorCreationOptions.
*/
/** The inner class for building ActorCreationOptions. */
public static class Builder {
private boolean global;
private String name;
@@ -44,13 +46,11 @@ public class ActorCreationOptions extends BaseTaskOptions {
private int bundleIndex;
/**
* Set the actor name of a named actor.
* This named actor is only accessible from this job by this name via
* {@link Ray#getActor(java.lang.String)}. If you want create a named actor that is accessible
* from all jobs, use {@link Builder#setGlobalName(java.lang.String)} instead.
* Set the actor name of a named actor. This named actor is only accessible from this job by
* this name via {@link Ray#getActor(java.lang.String)}. If you want create a named actor that
* is accessible from all jobs, use {@link Builder#setGlobalName(java.lang.String)} instead.
*
* @param name The name of the named actor.
* @return self
* @param name The name of the named actor. Returns self
*/
public Builder setName(String name) {
this.name = name;
@@ -63,8 +63,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
* {@link Ray#getGlobalActor(java.lang.String)}. If you want to create a named actor that is
* only accessible from this job, use {@link Builder#setName(java.lang.String)} instead.
*
* @param name The name of the named actor.
* @return self
* @param name The name of the named actor. Returns self
*/
public Builder setGlobalName(String name) {
this.name = name;
@@ -73,13 +72,12 @@ public class ActorCreationOptions extends BaseTaskOptions {
}
/**
* 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.
* 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
* @param resourceQuantity resource quantity Returns self
*/
public Builder setResource(String resourceName, Double resourceQuantity) {
this.resources.put(resourceName, resourceQuantity);
@@ -87,12 +85,11 @@ public class ActorCreationOptions extends BaseTaskOptions {
}
/**
* 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.
* 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
* @param resources requirements for multiple resources. Returns self
*/
public Builder setResources(Map<String, Double> resources) {
this.resources.putAll(resources);
@@ -104,8 +101,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
* 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
* @param maxRestarts max number of actor restarts Returns self
*/
public Builder setMaxRestarts(int maxRestarts) {
this.maxRestarts = maxRestarts;
@@ -114,11 +110,10 @@ public class ActorCreationOptions extends BaseTaskOptions {
/**
* 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
* <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. Returns self
*/
public Builder setJvmOptions(String jvmOptions) {
this.jvmOptions = jvmOptions;
@@ -127,12 +122,12 @@ public class ActorCreationOptions extends BaseTaskOptions {
/**
* 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
* <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. Returns
* self
*/
public Builder setMaxConcurrency(int maxConcurrency) {
if (maxConcurrency <= 0) {
@@ -147,8 +142,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
* 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
* @param bundleIndex The index of the bundle to place this actor in. Returns self
*/
public Builder setPlacementGroup(PlacementGroup group, int bundleIndex) {
this.group = group;
@@ -161,5 +155,4 @@ public class ActorCreationOptions extends BaseTaskOptions {
global, name, resources, maxRestarts, jvmOptions, maxConcurrency, group, bundleIndex);
}
}
}
@@ -4,9 +4,7 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* The options class for RayCall or ActorCreation.
*/
/** The options class for RayCall or ActorCreation. */
public abstract class BaseTaskOptions implements Serializable {
public final Map<String, Double> resources;
@@ -18,19 +16,22 @@ public abstract class BaseTaskOptions implements Serializable {
public BaseTaskOptions(Map<String, Double> resources) {
for (Map.Entry<String, Double> entry : resources.entrySet()) {
if (entry.getValue() == null || entry.getValue().compareTo(0.0) <= 0) {
throw new IllegalArgumentException(String.format("Resource values should be "
+ "positive. Specified resource: %s = %s.", entry.getKey(), entry.getValue()));
throw new IllegalArgumentException(
String.format(
"Resource values should be " + "positive. Specified resource: %s = %s.",
entry.getKey(), entry.getValue()));
}
// Note: A resource value should be an integer if it is greater than 1.0.
// e.g. 3.0 is a valid resource value, but 3.5 is not.
if (entry.getValue().compareTo(1.0) >= 0
&& entry.getValue().compareTo(Math.floor(entry.getValue())) != 0) {
throw new IllegalArgumentException(String.format("A resource value should be "
+ "an integer if it is greater than 1.0. Specified resource: %s = %s.",
entry.getKey(), entry.getValue()));
throw new IllegalArgumentException(
String.format(
"A resource value should be "
+ "an integer if it is greater than 1.0. Specified resource: %s = %s.",
entry.getKey(), entry.getValue()));
}
}
this.resources = resources;
}
}
@@ -22,8 +22,7 @@ public class CallOptions extends BaseTaskOptions {
/**
* Set a name for this task.
*
* @param name task name
* @return self
* @param name task name Returns self
*/
public Builder setName(String name) {
this.name = name;
@@ -35,8 +34,7 @@ public class CallOptions extends BaseTaskOptions {
* 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
* @param value resource capacity Returns self
*/
public Builder setResource(String name, Double value) {
this.resources.put(name, value);
@@ -47,8 +45,7 @@ public class CallOptions extends BaseTaskOptions {
* 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
* @param resources requirements for multiple resources. Returns self
*/
public Builder setResources(Map<String, Double> resources) {
this.resources.putAll(resources);
@@ -1,10 +1,9 @@
package io.ray.api.placementgroup;
/**
* 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.
* 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 {
}
public interface PlacementGroup {}
@@ -1,33 +1,21 @@
package io.ray.api.placementgroup;
/**
* State of placement group.
*/
/** State of placement group. */
public enum PlacementGroupState {
/**
* Wait for resource to schedule.
*/
/** Wait for resource to schedule. */
PENDING(0),
/**
* The placement group has created on some node.
*/
/** The placement group has created on some node. */
CREATED(1),
/**
* The placement group has removed.
*/
/** The placement group has removed. */
REMOVED(2),
/**
* The placement group is rescheduling.
*/
/** The placement group is rescheduling. */
RESCHEDULING(3),
/**
* Unrecognized state.
*/
/** Unrecognized state. */
UNRECOGNIZED(-1);
private int value = 0;
@@ -1,33 +1,23 @@
package io.ray.api.placementgroup;
/**
* The actor placement strategy.
*/
/** The actor placement strategy. */
public enum PlacementStrategy {
/**
* Packs Bundles close together inside nodes as tight as possible.
*/
/** Packs Bundles close together inside nodes as tight as possible. */
PACK(0),
/**
* Places Bundles across distinct nodes as even as possible.
*/
/** 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.
*/
/** 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.
* 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 strategy. */
UNRECOGNIZED(-1);
private int value = 0;
@@ -22,37 +22,31 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
/**
* Base interface of a Ray runtime.
*/
/** Base interface of a Ray runtime. */
public interface RayRuntime {
/**
* Shutdown the runtime.
*/
/** 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.
* @param obj The Java object to be stored. Returns 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.
* @param objectRef The reference of the object to get. Returns 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.
* @param objectRefs The list of object references. Returns A list of Java objects.
*/
<T> List<T> get(List<ObjectRef<T>> objectRefs);
@@ -62,8 +56,8 @@ public interface RayRuntime {
*
* @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.
* @return Two lists, one containing locally available objects, one containing the rest.
* @param timeoutMs The maximum time in milliseconds to wait before returning. Returns Two lists,
* one containing locally available objects, one containing the rest.
*/
<T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns, int timeoutMs);
@@ -88,13 +82,12 @@ public interface RayRuntime {
/**
* 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.
*
* <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 global Whether the named actor is global.
* @return ActorHandle to the actor.
* @param global Whether the named actor is global. Returns ActorHandle to the actor.
*/
<T extends BaseActorHandle> Optional<T> getActor(String name, boolean global);
@@ -111,8 +104,7 @@ public interface RayRuntime {
*
* @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.
* @param options The options for this call. Returns The result object.
*/
ObjectRef call(RayFunc func, Object[] args, CallOptions options);
@@ -121,8 +113,7 @@ public interface RayRuntime {
*
* @param pyFunction The Python function.
* @param args Arguments of the function.
* @param options The options for this call.
* @return The result object.
* @param options The options for this call. Returns The result object.
*/
ObjectRef call(PyFunction pyFunction, Object[] args, CallOptions options);
@@ -131,8 +122,7 @@ public interface RayRuntime {
*
* @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.
* @param args The arguments of the remote function. Returns The result object.
*/
ObjectRef callActor(ActorHandle<?> actor, RayFunc func, Object[] args);
@@ -141,8 +131,7 @@ public interface RayRuntime {
*
* @param pyActor A handle to the actor.
* @param pyActorMethod The actor method.
* @param args Arguments of the function.
* @return The result object.
* @param args Arguments of the function. Returns The result object.
*/
ObjectRef callActor(PyActorHandle pyActor, PyActorMethod pyActorMethod, Object[] args);
@@ -152,28 +141,25 @@ public interface RayRuntime {
* @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.
* @param options The options for creating actor. Returns A handle to the actor.
*/
<T> ActorHandle<T> createActor(RayFunc actorFactoryFunc, Object[] args,
ActorCreationOptions options);
<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.
* @param options The options for creating actor. Returns A handle to the actor.
*/
PyActorHandle createActor(PyActorClass pyActorClass, Object[] args,
ActorCreationOptions options);
PyActorHandle createActor(PyActorClass pyActorClass, Object[] args, ActorCreationOptions options);
PlacementGroup createPlacementGroup(String name, List<Map<String, Double>> bundles,
PlacementStrategy strategy);
PlacementGroup createPlacementGroup(
String name, List<Map<String, Double>> bundles, PlacementStrategy strategy);
PlacementGroup createPlacementGroup(List<Map<String, Double>> bundles,
PlacementStrategy strategy);
PlacementGroup createPlacementGroup(
List<Map<String, Double>> bundles, PlacementStrategy strategy);
RuntimeContext getRuntimeContext();
@@ -184,48 +170,47 @@ public interface RayRuntime {
/**
* Wrap a {@link Runnable} with necessary context capture.
*
* @param runnable The runnable to wrap.
* @return The wrapped runnable.
* @param runnable The runnable to wrap. Returns The wrapped runnable.
*/
Runnable wrapRunnable(Runnable runnable);
/**
* Wrap a {@link Callable} with necessary context capture.
*
* @param callable The callable to wrap.
* @return The wrapped callable.
* @param callable The callable to wrap. Returns The wrapped callable.
*/
<T> Callable<T> wrapCallable(Callable<T> callable);
/**
* Intentionally exit the current actor.
*/
/** Intentionally exit the current actor. */
void exitActor();
/**
* Get a placement group by id.
* @param id placement group id.
* @return The placement group.
*
* @param id placement group id. Returns The placement group.
*/
PlacementGroup getPlacementGroup(PlacementGroupId id);
/**
* Get all placement groups in this cluster.
* @return All placement groups.
*
* <p>Returns 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 timeoutMs Timeout in milliseconds.
* @return True if the placement group is created. False otherwise.
* @param timeoutMs Timeout in milliseconds. Returns True if the placement group is created. False
* otherwise.
*/
boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutMs);
}
@@ -1,8 +1,6 @@
package io.ray.api.runtime;
/**
* A factory that produces a RayRuntime instance.
*/
/** A factory that produces a RayRuntime instance. */
public interface RayRuntimeFactory {
RayRuntime createRayRuntime();
@@ -3,9 +3,7 @@ package io.ray.api.runtimecontext;
import io.ray.api.id.UniqueId;
import java.util.Map;
/**
* A class that represents the information of a node.
*/
/** A class that represents the information of a node. */
public class NodeInfo {
public final UniqueId nodeId;
@@ -24,9 +22,15 @@ public class NodeInfo {
public final Map<String, Double> resources;
public NodeInfo(UniqueId nodeId, String nodeAddress, String nodeHostname, int nodeManagerPort,
String objectStoreSocketName, String rayletSocketName,
boolean isAlive, Map<String, Double> resources) {
public NodeInfo(
UniqueId nodeId,
String nodeAddress,
String nodeHostname,
int nodeManagerPort,
String objectStoreSocketName,
String rayletSocketName,
boolean isAlive,
Map<String, Double> resources) {
this.nodeId = nodeId;
this.nodeAddress = nodeAddress;
this.nodeHostname = nodeHostname;
@@ -39,12 +43,19 @@ public class NodeInfo {
public String toString() {
return "NodeInfo{"
+ "nodeId='" + nodeId + '\''
+ ", nodeAddress='" + nodeAddress + "\'"
+ ", nodeHostname'" + nodeHostname + "\'"
+ ", isAlive=" + isAlive
+ ", resources=" + resources
+ "nodeId='"
+ nodeId
+ '\''
+ ", nodeAddress='"
+ nodeAddress
+ "\'"
+ ", nodeHostname'"
+ nodeHostname
+ "\'"
+ ", isAlive="
+ isAlive
+ ", resources="
+ resources
+ "}";
}
}
@@ -4,27 +4,23 @@ import io.ray.api.id.ActorId;
import io.ray.api.id.JobId;
import java.util.List;
/**
* A class used for getting information of Ray runtime.
*/
/** A class used for getting information of Ray runtime. */
public interface RuntimeContext {
/**
* Get the current Job ID.
*/
/** Get the current Job ID. */
JobId getCurrentJobId();
/**
* Get the current actor ID.
*
* Note, this can only be called in actors.
* <p>Note, this can only be called in actors.
*/
ActorId getCurrentActorId();
/**
* Returns true if the current actor was restarted, false if it's created for the first time.
*
* Note, this method should only be called from an actor creation task.
* <p>Note, this method should only be called from an actor creation task.
*/
boolean wasCurrentActorRestarted();
@@ -33,8 +29,6 @@ public interface RuntimeContext {
*/
boolean isSingleProcess();
/**
* Get all node information in Ray cluster.
*/
/** Get all node information in Ray cluster. */
List<NodeInfo> getAllNodeInfo();
}