scouter.server.plugin.builtin.BuiltInPluginManager Maven / Gradle / Ivy
package scouter.server.plugin.builtin;
import scouter.lang.pack.Pack;
import scouter.lang.plugin.annotation.ServerPlugin;
import scouter.server.Configure;
import scouter.server.Logger;
import scouter.util.scan.Scanner;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
/**
* @author Gun Lee ([email protected]) on 2016. 3. 19.
*/
public class BuiltInPluginManager {
public static Map> pluginMap = new HashMap>();
public static void loadPlugins() {
Set classNames = new Scanner("scouter.plugin.server").process();
Iterator itr = classNames.iterator();
while (itr.hasNext()) {
try {
Class c = Class.forName(itr.next());
if (!Modifier.isPublic(c.getModifiers()))
continue;
Method[] m = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++) {
ServerPlugin annotation = m[i].getAnnotation(ServerPlugin.class);
if (annotation == null)
continue;
String pluginPoint = annotation.value();
List pluginList = pluginMap.get(pluginPoint);
if(pluginList == null) {
pluginList = new ArrayList();
pluginMap.put(pluginPoint, pluginList);
}
Logger.println("[BuiltInPlugin]" + c.getName() + "=>" + m[i].getName());
pluginList.add(new PluginInvocation(c.newInstance(), m[i]));
}
} catch (Throwable t) {
Logger.println("Server Plugin Load Error");
if(Configure.getInstance()._trace) {
t.printStackTrace();
}
}
}
}
public static List getPluginList(String pluginPoint) {
if(pluginMap == null) return null;
return pluginMap.get(pluginPoint);
}
public static void invokeAllPlugins(String pluginPoint, Pack pack) {
if(pluginMap == null) return;
List pluginList = pluginMap.get(pluginPoint);
if(pluginList == null) return;
int count = pluginList.size();
for(int i=0; i