use of org.springframework.beans.factory.BeanFactoryAware in project spring-cloud-stream by spring-cloud.
the class AbstractMessageChannelBinder method bindPollableConsumer.
@Override
public Binding<PollableSource<MessageHandler>> bindPollableConsumer(String name, String group, final PollableSource<MessageHandler> inboundBindTarget, C properties) {
Assert.isInstanceOf(DefaultPollableMessageSource.class, inboundBindTarget);
DefaultPollableMessageSource bindingTarget = (DefaultPollableMessageSource) inboundBindTarget;
ConsumerDestination destination = this.provisioningProvider.provisionConsumerDestination(name, group, properties);
if (HeaderMode.embeddedHeaders.equals(properties.getHeaderMode())) {
bindingTarget.addInterceptor(0, this.embeddedHeadersChannelInterceptor);
}
final PolledConsumerResources resources = createPolledConsumerResources(name, group, destination, properties);
MessageSource<?> messageSource = resources.getSource();
if (messageSource instanceof BeanFactoryAware) {
((BeanFactoryAware) messageSource).setBeanFactory(getApplicationContext().getBeanFactory());
}
bindingTarget.setSource(messageSource);
if (resources.getErrorInfrastructure() != null) {
if (resources.getErrorInfrastructure().getErrorChannel() != null) {
bindingTarget.setErrorChannel(resources.getErrorInfrastructure().getErrorChannel());
}
ErrorMessageStrategy ems = getErrorMessageStrategy();
if (ems != null) {
bindingTarget.setErrorMessageStrategy(ems);
}
}
if (properties.getMaxAttempts() > 1) {
bindingTarget.setRetryTemplate(buildRetryTemplate(properties));
bindingTarget.setRecoveryCallback(getPolledConsumerRecoveryCallback(resources.getErrorInfrastructure(), properties));
}
postProcessPollableSource(bindingTarget);
if (properties.isAutoStartup() && resources.getSource() instanceof Lifecycle) {
((Lifecycle) resources.getSource()).start();
}
Binding<PollableSource<MessageHandler>> binding = new DefaultBinding<PollableSource<MessageHandler>>(name, group, inboundBindTarget, resources.getSource() instanceof Lifecycle ? (Lifecycle) resources.getSource() : null) {
@Override
public Map<String, Object> getExtendedInfo() {
return doGetExtendedInfo(destination, properties);
}
@Override
public boolean isInput() {
return true;
}
@Override
public void afterUnbind() {
afterUnbindConsumer(destination, this.group, properties);
destroyErrorInfrastructure(destination, this.group, properties);
}
};
doPublishEvent(new BindingCreatedEvent(binding));
return binding;
}
use of org.springframework.beans.factory.BeanFactoryAware in project spring-integration by spring-projects.
the class AbstractCorrelatingMessageHandler method onInit.
@Override
protected void onInit() throws Exception {
super.onInit();
Assert.state(!(this.discardChannelName != null && this.discardChannel != null), "'discardChannelName' and 'discardChannel' are mutually exclusive.");
BeanFactory beanFactory = this.getBeanFactory();
if (beanFactory != null) {
if (this.outputProcessor instanceof BeanFactoryAware) {
((BeanFactoryAware) this.outputProcessor).setBeanFactory(beanFactory);
}
if (this.correlationStrategy instanceof BeanFactoryAware) {
((BeanFactoryAware) this.correlationStrategy).setBeanFactory(beanFactory);
}
if (this.releaseStrategy instanceof BeanFactoryAware) {
((BeanFactoryAware) this.releaseStrategy).setBeanFactory(beanFactory);
}
}
if (this.discardChannel == null) {
this.discardChannel = new NullChannel();
}
if (this.releasePartialSequences) {
Assert.isInstanceOf(SequenceSizeReleaseStrategy.class, this.releaseStrategy, "Release strategy of type [" + this.releaseStrategy.getClass().getSimpleName() + "] cannot release partial sequences. Use a SequenceSizeReleaseStrategy instead.");
((SequenceSizeReleaseStrategy) this.releaseStrategy).setReleasePartialSequences(this.releasePartialSequences);
}
if (this.evaluationContext == null) {
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
}
if (this.sequenceAware) {
this.logger.warn("Using a SequenceSizeReleaseStrategy with large groups may not perform well, consider " + "using a SimpleSequenceSizeReleaseStrategy");
}
/*
* Disallow any further changes to the lock registry
* (checked in the setter).
*/
this.lockRegistrySet = true;
this.forceReleaseProcessor = createGroupTimeoutProcessor();
}
use of org.springframework.beans.factory.BeanFactoryAware in project spring-integration by spring-projects.
the class FileWritingMessageHandler method doInit.
@Override
protected void doInit() {
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
if (this.destinationDirectoryExpression instanceof LiteralExpression) {
final File directory = new File(this.destinationDirectoryExpression.getValue(this.evaluationContext, null, String.class));
validateDestinationDirectory(directory, this.autoCreateDirectory);
}
Assert.state(!(this.temporaryFileSuffixSet && (FileExistsMode.APPEND.equals(this.fileExistsMode) || FileExistsMode.APPEND_NO_FLUSH.equals(this.fileExistsMode))), "'temporaryFileSuffix' can not be set when appending to an existing file");
if (!this.fileNameGeneratorSet && this.fileNameGenerator instanceof BeanFactoryAware) {
((BeanFactoryAware) this.fileNameGenerator).setBeanFactory(getBeanFactory());
}
}
use of org.springframework.beans.factory.BeanFactoryAware in project spring-integration by spring-projects.
the class RedisInboundChannelAdapter method onInit.
@Override
protected void onInit() {
super.onInit();
boolean hasTopics = false;
if (this.topics != null) {
Assert.noNullElements(this.topics, "'topics' may not contain null elements.");
hasTopics = true;
}
boolean hasPatterns = false;
if (this.topicPatterns != null) {
Assert.noNullElements(this.topicPatterns, "'topicPatterns' may not contain null elements.");
hasPatterns = true;
}
Assert.state(hasTopics || hasPatterns, "at least one topic or topic pattern is required for subscription.");
if (this.messageConverter instanceof BeanFactoryAware) {
((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
}
MessageListenerDelegate delegate = new MessageListenerDelegate();
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
adapter.setSerializer(this.serializer);
List<Topic> topicList = new ArrayList<Topic>();
if (hasTopics) {
for (String topic : this.topics) {
topicList.add(new ChannelTopic(topic));
}
}
if (hasPatterns) {
for (String pattern : this.topicPatterns) {
topicList.add(new PatternTopic(pattern));
}
}
adapter.afterPropertiesSet();
this.container.addMessageListener(adapter, topicList);
this.container.afterPropertiesSet();
}
use of org.springframework.beans.factory.BeanFactoryAware in project spring-integration by spring-projects.
the class SubscribableRedisChannel method onInit.
@Override
public void onInit() throws Exception {
if (this.initialized) {
return;
}
super.onInit();
if (this.maxSubscribers == null) {
Integer maxSubscribers = getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, Integer.class);
this.setMaxSubscribers(maxSubscribers);
}
if (this.messageConverter == null) {
this.messageConverter = new SimpleMessageConverter();
}
if (this.messageConverter instanceof BeanFactoryAware) {
((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
}
this.container.setConnectionFactory(this.connectionFactory);
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) {
ErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
}
this.container.setTaskExecutor(this.taskExecutor);
MessageListenerAdapter adapter = new MessageListenerAdapter(new MessageListenerDelegate());
adapter.setSerializer(this.serializer);
adapter.afterPropertiesSet();
this.container.addMessageListener(adapter, new ChannelTopic(this.topicName));
this.container.afterPropertiesSet();
this.dispatcher.setBeanFactory(this.getBeanFactory());
this.initialized = true;
}
Aggregations