Search in sources :

Example 6 with ServiceFactoryBean

use of com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean in project sofa-boot by sofastack.

the class BeanLoadCostBeanFactory method createBean.

@Override
protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) throws BeanCreationException {
    Stack<BeanStat> parentStack = parentStackThreadLocal.get();
    BeanStat bs = new BeanStat();
    if (parentStack == null) {
        parentStack = new Stack<>();
        parentStackThreadLocal.set(parentStack);
    }
    if (!parentStack.empty()) {
        parentStack.peek().addChild(bs);
    }
    parentStack.push(bs);
    bs.startRefresh();
    Object object = super.createBean(beanName, mbd, args);
    bs.finishRefresh();
    if (mbd.getBeanClassName() == null) {
        bs.setBeanClassName("Factory (" + mbd.getFactoryBeanName() + ")");
    } else {
        if (mbd.getBeanClassName().contains("ExtensionPointFactoryBean") || mbd.getBeanClassName().contains("ExtensionFactoryBean")) {
            bs.setExtensionProperty(object.toString());
        }
        if (object instanceof ServiceFactoryBean) {
            bs.setBeanClassName(mbd.getBeanClassName() + " (" + ((ServiceFactoryBean) object).getBeanId() + ")");
            bs.setInterfaceType(((ServiceFactoryBean) object).getInterfaceType());
        } else if (object instanceof ReferenceFactoryBean) {
            bs.setBeanClassName(mbd.getBeanClassName() + " (" + beanName + ")");
            bs.setInterfaceType(((ReferenceFactoryBean) object).getInterfaceType());
        } else {
            bs.setBeanClassName(mbd.getBeanClassName() + " (" + beanName + ")");
            if (beanName.contains(mbd.getBeanClassName())) {
                bs.setBeanClassName(mbd.getBeanClassName());
            }
        }
    }
    if (beanStatExtension != null) {
        beanStatExtension.customBeanStat(beanName, mbd, args, bs);
    }
    parentStack.pop();
    if (parentStack.empty() && bs.getRefreshElapsedTime() > beanLoadCost) {
        beanStats.add(bs);
    }
    return object;
}
Also used : ServiceFactoryBean(com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean) ReferenceFactoryBean(com.alipay.sofa.runtime.spring.factory.ReferenceFactoryBean) BeanStat(com.alipay.sofa.boot.startup.BeanStat)

Aggregations

ServiceFactoryBean (com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean)6 ReferenceFactoryBean (com.alipay.sofa.runtime.spring.factory.ReferenceFactoryBean)4 Test (org.junit.Test)4 BeanStat (com.alipay.sofa.boot.startup.BeanStat)2 BindingType (com.alipay.sofa.runtime.api.binding.BindingType)2 HashMap (java.util.HashMap)2 SpringApplication (org.springframework.boot.SpringApplication)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ApplicationContext (org.springframework.context.ApplicationContext)2