Search in sources :

Example 11 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class URLClassLoaderHandler method injectClass.

@Override
@SuppressWarnings("unchecked")
public <T> Class<? extends T> injectClass(ClassLoader classLoader, String className) {
    try {
        if (classLoader instanceof URLClassLoader) {
            final URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
            addPluginURLIfAbsent(urlClassLoader);
            return (Class<T>) urlClassLoader.loadClass(className);
        }
    } catch (Exception e) {
        logger.warn("Failed to load plugin class {} with classLoader {}", className, classLoader, e);
        throw new PinpointException("Failed to load plugin class " + className + " with classLoader " + classLoader, e);
    }
    throw new PinpointException("invalid ClassLoader");
}
Also used : URLClassLoader(java.net.URLClassLoader) PinpointException(com.navercorp.pinpoint.exception.PinpointException) PinpointException(com.navercorp.pinpoint.exception.PinpointException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class AutoBindingObjectFactory method byConstructor.

private Object byConstructor(Class<?> type, ByConstructor byConstructor, ArgumentsResolver argumentsResolver) {
    final ConstructorResolver resolver = new ConstructorResolver(type, argumentsResolver);
    if (!resolver.resolve()) {
        throw new PinpointException("Cannot find suitable constructor for " + type.getName());
    }
    final Constructor<?> constructor = resolver.getResolvedConstructor();
    final Object[] resolvedArguments = resolver.getResolvedArguments();
    if (isDebug) {
        logger.debug("Create instance by constructor {}, with arguments {}", constructor, Arrays.toString(resolvedArguments));
    }
    try {
        return constructor.newInstance(resolvedArguments);
    } catch (Exception e) {
        throw new PinpointException("Fail to invoke constructor: " + constructor + ", arguments: " + Arrays.toString(resolvedArguments), e);
    }
}
Also used : PinpointException(com.navercorp.pinpoint.exception.PinpointException) PinpointException(com.navercorp.pinpoint.exception.PinpointException)

Example 13 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException in project pinpoint by naver.

the class AutoBindingObjectFactory method byStaticFactoryMethod.

private Object byStaticFactoryMethod(Class<?> type, ByStaticFactoryMethod staticFactoryMethod, ArgumentsResolver argumentsResolver) {
    StaticMethodResolver resolver = new StaticMethodResolver(type, staticFactoryMethod.getFactoryMethodName(), argumentsResolver);
    if (!resolver.resolve()) {
        throw new PinpointException("Cannot find suitable factory method " + type.getName() + "." + staticFactoryMethod.getFactoryMethodName());
    }
    final Method method = resolver.getResolvedMethod();
    final Object[] resolvedArguments = resolver.getResolvedArguments();
    if (isDebug) {
        logger.debug("Create instance by static factory method {}, with arguments {}", method, Arrays.toString(resolvedArguments));
    }
    try {
        return method.invoke(null, resolvedArguments);
    } catch (Exception e) {
        throw new PinpointException("Fail to invoke factory method: " + type.getName() + "." + staticFactoryMethod.getFactoryMethodName() + ", arguments: " + Arrays.toString(resolvedArguments), e);
    }
}
Also used : PinpointException(com.navercorp.pinpoint.exception.PinpointException) ByStaticFactoryMethod(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory.ByStaticFactoryMethod) Method(java.lang.reflect.Method) PinpointException(com.navercorp.pinpoint.exception.PinpointException)

Example 14 with PinpointException

use of com.navercorp.pinpoint.exception.PinpointException 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

PinpointException (com.navercorp.pinpoint.exception.PinpointException)14 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 FilteringMethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.FilteringMethodTransformer)2 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)1 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)1 ByStaticFactoryMethod (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory.ByStaticFactoryMethod)1 AutoBindingObjectFactory (com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory)1 InterceptorArgumentProvider (com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider)1 ClassCookBook (com.navercorp.pinpoint.profiler.plugin.xml.transformer.ClassCookBook)1 DedicatedMethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.DedicatedMethodTransformer)1 MethodRecipe (com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodRecipe)1 MethodTransformer (com.navercorp.pinpoint.profiler.plugin.xml.transformer.MethodTransformer)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1