Implementation:Ray project Ray Deployment Class Pattern
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Model_Serving, Microservices |
| Last Updated | 2026-02-13 17:00 GMT |
Overview
Interface specification for user-defined deployment handler classes in Ray Serve Java.
Description
Deployment classes are standard Java classes with a callable method (default name: call) that handles requests. The class is instantiated by RayServeReplicaImpl via ReflectUtil during replica startup. The constructor may accept configuration parameters.
Usage
Define a standard Java class with a call method. Register it via Serve.deployment().setDeploymentDef(className).bind().
Code Reference
Source Location
- Repository: ray-project/ray
- File: java/serve/src/test/java/io/ray/serve/docdemo/StrategyCalcOnRayServe.java (example)
Interface Specification
/**
* Deployment class requirements:
* 1. Public class accessible on the classpath
* 2. Public no-arg or parameterized constructor
* 3. Public method matching the callMethod name (default: "call")
*/
public class StrategyOnRayServe {
private String prefix;
public StrategyOnRayServe(String prefix) {
this.prefix = prefix;
}
public String call(Object request) {
return prefix + ": processed " + request.toString();
}
}
Import
// No special imports for the class itself.
// Serve imports are needed when deploying:
import io.ray.serve.api.Serve;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request | Object | Yes | The request payload passed via DeploymentHandle.remote() |
Outputs
| Name | Type | Description |
|---|---|---|
| response | Object | The return value, sent back to the caller via DeploymentResponse |
Usage Examples
Strategy Calculator Deployment
import io.ray.serve.api.Serve;
import io.ray.serve.deployment.Application;
import io.ray.serve.handle.DeploymentHandle;
public class ServeExample {
// Deployment class
public static class Calculator {
public String call(Object input) {
return "Result: " + input.toString();
}
}
public static void main(String[] args) {
Serve.start(new java.util.HashMap<>());
Application app = Serve.deployment()
.setName("calculator")
.setDeploymentDef(Calculator.class.getName())
.setNumReplicas(2)
.bind();
DeploymentHandle handle = Serve.run(app);
Object result = handle.remote("42").result();
System.out.println(result); // "Result: 42"
Serve.shutdown();
}
}
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment