mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 11:21:15 +08:00
[java] support creating an actor with parameters (#2817)
Previously `Ray.createActor` only support creating an actor without any parameter. This PR adds the support for creating an actor with parameters. Moreover, besides using a constructor, it's now also allowed to create an actor with a factory method. For more usage, prefer refer to `ActorTest.java`.
This commit is contained in:
committed by
Robert Nishihara
parent
b37a283053
commit
9d655721e5
@@ -14,7 +14,7 @@ public class Exercise05 {
|
||||
try {
|
||||
Ray.init();
|
||||
// `Ray.createActor` creates an actor instance.
|
||||
RayActor<Adder> adder = Ray.createActor(Adder.class);
|
||||
RayActor<Adder> adder = Ray.createActor(Adder::new, 0);
|
||||
// Use `Ray.call(actor, parameters)` to call an actor method.
|
||||
RayObject<Integer> result1 = Ray.call(Adder::add, adder, 1);
|
||||
System.out.println(result1.get());
|
||||
@@ -34,8 +34,8 @@ public class Exercise05 {
|
||||
@RayRemote
|
||||
public static class Adder {
|
||||
|
||||
public Adder() {
|
||||
sum = 0;
|
||||
public Adder(int initValue) {
|
||||
sum = initValue;
|
||||
}
|
||||
|
||||
public int add(int n) {
|
||||
|
||||
Reference in New Issue
Block a user