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 BaseId

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

Overview

Abstract base class for all Ray identifier types providing byte-array storage and standard identity operations in the Ray Java API.

Description

BaseId is a serializable abstract class that stores Ray identifiers as fixed-length byte arrays. It provides lazy-cached hashCode() and isNil() computations, hex string serialization via DatatypeConverter, equality comparison via Arrays.equals(), and an abstract size() method that subclasses implement to specify the expected byte length. It also includes protected utility methods for converting hex strings and ByteBuffer instances to byte arrays.

Usage

Use this class as the foundation for all concrete Ray identifier types (ActorId, JobId, TaskId, ObjectId, etc.). It ensures consistent serialization, comparison, and display behavior across the entire Ray Java ID system.

Code Reference

Source Location

  • Repository: Ray
  • File: java/api/src/main/java/io/ray/api/id/BaseId.java

Signature

public abstract class BaseId implements Serializable {
    protected BaseId(byte[] id);
    public byte[] getBytes();
    public ByteBuffer toByteBuffer();
    public boolean isNil();
    public abstract int size();
    public int hashCode();
    public boolean equals(Object obj);
    public String toString();
    protected static byte[] hexString2Bytes(String hex);
    protected static byte[] byteBuffer2Bytes(ByteBuffer bb);
}

Import

import io.ray.api.id.BaseId;

I/O Contract

Inputs

Name Type Required Description
id byte[] Yes Raw byte array of the identifier (must match size() length)
hex String No Hex string representation (for static utility method)
bb ByteBuffer No ByteBuffer representation (for static utility method)

Outputs

Name Type Description
bytes byte[] Raw byte data of the ID (via getBytes())
byteBuffer ByteBuffer ByteBuffer wrapping the ID bytes
isNil boolean True if all bytes are 0xff (nil ID)
hexString String Lowercase hex string representation (via toString())

Usage Examples

// BaseId is used through concrete subclasses like ActorId
ActorId actorId = ActorId.fromBytes(rawBytes);

// Check if the ID is nil
if (actorId.isNil()) {
    System.out.println("Actor ID is nil");
}

// Convert to hex string
String hex = actorId.toString();
System.out.println("Actor ID: " + hex);

// Compare two IDs
boolean same = actorId1.equals(actorId2);

// Get raw bytes
byte[] bytes = actorId.getBytes();

Related Pages

Page Connections

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