[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:
Hao Chen
2018-09-04 00:53:03 +08:00
committed by Robert Nishihara
parent b37a283053
commit 9d655721e5
27 changed files with 1131 additions and 680 deletions
@@ -15,7 +15,7 @@ public class RayDevRuntime extends AbstractRayRuntime {
PathConfig pathConfig = new PathConfig(configReader);
RemoteFunctionManager rfm = new NopRemoteFunctionManager(params.driver_id);
MockObjectStore store = new MockObjectStore();
MockLocalScheduler scheduler = new MockLocalScheduler(store);
MockLocalScheduler scheduler = new MockLocalScheduler(this, store);
init(scheduler, store, rfm, pathConfig);
scheduler.setLocalFunctionManager(this.functions);
}
@@ -6,6 +6,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.ray.api.id.UniqueId;
import org.ray.core.LocalFunctionManager;
import org.ray.core.Worker;
import org.ray.core.impl.RayDevRuntime;
import org.ray.spi.LocalSchedulerLink;
import org.ray.spi.model.FunctionArg;
import org.ray.spi.model.TaskSpec;
@@ -19,8 +20,10 @@ public class MockLocalScheduler implements LocalSchedulerLink {
private final Map<UniqueId, Map<UniqueId, TaskSpec>> waitTasks = new ConcurrentHashMap<>();
private final MockObjectStore store;
private LocalFunctionManager functions = null;
private final RayDevRuntime runtime;
public MockLocalScheduler(MockObjectStore store) {
public MockLocalScheduler(RayDevRuntime runtime, MockObjectStore store) {
this.runtime = runtime;
this.store = store;
store.registerScheduler(this);
}
@@ -43,7 +46,7 @@ public class MockLocalScheduler implements LocalSchedulerLink {
public void submitTask(TaskSpec task) {
UniqueId id = isTaskReady(task);
if (id == null) {
Worker.execute(task, functions);
runtime.getWorker().execute(task);
} else {
Map<UniqueId, TaskSpec> bucket = waitTasks
.computeIfAbsent(id, id_ -> new ConcurrentHashMap<>());