[Java] Support multiple workers in Java worker process (#5505)

This commit is contained in:
Kai Yang
2019-09-07 22:52:05 +08:00
committed by Hao Chen
parent d89ceb3ee5
commit 732336fc4f
37 changed files with 512 additions and 148 deletions
@@ -1,6 +1,7 @@
package org.ray.api;
import java.util.List;
import java.util.concurrent.Callable;
import org.ray.api.id.ObjectId;
import org.ray.api.id.UniqueId;
import org.ray.api.runtime.RayRuntime;
@@ -117,6 +118,28 @@ public final class Ray extends RayCall {
return runtime.wait(waitList, waitList.size(), Integer.MAX_VALUE);
}
/**
* If users want to use Ray API in there own threads, they should wrap their {@link Runnable}
* objects with this method.
*
* @param runnable The runnable to wrap.
* @return The wrapped runnable.
*/
public static Runnable wrapRunnable(Runnable runnable) {
return runtime.wrapRunnable(runnable);
}
/**
* If users want to use Ray API in there own threads, they should wrap their {@link Callable}
* objects with this method.
*
* @param callable The callable to wrap.
* @return The wrapped callable.
*/
public static Callable wrapCallable(Callable callable) {
return runtime.wrapCallable(callable);
}
/**
* Get the underlying runtime instance.
*/
@@ -30,7 +30,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
private Map<String, Double> resources = new HashMap<>();
private int maxReconstructions = NO_RECONSTRUCTION;
private String jvmOptions = "";
private String jvmOptions = null;
public Builder setResources(Map<String, Double> resources) {
this.resources = resources;
@@ -1,6 +1,7 @@
package org.ray.api.runtime;
import java.util.List;
import java.util.concurrent.Callable;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.RayPyActor;
@@ -141,4 +142,18 @@ public interface RayRuntime {
*/
RayPyActor createPyActor(String moduleName, String className, Object[] args,
ActorCreationOptions options);
/**
* Wrap a {@link Runnable} with necessary context capture.
* @param runnable The runnable to wrap.
* @return The wrapped runnable.
*/
Runnable wrapRunnable(Runnable runnable);
/**
* Wrap a {@link Callable} with necessary context capture.
* @param callable The callable to wrap.
* @return The wrapped callable.
*/
Callable wrapCallable(Callable callable);
}