In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
本篇内容介绍了"dubbo spring boot中DubboShutdownMetadata的实例用法"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
AbstractDubboMetadata
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 Map resolveBeanMetadata(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声明实现了ApplicationContextAware及EnvironmentAware接口;提供了getServiceBeansMap、getReferenceAnnotationBeanPostProcessor、getProtocolConfigsBeanMap实现类使用
DubboShutdownMetadata
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
@Componentpublic class DubboShutdownMetadata extends AbstractDubboMetadata { public Map shutdown() 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,挨个执行serviceBean.destroy()方法,最后执行ReferenceAnnotationBeanPostProcessor.destroy方法
ReferenceAnnotationBeanPostProcessor
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> injectedFieldReferenceBeanCache = new ConcurrentHashMap(CACHE_SIZE); private final ConcurrentMap
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.