本篇內(nèi)容介紹了“dubbo spring boot中DubboShutdownMetadata的實例用法”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)建站于2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都做網(wǎng)站、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元涵江做網(wǎng)站,已為上家服務(wù),為涵江各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220
dubbo-spring-boot-project-2.7.3/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/AbstractDubboMetadata.java
public abstract class AbstractDubboMetadata implements ApplicationContextAware, EnvironmentAware { protected ApplicationContext applicationContext; protected ConfigurableEnvironment environment; private static boolean isSimpleType(Class> type) { return isPrimitiveOrWrapper(type) || type == String.class || type == BigDecimal.class || type == BigInteger.class || type == Date.class || type == URL.class || type == Class.class ; } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } @Override public void setEnvironment(Environment environment) { if (environment instanceof ConfigurableEnvironment) { this.environment = (ConfigurableEnvironment) environment; } } protected MapresolveBeanMetadata(final Object bean) { final Map beanMetadata = new LinkedHashMap<>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod != null && isSimpleType(propertyDescriptor.getPropertyType())) { String name = Introspector.decapitalize(propertyDescriptor.getName()); Object value = readMethod.invoke(bean); beanMetadata.put(name, value); } } } catch (Exception e) { throw new RuntimeException(e); } return beanMetadata; } protected Map getServiceBeansMap() { return beansOfTypeIncludingAncestors(applicationContext, ServiceBean.class); } protected ReferenceAnnotationBeanPostProcessor getReferenceAnnotationBeanPostProcessor() { return applicationContext.getBean(BEAN_NAME, ReferenceAnnotationBeanPostProcessor.class); } protected Map getProtocolConfigsBeanMap() { return beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class); } }
AbstractDubboMetadata聲明實現(xiàn)了ApplicationContextAware及EnvironmentAware接口;提供了getServiceBeansMap、getReferenceAnnotationBeanPostProcessor、getProtocolConfigsBeanMap實現(xiàn)類使用
dubbo-spring-boot-project-2.7.3/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboShutdownMetadata.java
@Component public class DubboShutdownMetadata extends AbstractDubboMetadata { public Mapshutdown() throws Exception { Map shutdownCountData = new LinkedHashMap<>(); // registries int registriesCount = getRegistries().size(); // protocols int protocolsCount = getProtocolConfigsBeanMap().size(); shutdownCountData.put("registries", registriesCount); shutdownCountData.put("protocols", protocolsCount); // Service Beans Map serviceBeansMap = getServiceBeansMap(); if (!serviceBeansMap.isEmpty()) { for (ServiceBean serviceBean : serviceBeansMap.values()) { serviceBean.destroy(); } } shutdownCountData.put("services", serviceBeansMap.size()); // Reference Beans ReferenceAnnotationBeanPostProcessor beanPostProcessor = getReferenceAnnotationBeanPostProcessor(); int referencesCount = beanPostProcessor.getReferenceBeans().size(); beanPostProcessor.destroy(); shutdownCountData.put("references", referencesCount); // Set Result to complete Map shutdownData = new TreeMap<>(); shutdownData.put("shutdown.count", shutdownCountData); return shutdownData; } }
DubboShutdownMetadata繼承了AbstractDubboMetadata,它提供了shutdown方法,該方法會遍歷getServiceBeansMap,挨個執(zhí)行serviceBean.destroy()方法,最后執(zhí)行ReferenceAnnotationBeanPostProcessor.destroy方法
dubbo-2.7.3-sources.jar!/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBeanPostProcessor implements ApplicationContextAware, ApplicationListener { /** * The bean name of {@link ReferenceAnnotationBeanPostProcessor} */ public static final String BEAN_NAME = "referenceAnnotationBeanPostProcessor"; /** * Cache size */ private static final int CACHE_SIZE = Integer.getInteger(BEAN_NAME + ".cache.size", 32); private final ConcurrentMap> referenceBeanCache = new ConcurrentHashMap<>(CACHE_SIZE); private final ConcurrentHashMap localReferenceBeanInvocationHandlerCache = new ConcurrentHashMap<>(CACHE_SIZE); private final ConcurrentMap > injectedFieldReferenceBeanCache = new ConcurrentHashMap<>(CACHE_SIZE); private final ConcurrentMap > injectedMethodReferenceBeanCache = new ConcurrentHashMap<>(CACHE_SIZE); private ApplicationContext applicationContext; /** * To support the legacy annotation that is @com.alibaba.dubbo.config.annotation.Reference since 2.7.3 */ public ReferenceAnnotationBeanPostProcessor() { super(Reference.class, com.alibaba.dubbo.config.annotation.Reference.class); } //...... @Override public void destroy() throws Exception { super.destroy(); this.referenceBeanCache.clear(); this.localReferenceBeanInvocationHandlerCache.clear(); this.injectedFieldReferenceBeanCache.clear(); this.injectedMethodReferenceBeanCache.clear(); } }
ReferenceAnnotationBeanPostProcessor繼承了AnnotationInjectedBeanPostProcessor,實現(xiàn)了ApplicationContextAware, ApplicationListener接口;destroy方法會執(zhí)行AnnotationInjectedBeanPostProcessor.destroy,然后清空referenceBeanCache、localReferenceBeanInvocationHandlerCache、injectedFieldReferenceBeanCache、injectedMethodReferenceBeanCache
DubboShutdownMetadata繼承了AbstractDubboMetadata,它提供了shutdown方法,該方法會遍歷getServiceBeansMap,挨個執(zhí)行serviceBean.destroy()方法,最后執(zhí)行ReferenceAnnotationBeanPostProcessor.destroy方法
“dubbo spring boot中DubboShutdownMetadata的實例用法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!