[Java] Add runtime context (#4194)

This commit is contained in:
Wang Qing
2019-03-05 20:25:29 +08:00
committed by Hao Chen
parent c73d5086f3
commit a116b7f646
12 changed files with 238 additions and 2 deletions
@@ -120,4 +120,11 @@ public final class Ray extends RayCall {
public static RayRuntime internal() {
return runtime;
}
/**
* Get the runtime context.
*/
public static RuntimeContext getRuntimeContext() {
return runtime.getRuntimeContext();
}
}
@@ -0,0 +1,46 @@
package org.ray.api;
import org.ray.api.id.UniqueId;
/**
* A class used for getting information of Ray runtime.
*/
public interface RuntimeContext {
/**
* Get the current Driver ID.
*
* If called in a driver, this returns the driver ID. If called in a worker, this returns the ID
* of the associated driver.
*/
UniqueId getCurrentDriverId();
/**
* Get the current actor ID.
*
* Note, this can only be called in actors.
*/
UniqueId getCurrentActorId();
/**
* Returns true if the current actor was reconstructed, false if it's created for the first time.
*
* Note, this method should only be called from an actor creation task.
*/
boolean wasCurrentActorReconstructed();
/**
* Get the raylet socket name.
*/
String getRayletSocketName();
/**
* Get the object store socket name.
*/
String getObjectStoreSocketName();
/**
* Return true if Ray is running in single-process mode, false if Ray is running in cluster mode.
*/
boolean isSingleProcess();
}
@@ -3,6 +3,7 @@ package org.ray.api.runtime;
import java.util.List;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.RuntimeContext;
import org.ray.api.WaitResult;
import org.ray.api.function.RayFunc;
import org.ray.api.id.UniqueId;
@@ -93,4 +94,6 @@ public interface RayRuntime {
*/
<T> RayActor<T> createActor(RayFunc actorFactoryFunc, Object[] args,
ActorCreationOptions options);
RuntimeContext getRuntimeContext();
}