Search in sources :

Example 1 with ReferenceBean

use of com.alibaba.dubbo.config.spring.ReferenceBean in project dubbo by alibaba.

the class ReferenceAnnotationBeanPostProcessor method destroy.

@Override
public void destroy() throws Exception {
    for (ReferenceBean referenceBean : referenceBeansCache.values()) {
        if (logger.isInfoEnabled()) {
            logger.info(referenceBean + " was destroying!");
        }
        referenceBean.destroy();
    }
    injectionMetadataCache.clear();
    referenceBeansCache.clear();
    if (logger.isInfoEnabled()) {
        logger.info(getClass() + " was destroying!");
    }
}
Also used : ReferenceBean(com.alibaba.dubbo.config.spring.ReferenceBean)

Example 2 with ReferenceBean

use of com.alibaba.dubbo.config.spring.ReferenceBean in project dubbo by alibaba.

the class ReferenceAnnotationBeanPostProcessorTest method testGetReferenceBeans.

/**
 * Test on {@link ReferenceAnnotationBeanPostProcessor#getReferenceBeans()}
 */
@Test
public void testGetReferenceBeans() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestBean.class);
    ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME, ReferenceAnnotationBeanPostProcessor.class);
    Collection<ReferenceBean<?>> referenceBeans = beanPostProcessor.getReferenceBeans();
    Assert.assertEquals(1, referenceBeans.size());
    ReferenceBean<?> referenceBean = referenceBeans.iterator().next();
    TestBean testBean = context.getBean(TestBean.class);
    Assert.assertEquals(referenceBean.get(), testBean.getDemoServiceFromAncestor());
    Assert.assertEquals(referenceBean.get(), testBean.getDemoServiceFromParent());
    Assert.assertEquals(referenceBean.get(), testBean.getDemoService());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ReferenceBean(com.alibaba.dubbo.config.spring.ReferenceBean) Test(org.junit.Test)

Example 3 with ReferenceBean

use of com.alibaba.dubbo.config.spring.ReferenceBean 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

ReferenceBean (com.alibaba.dubbo.config.spring.ReferenceBean)3 ReferenceAnnotationBeanPostProcessor (com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor)1 Test (org.junit.Test)1 InjectionMetadata (org.springframework.beans.factory.annotation.InjectionMetadata)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1