Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ray project Ray BaseActorCreator

From Leeroopedia
Knowledge Sources
Domains Distributed_Computing, Java_API
Last Updated 2026-02-13 16:00 GMT

Overview

Abstract base class for all actor creator builders providing common actor configuration options via a fluent API in the Ray Java API.

Description

BaseActorCreator<T> uses the Curiously Recurring Template Pattern (CRTP) with <T extends BaseActorCreator> to enable fluent method chaining that returns the concrete subclass type. It wraps an ActorCreationOptions.Builder and exposes setter methods for actor name and namespace, lifetime, custom resources, max restarts, max task retries, max concurrency, max pending calls, and placement group assignment. The buildOptions() method finalizes the options.

Usage

Use this class as the base for language-specific actor creators (ActorCreator for Java, PyActorCreator for Python, CppActorCreator for C++). It centralizes all language-agnostic actor creation configuration, ensuring consistency and ergonomic builder patterns.

Code Reference

Source Location

  • Repository: Ray
  • File: java/api/src/main/java/io/ray/api/call/BaseActorCreator.java

Signature

public class BaseActorCreator<T extends BaseActorCreator> {
    protected ActorCreationOptions.Builder builder;
    public T setName(String name);
    public T setName(String name, String namespace);
    public T setLifetime(ActorLifetime lifetime);
    public T setResource(String resourceName, Double resourceQuantity);
    public T setResources(Map<String, Double> resources);
    public T setMaxRestarts(int maxRestarts);
    public T setMaxTaskRetries(int maxTaskRetries);
    public T setMaxConcurrency(int maxConcurrency);
    public T setMaxPendingCalls(int maxPendingCalls);
    public T setPlacementGroup(PlacementGroup group, int bundleIndex);
    public T setPlacementGroup(PlacementGroup group);
    protected ActorCreationOptions buildOptions();
}

Import

import io.ray.api.call.BaseActorCreator;

I/O Contract

Inputs

Name Type Required Description
name String No The name of the named actor
namespace String No The namespace for the named actor
lifetime ActorLifetime No The lifetime of the actor
resourceName String No Custom resource name to reserve
resourceQuantity Double No Quantity of the custom resource
maxRestarts int No Maximum number of actor restarts (0 = no restart, -1 = unlimited)
maxTaskRetries int No Maximum number of task retries (0 = no retry, -1 = unlimited)
maxConcurrency int No Maximum concurrent calls (defaults to 1)
maxPendingCalls int No Maximum pending calls per handle (-1 = unlimited)
group PlacementGroup No Placement group for the actor
bundleIndex int No Bundle index within placement group (-1 = any)

Outputs

Name Type Description
self T Returns the concrete creator subclass for method chaining
options ActorCreationOptions Built actor creation options (via buildOptions())

Usage Examples

// BaseActorCreator is used through its subclass ActorCreator
ActorHandle<MyActor> actor = Ray.actor(MyActor::new)
    .setName("my-actor")
    .setMaxRestarts(3)
    .setMaxConcurrency(4)
    .setResource("GPU", 1.0)
    .setPlacementGroup(myPlacementGroup)
    .remote();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment