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;
}
Aggregations