Search in sources :

Example 1 with ObjectFactory

use of com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory 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 ObjectFactory

use of com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory 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 ObjectFactory

use of com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory in project pinpoint by naver.

the class SpringBeansPlugin method addAbstractAutowireCapableBeanFactoryTransformer.

private void addAbstractAutowireCapableBeanFactoryTransformer(final ProfilerPluginSetupContext context) {
    final ProfilerConfig config = context.getConfig();
    final boolean errorMark = config.readBoolean(SPRING_BEANS_MARK_ERROR, false);
    transformTemplate.transform("org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory", new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            final BeanMethodTransformer beanTransformer = new BeanMethodTransformer(errorMark);
            final ObjectFactory beanFilterFactory = ObjectFactory.byStaticFactory("com.navercorp.pinpoint.plugin.spring.beans.interceptor.TargetBeanFilter", "of", config);
            final InstrumentMethod createBeanInstance = target.getDeclaredMethod("createBeanInstance", "java.lang.String", "org.springframework.beans.factory.support.RootBeanDefinition", "java.lang.Object[]");
            createBeanInstance.addInterceptor("com.navercorp.pinpoint.plugin.spring.beans.interceptor.CreateBeanInstanceInterceptor", va(beanTransformer, beanFilterFactory));
            final InstrumentMethod postProcessor = target.getDeclaredMethod("applyBeanPostProcessorsBeforeInstantiation", "java.lang.Class", "java.lang.String");
            postProcessor.addInterceptor("com.navercorp.pinpoint.plugin.spring.beans.interceptor.PostProcessorInterceptor", va(beanTransformer, beanFilterFactory));
            return target.toBytecode();
        }
    });
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)

Example 4 with ObjectFactory

use of com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory in project pinpoint by naver.

the class SpringBeansPlugin method addClassPathDefinitionScannerTransformer.

private void addClassPathDefinitionScannerTransformer(final ProfilerPluginSetupContext context) {
    final ProfilerConfig config = context.getConfig();
    final boolean errorMark = config.readBoolean(SPRING_BEANS_MARK_ERROR, false);
    transformTemplate.transform("org.springframework.context.annotation.ClassPathBeanDefinitionScanner", new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            final BeanMethodTransformer beanTransformer = new BeanMethodTransformer(errorMark);
            final ObjectFactory beanFilterFactory = ObjectFactory.byStaticFactory("com.navercorp.pinpoint.plugin.spring.beans.interceptor.TargetBeanFilter", "of", context.getConfig());
            final InstrumentMethod method = target.getDeclaredMethod("doScan", "java.lang.String[]");
            method.addInterceptor("com.navercorp.pinpoint.plugin.spring.beans.interceptor.ClassPathDefinitionScannerDoScanInterceptor", va(loader, beanTransformer, beanFilterFactory));
            return target.toBytecode();
        }
    });
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)

Example 5 with ObjectFactory

use of com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory 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)

Aggregations

ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)5 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)3 AutoBindingObjectFactory (com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory)3 InterceptorArgumentProvider (com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider)3 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)2 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)2 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)2 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)2 ProtectionDomain (java.security.ProtectionDomain)2 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)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