Search in sources :

Example 1 with IntegrationConsumer

use of org.springframework.integration.endpoint.IntegrationConsumer in project spring-integration by spring-projects.

the class IntegrationGraphServer method consumers.

private void consumers(Collection<IntegrationNode> nodes, Collection<LinkNode> links, Map<String, MessageChannelNode> channelNodes) {
    Map<String, IntegrationConsumer> consumers = this.applicationContext.getBeansOfType(IntegrationConsumer.class);
    for (Entry<String, IntegrationConsumer> entry : consumers.entrySet()) {
        IntegrationConsumer consumer = entry.getValue();
        MessageHandlerNode handlerNode = consumer instanceof PollingConsumer ? this.nodeFactory.polledHandlerNode(entry.getKey(), (PollingConsumer) consumer) : this.nodeFactory.handlerNode(entry.getKey(), consumer);
        nodes.add(handlerNode);
        MessageChannelNode channelNode = channelNodes.get(handlerNode.getInput());
        if (channelNode != null) {
            links.add(new LinkNode(channelNode.getNodeId(), handlerNode.getNodeId(), LinkNode.Type.input));
        }
        producerLink(links, channelNodes, handlerNode);
    }
}
Also used : IntegrationConsumer(org.springframework.integration.endpoint.IntegrationConsumer) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer)

Example 2 with IntegrationConsumer

use of org.springframework.integration.endpoint.IntegrationConsumer in project spring-integration by spring-projects.

the class MockIntegrationContext method resetBeans.

/**
 * Reinstate the mocked beans after execution test to their real state.
 * Typically is used from the {@link org.junit.After} method.
 * @param beanNames the bean names to reset.
 * If {@code null}, all the mocked beans are reset
 */
public void resetBeans(String... beanNames) {
    final Collection<String> names;
    if (!ObjectUtils.isEmpty(beanNames)) {
        names = Arrays.asList(beanNames);
    } else {
        names = null;
    }
    this.beans.entrySet().stream().filter(e -> names == null || names.contains(e.getKey())).forEach(e -> {
        Object endpoint = this.beanFactory.getBean(e.getKey());
        DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(endpoint);
        if (endpoint instanceof SourcePollingChannelAdapter) {
            directFieldAccessor.setPropertyValue("source", e.getValue());
        } else if (endpoint instanceof IntegrationConsumer) {
            directFieldAccessor.setPropertyValue("handler", e.getValue());
        }
    });
}
Also used : Arrays(java.util.Arrays) MockMessageHandler(org.springframework.integration.test.mock.MockMessageHandler) Collection(java.util.Collection) ObjectUtils(org.springframework.util.ObjectUtils) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) HashMap(java.util.HashMap) BeansException(org.springframework.beans.BeansException) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageProducer(org.springframework.integration.core.MessageProducer) TestUtils(org.springframework.integration.test.util.TestUtils) MessageChannel(org.springframework.messaging.MessageChannel) MessageSource(org.springframework.integration.core.MessageSource) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Lifecycle(org.springframework.context.Lifecycle) IntegrationConsumer(org.springframework.integration.endpoint.IntegrationConsumer) MessageHandler(org.springframework.messaging.MessageHandler) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) Map(java.util.Map) BeanFactory(org.springframework.beans.factory.BeanFactory) Assert(org.springframework.util.Assert) IntegrationConsumer(org.springframework.integration.endpoint.IntegrationConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter)

Aggregations

IntegrationConsumer (org.springframework.integration.endpoint.IntegrationConsumer)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BeansException (org.springframework.beans.BeansException)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 Lifecycle (org.springframework.context.Lifecycle)1 MessageProducer (org.springframework.integration.core.MessageProducer)1 MessageSource (org.springframework.integration.core.MessageSource)1 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)1 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)1 MockMessageHandler (org.springframework.integration.test.mock.MockMessageHandler)1 TestUtils (org.springframework.integration.test.util.TestUtils)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageHandler (org.springframework.messaging.MessageHandler)1 Assert (org.springframework.util.Assert)1