diff --git a/src/main/src/org/bdware/server/action/ActionExecutor.java b/src/main/src/org/bdware/server/action/ActionExecutor.java index d078b6f..141653a 100644 --- a/src/main/src/org/bdware/server/action/ActionExecutor.java +++ b/src/main/src/org/bdware/server/action/ActionExecutor.java @@ -3,12 +3,15 @@ package org.bdware.server.action; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.Console; import java.io.FileNotFoundException; import java.io.RandomAccessFile; +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; @@ -23,6 +26,7 @@ public class ActionExecutor { public long permission; Map staticData; private Map> handlers; + private Object Constructor; public ActionExecutor(ExecutorService executor, Object... classes) { this.executor = executor; @@ -57,39 +61,7 @@ public class ActionExecutor { handlers = new HashMap<>(); if (objects.length > 0) { for (Object obj : objects) { - if (obj == null) continue; - Method[] methods = obj.getClass().getDeclaredMethods(); - for (Method method : methods) { - if (method.getAnnotation(Action.class) != null) { - if (method.getAnnotation(Action.class).alias().length == 0) { - handlers.put(method.getName(), new Pair<>(method, obj)); - if (!method.getReturnType().equals(Void.TYPE) - || method.getParameterCount() != 2) { - LOGGER.error( - "action ret is not void:" - + obj.getClass().getCanonicalName() - + "-->" - + method.getName()); - - System.exit(0); - } - } else { - for (String a : method.getAnnotation(Action.class).alias()) { - handlers.put(a, new Pair<>(method, obj)); - if (!method.getReturnType().equals(Void.TYPE) - || method.getParameterCount() != 2) { - LOGGER.error( - "action ret is not void:" - + obj.getClass().getCanonicalName() - + "-->" - + method.getName()); - - System.exit(0); - } - } - } - } - } + appendHandler(obj); } } } @@ -102,6 +74,46 @@ public class ActionExecutor { return handlers; } + public void appendHandler(Object obj) { + try { + if (obj == null) return; + Method[] methods = obj.getClass().getDeclaredMethods(); + System.out.println("zzz2"+obj.getClass()); + for (Method method : methods) { + if (method.getAnnotation(Action.class) != null) { + if (method.getAnnotation(Action.class).alias().length == 0) { + handlers.put(method.getName(), new Pair<>(method, obj)); + if (!method.getReturnType().equals(Void.TYPE) + || method.getParameterCount() != 2) { + LOGGER.error( + "action ret is not void:" + + obj.getClass().getCanonicalName() + + "-->" + + method.getName()); + + System.exit(0); + } + } else { + for (String a : method.getAnnotation(Action.class).alias()) { + handlers.put(a, new Pair<>(method, obj)); + if (!method.getReturnType().equals(Void.TYPE) + || method.getParameterCount() != 2) { + LOGGER.error( + "action ret is not void:" + + obj.getClass().getCanonicalName() + + "-->" + + method.getName()); + + System.exit(0); + } + } + } + } + } + }catch(Exception e){ + e.printStackTrace(); + } + } public void handle(String action, final U args, final T callback) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { // logger.info("[ActionExecutor] handle : "+action);