Search in sources :

Example 1 with InterceptorArgumentProvider

use of com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider in project pinpoint by naver.

the class ASMClass method addInterceptor0.

private int addInterceptor0(TargetFilter annotation, String interceptorClassName, InterceptorScope scope, ExecutionPolicy executionPolicy, Object[] constructorArgs) throws InstrumentException {
    final String filterTypeName = annotation.type();
    Asserts.notNull(filterTypeName, "type of @TargetFilter");
    final InterceptorArgumentProvider interceptorArgumentProvider = objectBinderFactory.newInterceptorArgumentProvider(this);
    final AutoBindingObjectFactory filterFactory = objectBinderFactory.newAutoBindingObjectFactory(pluginContext, classLoader, interceptorArgumentProvider);
    final ObjectFactory objectFactory = ObjectFactory.byConstructor(filterTypeName, (Object[]) annotation.constructorArguments());
    final MethodFilter filter = (MethodFilter) filterFactory.createInstance(objectFactory);
    boolean singleton = annotation.singleton();
    int interceptorId = -1;
    for (InstrumentMethod m : getDeclaredMethods(filter)) {
        if (singleton && interceptorId != -1) {
            m.addInterceptor(interceptorId);
        } else {
            // TODO casting fix
            interceptorId = ((ASMMethod) m).addInterceptorInternal(interceptorClassName, constructorArgs, scope, executionPolicy);
        }
    }
    if (interceptorId == -1) {
        logger.warn("No methods are intercepted. target: " + this.classNode.getInternalName(), ", interceptor: " + interceptorClassName + ", methodFilter: " + filterTypeName);
    }
    return interceptorId;
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory) AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)

Example 2 with InterceptorArgumentProvider

use of com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider in project pinpoint by naver.

the class AnnotatedInterceptorFactory method getInterceptor.

@Override
public Interceptor getInterceptor(ClassLoader classLoader, String interceptorClassName, Object[] providedArguments, InterceptorScope scope, ExecutionPolicy policy, InstrumentClass target, InstrumentMethod targetMethod) {
    Class<? extends Interceptor> interceptorType = pluginContext.injectClass(classLoader, interceptorClassName);
    if (scope == null) {
        Scope interceptorScope = interceptorType.getAnnotation(Scope.class);
        if (interceptorScope != null) {
            String scopeName = interceptorScope.value();
            scope = pluginContext.getInterceptorScope(scopeName);
            policy = interceptorScope.executionPolicy();
        }
    }
    AutoBindingObjectFactory factory = new AutoBindingObjectFactory(profilerConfig, traceContext, pluginContext, classLoader);
    ObjectFactory objectFactory = ObjectFactory.byConstructor(interceptorClassName, providedArguments);
    InterceptorArgumentProvider interceptorArgumentProvider = new InterceptorArgumentProvider(dataSourceMonitorRegistry, apiMetaDataService, scope, target, targetMethod);
    Interceptor interceptor = (Interceptor) factory.createInstance(objectFactory, interceptorArgumentProvider);
    if (scope != null) {
        if (exceptionHandle) {
            interceptor = wrapByExceptionHandleScope(interceptor, scope, policy == null ? ExecutionPolicy.BOUNDARY : policy);
        } else {
            interceptor = wrapByScope(interceptor, scope, policy == null ? ExecutionPolicy.BOUNDARY : policy);
        }
    } else {
        if (exceptionHandle) {
            interceptor = wrapByExceptionHandle(interceptor);
        }
    }
    return interceptor;
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) InterceptorScope(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope) Scope(com.navercorp.pinpoint.bootstrap.interceptor.annotation.Scope) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory) AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider) ExceptionHandleScopedStaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedStaticAroundInterceptor) ExceptionHandleScopedInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedInterceptor) ExceptionHandleAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleAroundInterceptor) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) ExceptionHandleStaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleStaticAroundInterceptor) ScopedInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedInterceptor) StaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.StaticAroundInterceptor) ExceptionHandleScopedApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedApiIdAwareAroundInterceptor) AroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor) ScopedApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedApiIdAwareAroundInterceptor) ApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ApiIdAwareAroundInterceptor) ScopedStaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedStaticAroundInterceptor) ExceptionHandleApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleApiIdAwareAroundInterceptor)

