Interface RayRuntime


public interface RayRuntime
Base interface of a Ray runtime.
  • Method Details

    • shutdown

      void shutdown()
      Shutdown the runtime.
    • put

      <T> ObjectRef<T> put(T obj)
      Store an object in the object store.
      Parameters:
      obj - The Java object to be stored.
      Returns:
      A ObjectRef instance that represents the in-store object.
    • put

      <T> ObjectRef<T> put(T obj, BaseActorHandle owner)
      Store an object in the object store, and assign its ownership to owner. This function is experimental.
      Parameters:
      obj - The Java object to be stored.
      owner - The actor that should own this object. This allows creating objects with lifetimes decoupled from that of the creating process. Note that the owner actor must be passed a reference to the object prior to the object creator exiting, otherwise the reference will still be lost.
      Returns:
      A ObjectRef instance that represents the in-store object.
    • get

      <T> T get(ObjectRef<T> objectRef)
      Get an object from the object store.
      Parameters:
      objectRef - The reference of the object to get.
      Returns:
      The Java object.
    • get

      <T> List<T> get(List<ObjectRef<T>> objectRefs)
      Get a list of objects from the object store.
      Parameters:
      objectRefs - The list of object references.
      Returns:
      A list of Java objects.
    • get

      <T> T get(ObjectRef<T> objectRef, long timeoutMs)
      Get an object from the object store.
      Parameters:
      objectRef - The reference of the object to get.
      timeoutMs - The maximum amount of time in millseconds to wait before returning.
      Returns:
      The Java object.
      Throws:
      RayTimeoutException - If it's timeout to get the object.
    • get

      <T> List<T> get(List<ObjectRef<T>> objectRefs, long timeoutMs)
      Get a list of objects from the object store.
      Parameters:
      objectRefs - The list of object references.
      timeoutMs - The maximum amount of time in millseconds to wait before returning.
      Returns:
      A list of Java objects.
      Throws:
      RayTimeoutException - If it's timeout to get the object.
    • wait

      <T> WaitResult<T> wait(List<ObjectRef<T>> waitList, int numReturns, int timeoutMs, boolean fetchLocal)
      Wait for a list of RayObjects to be available, until specified number of objects are ready, or specified timeout has passed.
      Parameters:
      waitList - A list of ObjectRef to wait for.
      numReturns - The number of objects that should be returned.
      timeoutMs - The maximum time in milliseconds to wait before returning.
      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.
      Returns:
      Two lists, one containing locally available objects, one containing the rest.
    • free

      void free(List<ObjectRef<?>> objectRefs, boolean localOnly)
      Free a list of objects from Plasma Store.
      Parameters:
      objectRefs - The object references to free.
      localOnly - Whether only free objects for local object store or not.
    • getActorHandle

      <T extends BaseActorHandle> T getActorHandle(ActorId actorId)
    • getActor

      <T extends BaseActorHandle> Optional<T> getActor(String name, String namespace)
      Get a handle to a named actor.

      Gets a handle to a named actor with the given name. The actor must have been created with name specified.

      Parameters:
      name - The name of the named actor.
      namespace - The namespace of the actor.
      Returns:
      ActorHandle to the actor.
    • killActor

      void killActor(BaseActorHandle actor, boolean noRestart)
      Kill the actor immediately.
      Parameters:
      actor - The actor to be killed.
      noRestart - If set to true, the killed actor will not be restarted anymore.
    • call

      ObjectRef call(RayFunc func, Object[] args, CallOptions options)
      Invoke a remote function.
      Parameters:
      func - The remote function to run.
      args - The arguments of the remote function.
      options - The options for this call.
      Returns:
      The result object.
    • call

      ObjectRef call(PyFunction pyFunction, Object[] args, CallOptions options)
      Invoke a remote Python function.
      Parameters:
      pyFunction - The Python function.
      args - Arguments of the function.
      options - The options for this call.
      Returns:
      The result object.
    • callActor

      ObjectRef callActor(ActorHandle<?> actor, RayFunc func, Object[] args, CallOptions options)
      Invoke a remote function on an actor.
      Parameters:
      actor - A handle to the actor.
      func - The remote function to run, it must be a method of the given actor.
      args - The arguments of the remote function.
      Returns:
      The result object.
    • callActor

      ObjectRef callActor(PyActorHandle pyActor, PyActorMethod pyActorMethod, Object[] args)
      Invoke a remote Python function on an actor.
      Parameters:
      pyActor - A handle to the actor.
      pyActorMethod - The actor method.
      args - Arguments of the function.
      Returns:
      The result object.
    • createActor

      <T> ActorHandle<T> createActor(RayFunc actorFactoryFunc, Object[] args, ActorCreationOptions options)
      Create an actor on a remote node.
      Type Parameters:
      T - The type of the actor object.
      Parameters:
      actorFactoryFunc - A remote function whose return value is the actor object.
      args - The arguments for the remote function.
      options - The options for creating actor.
      Returns:
      A handle to the actor.
    • createActor

      PyActorHandle createActor(PyActorClass pyActorClass, Object[] args, ActorCreationOptions options)
      Create a Python actor on a remote node.
      Parameters:
      pyActorClass - The Python actor class.
      args - Arguments of the actor constructor.
      options - The options for creating actor.
      Returns:
      A handle to the actor.
    • createPlacementGroup

      PlacementGroup createPlacementGroup(PlacementGroupCreationOptions creationOptions)
      Create a placement group on remote nodes.
      Parameters:
      creationOptions - Creation options of the placement group.
      Returns:
      A handle to the created placement group.
    • getRuntimeContext

      RuntimeContext getRuntimeContext()
    • getAsyncContext

      Object getAsyncContext()
    • setAsyncContext

      void setAsyncContext(Object asyncContext)
    • wrapRunnable

      Runnable wrapRunnable(Runnable runnable)
      Wrap a Runnable with necessary context capture.
      Parameters:
      runnable - The runnable to wrap.
      Returns:
      The wrapped runnable.
    • wrapCallable

      <T> Callable<T> wrapCallable(Callable<T> callable)
      Wrap a Callable with necessary context capture.
      Parameters:
      callable - The callable to wrap.
      Returns:
      The wrapped callable.
    • exitActor

      void exitActor()
      Intentionally exit the current actor.
    • getAvailableResourceIds

      Map<String,​List<ResourceValue>> getAvailableResourceIds()
      Get the resources available on this worker. Note that this API doesn't work on driver.
      Returns:
      The resource info of one node.
    • getNamespace

      String getNamespace()
      Get the namespace of this job.
    • getPlacementGroup

      PlacementGroup getPlacementGroup(PlacementGroupId id)
      Get a placement group by id.
      Parameters:
      id - placement group id.
      Returns:
      The placement group.
    • getPlacementGroup

      PlacementGroup getPlacementGroup(String name, String namespace)
      Get a placement group by name.
      Parameters:
      name - The name of the placement group.
      namespace - The namespace of the placement group.
      Returns:
      The placement group.
    • getAllPlacementGroups

      List<PlacementGroup> getAllPlacementGroups()
      Get all placement groups in this cluster.
      Returns:
      All placement groups.
    • removePlacementGroup

      void removePlacementGroup(PlacementGroupId id)
      Remove a placement group by id.
      Parameters:
      id - Id of the placement group.
    • waitPlacementGroupReady

      boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutSeconds)
      Wait for the placement group to be ready within the specified time.
      Parameters:
      id - Id of placement group.
      timeoutSeconds - Timeout in seconds.
      Returns:
      True if the placement group is created. False otherwise.
    • createConcurrencyGroup

      ConcurrencyGroup createConcurrencyGroup(String name, int maxConcurrency, List<RayFunc> funcs)
      Create concurrency group instance at runtime.
    • extractConcurrencyGroups

      List<ConcurrencyGroup> extractConcurrencyGroups(RayFuncR<?> actorConstructorLambda)
    • createRuntimeEnv

      RuntimeEnv createRuntimeEnv(Map<String,​String> envVars)
      Create runtime env instance at runtime.
    • getParallelActorContext

      ParallelActorContext getParallelActorContext()