Search in sources :

Example 1 with ByStaticFactoryMethod

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

Aggregations

ByStaticFactoryMethod (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory.ByStaticFactoryMethod)1 PinpointException (com.navercorp.pinpoint.exception.PinpointException)1 Method (java.lang.reflect.Method)1