Search in sources :

Example 1 with DubboIT

use of com.creditease.uav.hook.dubbo.interceptors.DubboIT in project uavstack by uavorg.

the class DubboHookProxy method InsertInterceptToClients.

private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {
    if (isHookEventDone("InsertInterceptToClients")) {
        return;
    }
    InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
    String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
    String basePath = (String) ic.get(InterceptConstants.BASEPATH);
    final String appid = MonitorServerUtil.getApplicationId(contextPath, basePath);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * inject ServiceBean for profiling
     */
    dpInstall.installProxy("com.alibaba.dubbo.config.spring.ServiceBean", new String[] { "com.creditease.uav.hook.dubbo.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("onApplicationEvent".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DubboIT.class);
                m.insertAfter("{mObj=new DubboIT(\"" + appid + "\");mObj.doProfiling(new Object[]{this,$1});}");
            }
        }
    }, false);
    /**
     * inject Dubbo's MonitorFilter to get Service & Consumer Perf Data
     */
    dpInstall.installProxy("com.alibaba.dubbo.monitor.support.MonitorFilter", new String[] { "com.creditease.uav.hook.dubbo.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("invoke".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DubboIT.class);
                m.insertBefore("{DubboIT.doMonitorStart(\"" + appid + "\",new Object[]{$1,$2},false,null);}");
                m.insertAfter("{DubboIT.doMonitorEnd(new Object[]{$1,$2,$_},true,null);}");
                dpInstall.addCatch(m, "{DubboIT.doMonitorEnd(new Object[]{$1,$2},true,$e);throw $e;}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) DubboIT(com.creditease.uav.hook.dubbo.interceptors.DubboIT) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Aggregations

InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)1 DubboIT (com.creditease.uav.hook.dubbo.interceptors.DubboIT)1 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)1 DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)1