Example usage for org.springframework.integration.context IntegrationContextUtils AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME

List of usage examples for org.springframework.integration.context IntegrationContextUtils AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME

Introduction

In this page you can find the example usage for org.springframework.integration.context IntegrationContextUtils AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME.

Prototype

String AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME

To view the source code for org.springframework.integration.context IntegrationContextUtils AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME.

Click Source Link

Usage

From source file:org.springframework.integration.config.ChannelInitializer.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(this.beanFactory, "'beanFactory' must not be null");
    if (!this.autoCreate) {
        return;/*  w w w. ja  va  2  s  . c  o m*/
    } else {
        AutoCreateCandidatesCollector channelCandidatesCollector = this.beanFactory.getBean(
                IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME,
                AutoCreateCandidatesCollector.class);
        Assert.notNull(channelCandidatesCollector,
                "Failed to locate '" + IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME);
        // at this point channelNames are all resolved with placeholders and SpEL
        Collection<String> channelNames = channelCandidatesCollector.getChannelNames();
        if (channelNames != null) {
            for (String channelName : channelNames) {
                if (!this.beanFactory.containsBean(channelName)) {
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug("Auto-creating channel '" + channelName + "' as DirectChannel");
                    }
                    IntegrationConfigUtils.autoCreateDirectChannel(channelName,
                            (BeanDefinitionRegistry) this.beanFactory);
                }
            }
        }
    }
}

From source file:org.springframework.integration.config.IntegrationRegistrar.java

/**
 * This method will auto-register a ChannelInitializer which could also be overridden by the user
 * by simply registering a ChannelInitializer {@code <bean>} with its {@code autoCreate} property
 * set to false to suppress channel creation.
 * It will also register a ChannelInitializer$AutoCreateCandidatesCollector
 * which simply collects candidate channel names.
 * @param registry The {@link BeanDefinitionRegistry} to register additional {@link BeanDefinition}s.
 *///from w  w  w . ja  v  a  2 s . co m
private void registerImplicitChannelCreator(BeanDefinitionRegistry registry) {
    if (!registry.containsBeanDefinition(IntegrationContextUtils.CHANNEL_INITIALIZER_BEAN_NAME)) {
        String channelsAutoCreateExpression = IntegrationProperties
                .getExpressionFor(IntegrationProperties.CHANNELS_AUTOCREATE);
        BeanDefinitionBuilder channelDef = BeanDefinitionBuilder.genericBeanDefinition(ChannelInitializer.class)
                .addPropertyValue("autoCreate", channelsAutoCreateExpression);
        BeanDefinitionHolder channelCreatorHolder = new BeanDefinitionHolder(channelDef.getBeanDefinition(),
                IntegrationContextUtils.CHANNEL_INITIALIZER_BEAN_NAME);
        BeanDefinitionReaderUtils.registerBeanDefinition(channelCreatorHolder, registry);
    }

    if (!registry.containsBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)) {
        BeanDefinitionBuilder channelRegistryBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(ChannelInitializer.AutoCreateCandidatesCollector.class);
        channelRegistryBuilder.addConstructorArgValue(new ManagedSet<String>());
        channelRegistryBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); //SPR-12761
        BeanDefinitionHolder channelRegistryHolder = new BeanDefinitionHolder(
                channelRegistryBuilder.getBeanDefinition(),
                IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME);
        BeanDefinitionReaderUtils.registerBeanDefinition(channelRegistryHolder, registry);
    }
}