Search in sources :

Example 1 with ReferenceAnnotationBeanPostProcessor

use of com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor in project incubator-dubbo-spring-boot-project by apache.

the class DubboMvcEndpoint method shutdown.

@RequestMapping(value = DUBBO_SHUTDOWN_ENDPOINT_URI, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public DeferredResult shutdown() throws Exception {
    DeferredResult result = new DeferredResult();
    Map<String, Object> shutdownCountData = new LinkedHashMap<>();
    // registries
    int registriesCount = getRegistries().size();
    // protocols
    int protocolsCount = getProtocolConfigsBeanMap().size();
    ProtocolConfig.destroyAll();
    shutdownCountData.put("registries", registriesCount);
    shutdownCountData.put("protocols", protocolsCount);
    // Service Beans
    Map<String, ServiceBean> 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<String, Object> shutdownData = new TreeMap<>();
    shutdownData.put("shutdown.count", shutdownCountData);
    result.setResult(shutdownData);
    return result;
}
Also used : ReferenceAnnotationBeanPostProcessor(com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor) ServiceBean(com.alibaba.dubbo.config.spring.ServiceBean) DubboEndpoint(com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) DeferredResult(org.springframework.web.context.request.async.DeferredResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ReferenceAnnotationBeanPostProcessor

use of com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor in project incubator-dubbo-spring-boot-project by apache.

the class DubboMvcEndpoint method resolveInjectedElementReferenceBeanMap.

/**
 * Resolves the {@link Collection} of {@link InjectionMetadata.InjectedElement} that were annotated by {@link Reference}
 * from all Spring Beans.
 *
 * @return non-null {@link Collection}
 * TODO Reactors ReferenceAnnotationBeanPostProcessor to expose those info
 */
private Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> resolveInjectedElementReferenceBeanMap() {
    Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> injectedElementReferenceBeanMap = new LinkedHashMap<>();
    final ReferenceAnnotationBeanPostProcessor processor = getReferenceAnnotationBeanPostProcessor();
    ConcurrentMap<String, InjectionMetadata> injectionMetadataCache = getFieldValue(processor, "injectionMetadataCache", ConcurrentMap.class);
    ConcurrentMap<String, ReferenceBean<?>> referenceBeansCache = getFieldValue(processor, "referenceBeansCache", ConcurrentMap.class);
    for (InjectionMetadata metadata : injectionMetadataCache.values()) {
        Set<InjectionMetadata.InjectedElement> checkedElements = getFieldValue(metadata, "checkedElements", Set.class);
        Collection<InjectionMetadata.InjectedElement> injectedElements = getFieldValue(metadata, "injectedElements", Collection.class);
        Collection<InjectionMetadata.InjectedElement> actualInjectedElements = checkedElements != null ? checkedElements : injectedElements;
        for (InjectionMetadata.InjectedElement injectedElement : actualInjectedElements) {
            ReferenceBean<?> referenceBean = resolveReferenceBean(injectedElement, referenceBeansCache);
            injectedElementReferenceBeanMap.put(injectedElement, referenceBean);
        }
    }
    return injectedElementReferenceBeanMap;
}
Also used : ReferenceAnnotationBeanPostProcessor(com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor) InjectionMetadata(org.springframework.beans.factory.annotation.InjectionMetadata) ReferenceBean(com.alibaba.dubbo.config.spring.ReferenceBean)

Aggregations

ReferenceAnnotationBeanPostProcessor (com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor)2 DubboEndpoint (com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint)1 ReferenceBean (com.alibaba.dubbo.config.spring.ReferenceBean)1 ServiceBean (com.alibaba.dubbo.config.spring.ServiceBean)1 InjectionMetadata (org.springframework.beans.factory.annotation.InjectionMetadata)1 MvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 DeferredResult (org.springframework.web.context.request.async.DeferredResult)1