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 TaskExecutor

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

Overview

Abstract base class that executes Ray tasks assigned to a Java worker, handling the complete task lifecycle from function resolution through invocation to result serialization.

Description

TaskExecutor resolves RayFunction objects via the FunctionManager, unwraps arguments using ArgumentsBuilder, invokes methods or constructors via reflection, and serializes results or exceptions into NativeRayObject return values. It manages actor context lifecycle by creating contexts on actor creation tasks and retrieving them on actor method calls. The class provides detailed error reporting including cross-language exception handling, with special treatment for RayIntentionalSystemExitException.

Usage

Use TaskExecutor as the central execution engine for all Java tasks in Ray. It is shared by both local mode and cluster mode executors. Subclasses must implement createActorContext() to provide mode-specific actor context initialization. The execute() method is called by the runtime whenever a task needs to be run.

Code Reference

Source Location

  • Repository: Ray
  • File: java/runtime/src/main/java/io/ray/runtime/task/TaskExecutor.java

Signature

public abstract class TaskExecutor<T extends TaskExecutor.ActorContext> {

  protected final AbstractRayRuntime runtime;

  static class ActorContext {
    Object currentActor = null;
  }

  TaskExecutor(AbstractRayRuntime runtime) { ... }

  protected abstract T createActorContext();
  T getActorContext() { ... }
  void setActorContext(UniqueId workerId, T actorContext) { ... }
  protected boolean[] checkByteBufferArguments(List<String> rayFunctionInfo) { ... }
  protected List<NativeRayObject> execute(
      List<String> rayFunctionInfo, List<Object> argsBytes) { ... }
}

Import

import io.ray.runtime.task.TaskExecutor;

I/O Contract

Input

Parameter Type Description
runtime AbstractRayRuntime The Ray runtime instance providing worker context and function management
rayFunctionInfo List<String> Three-element list containing class name, method name, and signature descriptor
argsBytes List<Object> Serialized task arguments to be unwrapped before invocation

Output

Method Return Type Description
execute List<NativeRayObject> Serialized return objects; contains the result for functions with return values or serialized exceptions on failure
checkByteBufferArguments boolean[] Array indicating which parameters are of type ByteBuffer, or null if function resolution fails
createActorContext T Mode-specific actor context created during actor creation tasks

Usage Examples

// TaskExecutor is used internally by the Ray runtime.
// Subclasses provide mode-specific implementations:

// In local mode:
public class LocalModeTaskExecutor extends TaskExecutor<ActorContext> {
    @Override
    protected ActorContext createActorContext() {
        return new ActorContext();
    }
}

// The execute method is called by the runtime with function info and args:
List<String> funcInfo = Arrays.asList(
    "com.example.MyClass", "myMethod", "(Ljava/lang/String;)Ljava/lang/String;");
List<Object> args = Arrays.asList(serializedArg);
List<NativeRayObject> results = taskExecutor.execute(funcInfo, args);

Related Pages

Page Connections

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