[Java] support java actor class inheritance (#12001)

This commit is contained in:
chaokunyang
2020-11-23 14:07:10 +08:00
committed by GitHub
parent 643c07e451
commit 9d133e874c
3 changed files with 133 additions and 27 deletions
@@ -1,5 +1,6 @@
package io.ray.runtime.functionmanager;
import com.google.common.collect.Lists;
import io.ray.api.function.RayFunc;
import io.ray.api.id.JobId;
import io.ray.runtime.util.LambdaUtils;
@@ -204,12 +205,28 @@ public class FunctionManager {
Map<Pair<String, String>, RayFunction> map = new HashMap<>();
try {
Class clazz = Class.forName(className, true, classLoader);
List<Executable> executables = new ArrayList<>();
executables.addAll(Arrays.asList(clazz.getDeclaredMethods()));
executables.addAll(Arrays.asList(clazz.getConstructors()));
executables.addAll(Arrays.asList(clazz.getDeclaredConstructors()));
for (Executable e : executables) {
Class clz = clazz;
clz = clz.getSuperclass();
while (clz != null && clz != Object.class) {
executables.addAll(Arrays.asList(clz.getDeclaredMethods()));
clz = clz.getSuperclass();
}
// Put interface methods ahead, so that in can be override by subclass methods in `map.put`
for (Class baseInterface : clazz.getInterfaces()) {
for (Method method : baseInterface.getDeclaredMethods()) {
if (method.isDefault()) {
executables.add(method);
}
}
}
// Use reverse order so that child class methods can override super class methods.
for (Executable e : Lists.reverse(executables)) {
e.setAccessible(true);
final String methodName = e instanceof Method ? e.getName() : CONSTRUCTOR_NAME;
final Type type =