千家信息网

dubbo spring boot中DubboShutdownMetadata的实例用法

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,本篇内容介绍了"dubbo spring boot中DubboShutdownMetadata的实例用法"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如
千家信息网最后更新 2026年11月03日dubbo spring boot中DubboShutdownMetadata的实例用法

本篇内容介绍了"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> 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,实现了ApplicationContextAware, ApplicationListener接口;destroy方法会执行AnnotationInjectedBeanPostProcessor.destroy,然后清空referenceBeanCache、localReferenceBeanInvocationHandlerCache、injectedFieldReferenceBeanCache、injectedMethodReferenceBeanCache

小结

DubboShutdownMetadata继承了AbstractDubboMetadata,它提供了shutdown方法,该方法会遍历getServiceBeansMap,挨个执行serviceBean.destroy()方法,最后执行ReferenceAnnotationBeanPostProcessor.destroy方法

"dubbo spring boot中DubboShutdownMetadata的实例用法"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

方法 实例 内容 接口 更多 知识 实用 学有所成 接下来 困境 实际 小结 情况 文章 案例 编带 网站 行业 过程 高质量 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 湖南永感互联网科技有限公司 互联网通讯科技 科技互联网技术 上海喔噻互联网科技 广州互联网络科技有限公司 亿账通互联网科技 中国最先进互联网科技公司 团飞科技与伯堂互联网服务平台 以后互联网后是啥科技 栖莱科技互联网股份有限公司 苏州五指互联网络科技有限 苏州铭阳互联网科技有限公司 互联网媒体平台算高科技产业 深圳市优智互联网科技有限公司 想开互联网科技公司怎么样 滨湖区互联网智能科技产品有哪些 张家口科技产业互联网平台 银川新华互联网科技学校原画 互联网科技企业文化 广州全民伙伴互联网科技有限公司 深圳恒合互联网络科技有限公司 科技信息互联网 广州宏创互联网科技 上游互联网科技 互联网科技视频素材 彤创互联网科技有限公司 互联网科技和信息 广州新华互联网科技学校电竞方面 科技信息时代互联网发展 知域互联网科技有限公司官网
0