mirror of
https://github.com/wassname/ray.git
synced 2026-07-03 02:30:48 +08:00
[Java] support java actor class inheritance (#12001)
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user