[Java] Throw exception if Ray.init() is not called and users try to access ray API (#10497)

This commit is contained in:
chaokunyang
2020-09-05 10:09:19 +08:00
committed by GitHub
parent 8ee7c182f5
commit 7ee0fdba3d
6 changed files with 35 additions and 26 deletions
@@ -40,7 +40,8 @@ public final class ObjectRefImpl<T> implements ObjectRef<T>, Externalizable {
addLocalReference();
}
public ObjectRefImpl() {}
public ObjectRefImpl() {
}
@Override
public synchronized T get() {
@@ -103,10 +104,10 @@ public final class ObjectRefImpl<T> implements ObjectRef<T>, Externalizable {
// unit tests). So if `workerId` is null, it means this method has been invoked.
if (!removed.getAndSet(true)) {
REFERENCES.remove(this);
RayRuntimeInternal runtime = (RayRuntimeInternal) Ray.internal();
// It's possible that GC is executed after the runtime is shutdown.
if (runtime != null) {
runtime.getObjectStore().removeLocalReference(workerId, objectId);
if (Ray.isInitialized()) {
((RayRuntimeInternal) (Ray.internal())).getObjectStore()
.removeLocalReference(workerId, objectId);
}
}
}