Example 3 with InterceptorArgumentProvider

use of com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider in project pinpoint by naver.

the class JavassistClass method addInterceptor0.

private int addInterceptor0(TargetFilter annotation, String interceptorClassName, InterceptorScope scope, ExecutionPolicy executionPolicy, Object[] constructorArgs) throws InstrumentException {
    String filterTypeName = annotation.type();
    Asserts.notNull(filterTypeName, "type of @TargetFilter");
    InterceptorArgumentProvider interceptorArgumentProvider = this.objectBinderFactory.newInterceptorArgumentProvider(this);
    AutoBindingObjectFactory filterFactory = this.objectBinderFactory.newAutoBindingObjectFactory(pluginContext, classLoader, interceptorArgumentProvider);
    final ObjectFactory objectFactory = ObjectFactory.byConstructor(filterTypeName, (Object[]) annotation.constructorArguments());
    MethodFilter filter = (MethodFilter) filterFactory.createInstance(objectFactory);
    boolean singleton = annotation.singleton();
    int interceptorId = -1;
    for (InstrumentMethod m : getDeclaredMethods(filter)) {
        if (singleton && interceptorId != -1) {
            m.addInterceptor(interceptorId);
        } else {
            // TODO casting fix
            interceptorId = ((JavassistMethod) m).addInterceptorInternal(interceptorClassName, constructorArgs, scope, executionPolicy);
        }
    }
    if (interceptorId == -1) {
        logger.warn("No methods are intercepted. target: " + ctClass.getName(), ", interceptor: " + interceptorClassName + ", methodFilter: " + filterTypeName);
    }
    return interceptorId;
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory) AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider)

Example 4 with InterceptorArgumentProvider

use of com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider in project pinpoint by naver.

the class TargetAnnotatedInterceptorInjector method createFilteredMethodEditor.

private MethodTransformer createFilteredMethodEditor(TargetFilter annotation, InstrumentClass targetClass, AnnotatedInterceptorInjector injector, ClassLoader classLoader) {
    String type = annotation.type();
    if (type == null) {
        throw new PinpointException("type of @TargetFilter is null: " + interceptorClassName);
    }
    final InterceptorArgumentProvider interceptorArgumentProvider = new InterceptorArgumentProvider(dataSourceMonitorRegistry, apiMetaDataService, targetClass);
    AutoBindingObjectFactory filterFactory = new AutoBindingObjectFactory(profilerConfig, traceContext, pluginContext, classLoader, interceptorArgumentProvider);
    MethodFilter filter = (MethodFilter) filterFactory.createInstance(ObjectFactory.byConstructor(type, (Object[]) annotation.constructorArguments()));
    MethodRecipe recipe = annotation.singleton() ? new SharedAnnotatedInterceptorInjector(injector) : injector;
    return new FilteringMethodTransformer(new MethodFilter[] { filter }, Arrays.<MethodRecipe>asList(recipe), null);
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) MethodRecipe(com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodRecipe) PinpointException(com.navercorp.pinpoint.exception.PinpointException) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider) FilteringMethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer)

Aggregations

AutoBindingObjectFactory (com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory)4 InterceptorArgumentProvider (com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider)4 ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)3 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)2 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)1 ApiIdAwareAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ApiIdAwareAroundInterceptor)1 AroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor)1 ExceptionHandleApiIdAwareAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleApiIdAwareAroundInterceptor)1 ExceptionHandleAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleAroundInterceptor)1 ExceptionHandleStaticAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleStaticAroundInterceptor)1 Interceptor (com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)1 StaticAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.StaticAroundInterceptor)1 Scope (com.navercorp.pinpoint.bootstrap.interceptor.annotation.Scope)1 ExceptionHandleScopedApiIdAwareAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedApiIdAwareAroundInterceptor)1 ExceptionHandleScopedInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedInterceptor)1 ExceptionHandleScopedStaticAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedStaticAroundInterceptor)1 InterceptorScope (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope)1 ScopedApiIdAwareAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedApiIdAwareAroundInterceptor)1 ScopedInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedInterceptor)1 ScopedStaticAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedStaticAroundInterceptor)1