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 BaseTaskCaller

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

Overview

Abstract base class for all remote task caller builders providing common task call configuration via a fluent API in the Ray Java API.

Description

BaseTaskCaller<T> uses the Curiously Recurring Template Pattern (CRTP) with <T extends BaseTaskCaller<T>> to enable fluent method chaining. It wraps a CallOptions.Builder and exposes setter methods for task name, custom resources (single or map), placement group assignment (with or without specific bundle index), and runtime environment. The buildOptions() method finalizes and returns the CallOptions instance.

Usage

Use this class as the base for language-specific task callers (TaskCaller for Java, PyTaskCaller for Python, CppTaskCaller for C++). It centralizes all language-agnostic remote function call configuration, ensuring consistency across language-specific task callers.

Code Reference

Source Location

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

Signature

public class BaseTaskCaller<T extends BaseTaskCaller<T>> {
    public T setName(String name);
    public T setResource(String name, Double value);
    public T setResources(Map<String, Double> resources);
    public T setPlacementGroup(PlacementGroup group, int bundleIndex);
    public T setPlacementGroup(PlacementGroup group);
    public T setRuntimeEnv(RuntimeEnv runtimeEnv);
    protected CallOptions buildOptions();
}

Import

import io.ray.api.call.BaseTaskCaller;

I/O Contract

Inputs

Name Type Required Description
name String No Name for the task
name (resource) String No Resource name for custom resource requirement
value Double No Resource capacity value
resources Map<String, Double> No Multiple resource requirements
group PlacementGroup No Placement group for the task
bundleIndex int No Bundle index within the placement group (-1 = any)
runtimeEnv RuntimeEnv No Runtime environment for the task

Outputs

Name Type Description
self T Returns the concrete caller subclass for method chaining
options CallOptions Built call options (via buildOptions())

Usage Examples

// BaseTaskCaller is used through its subclass TaskCaller
ObjectRef<Integer> result = Ray.task(MyClass::compute, 42)
    .setName("compute-task")
    .setResource("CPU", 2.0)
    .setPlacementGroup(myGroup)
    .remote();

Related Pages

Page Connections

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