启动模块
即调用@Command修饰的方法
通过http 调用ModuleHttpServlet 的 doMethod方法, jvm-sandbox是同构jetty启动了一个http server, 通过http对外交互。
增强字节码过程
对于激活命令
./sandbox.sh -p 2723 -a 'debug-trace/trace'
- 访问的路径是: /sandbox/default/module/http/sandbox-module-mgr/active?1=1&ids=debug-trace/trace
ModuleHttpServlet.doGet()
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding(cfg.getServerCharset().name());
doMethod(req, resp, Http.Method.GET);
}
- 最后增强字节码的动作在 ModuleEventWatcher 的 watch()方法, 一般通过他的默认实现类DefaultModuleEventWatcher中的private int watch() 进行。
- IBuildingForBehavior的实现类BuildingForBehavior 中的build()方法会调用上述方法。
- 而2中的build()方法由BuildingForBehavior中的onWatch()方法调起。
- BuildingForBehavior 中的 onWatch() 方法相当于客户端API,jvm-sandbox中的所有例子都是通过构造这个方法的入参进行字节码增强。例如DebugTraceModule
- sandbox-repeater也是通过这个api来进行字节码的增强, 位置在AbstractInvokePluginAdapter的watchIfNecessary() 方法,也就是所有插件的父类。