Search in sources :

Example 1 with TargetMethods

use of com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods in project pinpoint by naver.

the class ASMClass method addInterceptor0.

private int addInterceptor0(String interceptorClassName, Object[] constructorArgs, InterceptorScope scope, ExecutionPolicy executionPolicy) throws InstrumentException {
    int interceptorId = -1;
    final Class<?> interceptorType = this.pluginContext.injectClass(this.classLoader, interceptorClassName);
    final TargetMethods targetMethods = interceptorType.getAnnotation(TargetMethods.class);
    if (targetMethods != null) {
        for (TargetMethod m : targetMethods.value()) {
            interceptorId = addInterceptor0(m, interceptorClassName, constructorArgs, scope, executionPolicy);
        }
    }
    final TargetMethod targetMethod = interceptorType.getAnnotation(TargetMethod.class);
    if (targetMethod != null) {
        interceptorId = addInterceptor0(targetMethod, interceptorClassName, constructorArgs, scope, executionPolicy);
    }
    final TargetConstructors targetConstructors = interceptorType.getAnnotation(TargetConstructors.class);
    if (targetConstructors != null) {
        for (TargetConstructor c : targetConstructors.value()) {
            interceptorId = addInterceptor0(c, interceptorClassName, scope, executionPolicy, constructorArgs);
        }
    }
    final TargetConstructor targetConstructor = interceptorType.getAnnotation(TargetConstructor.class);
    if (targetConstructor != null) {
        interceptorId = addInterceptor0(targetConstructor, interceptorClassName, scope, executionPolicy, constructorArgs);
    }
    final TargetFilter targetFilter = interceptorType.getAnnotation(TargetFilter.class);
    if (targetFilter != null) {
        interceptorId = addInterceptor0(targetFilter, interceptorClassName, scope, executionPolicy, constructorArgs);
    }
    if (interceptorId == -1) {
        throw new PinpointException("No target is specified. At least one of @Targets, @TargetMethod, @TargetConstructor, @TargetFilter must present. interceptor: " + interceptorClassName);
    }
    return interceptorId;
}
Also used : TargetConstructors(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructors) TargetMethod(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod) TargetMethods(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods) PinpointException(com.navercorp.pinpoint.exception.PinpointException) TargetConstructor(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructor) TargetFilter(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetFilter)

Example 2 with TargetMethods

use of com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods in project pinpoint by naver.

the class TargetAnnotatedInterceptorInjector method createMethodEditor.

private ClassRecipe createMethodEditor(ClassLoader classLoader, Class<?> interceptorType, InstrumentClass targetClass, AnnotatedInterceptorInjector injector) {
    List<MethodTransformer> editors = new ArrayList<MethodTransformer>();
    TargetMethods targetMethods = interceptorType.getAnnotation(TargetMethods.class);
    if (targetMethods != null) {
        for (TargetMethod m : targetMethods.value()) {
            editors.add(createDedicatedMethodEditor(m, injector));
        }
    }
    TargetConstructors targetConstructors = interceptorType.getAnnotation(TargetConstructors.class);
    if (targetConstructors != null) {
        for (TargetConstructor c : targetConstructors.value()) {
            editors.add(createConstructorEditor(c, injector));
        }
    }
    TargetMethod targetMethod = interceptorType.getAnnotation(TargetMethod.class);
    if (targetMethod != null) {
        editors.add(createDedicatedMethodEditor(targetMethod, injector));
    }
    TargetConstructor targetConstructor = interceptorType.getAnnotation(TargetConstructor.class);
    if (targetConstructor != null) {
        editors.add(createConstructorEditor(targetConstructor, injector));
    }
    TargetFilter targetFilter = interceptorType.getAnnotation(TargetFilter.class);
    if (targetFilter != null) {
        editors.add(createFilteredMethodEditor(targetFilter, targetClass, injector, classLoader));
    }
    if (editors.isEmpty()) {
        throw new PinpointException("No target is specified. At least one of @Targets, @TargetMethod, @TargetConstructor, @TargetFilter must present. interceptor: " + interceptorClassName);
    }
    return editors.size() == 1 ? editors.get(0) : new ClassCookBook(editors);
}
Also used : TargetConstructors(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructors) MethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodTransformer) DedicatedMethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.DedicatedMethodTransformer) FilteringMethodTransformer(com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer) TargetMethod(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod) ClassCookBook(com.navercorp.pinpoint.profiler.plugin.xml.transformer.ClassCookBook) TargetMethods(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods) PinpointException(com.navercorp.pinpoint.exception.PinpointException) ArrayList(java.util.ArrayList) TargetConstructor(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructor) TargetFilter(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetFilter)

Example 3 with TargetMethods

use of com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods in project pinpoint by naver.

the class JavassistClass method addInterceptor0.

private int addInterceptor0(String interceptorClassName, Object[] constructorArgs, InterceptorScope scope, ExecutionPolicy executionPolicy) throws InstrumentException {
    int interceptorId = -1;
    final Class<?> interceptorType = pluginContext.injectClass(classLoader, interceptorClassName);
    final TargetMethods targetMethods = interceptorType.getAnnotation(TargetMethods.class);
    if (targetMethods != null) {
        for (TargetMethod m : targetMethods.value()) {
            interceptorId = addInterceptor0(m, interceptorClassName, constructorArgs, scope, executionPolicy);
        }
    }
    final TargetMethod targetMethod = interceptorType.getAnnotation(TargetMethod.class);
    if (targetMethod != null) {
        interceptorId = addInterceptor0(targetMethod, interceptorClassName, constructorArgs, scope, executionPolicy);
    }
    final TargetConstructors targetConstructors = interceptorType.getAnnotation(TargetConstructors.class);
    if (targetConstructors != null) {
        for (TargetConstructor c : targetConstructors.value()) {
            interceptorId = addInterceptor0(c, interceptorClassName, scope, executionPolicy, constructorArgs);
        }
    }
    final TargetConstructor targetConstructor = interceptorType.getAnnotation(TargetConstructor.class);
    if (targetConstructor != null) {
        interceptorId = addInterceptor0(targetConstructor, interceptorClassName, scope, executionPolicy, constructorArgs);
    }
    final TargetFilter targetFilter = interceptorType.getAnnotation(TargetFilter.class);
    if (targetFilter != null) {
        interceptorId = addInterceptor0(targetFilter, interceptorClassName, scope, executionPolicy, constructorArgs);
    }
    if (interceptorId == -1) {
        throw new PinpointException("No target is specified. At least one of @Targets, @TargetMethod, @TargetConstructor, @TargetFilter must present. interceptor: " + interceptorClassName);
    }
    return interceptorId;
}
Also used : TargetConstructors(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructors) TargetMethod(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod) TargetMethods(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods) PinpointException(com.navercorp.pinpoint.exception.PinpointException) TargetConstructor(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructor) TargetFilter(com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetFilter)

Aggregations

TargetConstructor (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructor)3 TargetConstructors (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetConstructors)3 TargetFilter (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetFilter)3 TargetMethod (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod)3 TargetMethods (com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethods)3 PinpointException (com.navercorp.pinpoint.exception.PinpointException)3 ClassCookBook (com.navercorp.pinpoint.profiler.plugin.xml.transformer.ClassCookBook)1 DedicatedMethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.DedicatedMethodTransformer)1 FilteringMethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer)1 MethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodTransformer)1 ArrayList (java.util.ArrayList)1