Example usage for org.springframework.integration.endpoint PollingConsumer setTrigger

List of usage examples for org.springframework.integration.endpoint PollingConsumer setTrigger

Introduction

In this page you can find the example usage for org.springframework.integration.endpoint PollingConsumer setTrigger.

Prototype

public void setTrigger(Trigger trigger) 

Source Link

Usage

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

private void initializeEndpoint() throws Exception {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }/*from ww  w .  j  a  va 2 s.  c om*/
        MessageChannel channel = null;
        if (StringUtils.hasText(this.inputChannelName)) {
            Assert.isTrue(this.beanFactory.containsBean(this.inputChannelName), "no such input channel '"
                    + this.inputChannelName + "' for endpoint '" + this.beanName + "'");
            channel = this.beanFactory.getBean(this.inputChannelName, MessageChannel.class);
        }
        if (this.inputChannel != null) {
            channel = this.inputChannel;
        }
        Assert.state(channel != null, "one of inputChannelName or inputChannel is required");
        if (channel instanceof SubscribableChannel) {
            Assert.isNull(this.pollerMetadata, "A poller should not be specified for endpoint '" + this.beanName
                    + "', since '" + channel + "' is a SubscribableChannel (not pollable).");
            this.endpoint = new EventDrivenConsumer((SubscribableChannel) channel, this.handler);
        } else if (channel instanceof PollableChannel) {
            PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) channel, this.handler);
            if (this.pollerMetadata == null) {
                this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
                Assert.notNull(this.pollerMetadata, "No poller has been defined for endpoint '" + this.beanName
                        + "', and no default poller is available within the context.");
            }
            pollingConsumer.setTaskExecutor(this.pollerMetadata.getTaskExecutor());
            pollingConsumer.setTrigger(this.pollerMetadata.getTrigger());
            pollingConsumer.setAdviceChain(this.pollerMetadata.getAdviceChain());
            pollingConsumer.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll());

            pollingConsumer.setErrorHandler(this.pollerMetadata.getErrorHandler());

            pollingConsumer.setReceiveTimeout(this.pollerMetadata.getReceiveTimeout());
            pollingConsumer.setTransactionSynchronizationFactory(
                    this.pollerMetadata.getTransactionSynchronizationFactory());
            pollingConsumer.setBeanClassLoader(beanClassLoader);
            pollingConsumer.setBeanFactory(beanFactory);
            this.endpoint = pollingConsumer;
        } else {
            throw new IllegalArgumentException("unsupported channel type: [" + channel.getClass() + "]");
        }
        this.endpoint.setBeanName(this.beanName);
        this.endpoint.setBeanFactory(this.beanFactory);
        this.endpoint.setAutoStartup(this.autoStartup);
        this.endpoint.afterPropertiesSet();
        this.initialized = true;
    }
}