@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof ApplicationListener) { // potentially not detected as a listener by getBeanNamesForType retrieval Boolean flag = this.singletonNames.get(beanName); if (Boolean.TRUE.equals(flag)) { // singleton bean (top-level or inner): register on the fly this.applicationContext.addApplicationListener((ApplicationListener<?>) bean); } else if (Boolean.FALSE.equals(flag)) { if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) { // inner bean with other scope - can't reliably process events logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " + "but is not reachable for event multicasting by its containing ApplicationContext " + "because it does not have singleton scope. Only top-level listener beans are allowed " + "to be of non-singleton scope."); } this.singletonNames.remove(beanName); } } return bean; }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof ApplicationListener) { // potentially not detected as a listener by getBeanNamesForType retrieval Boolean flag = this.singletonNames.get(beanName); if (Boolean.TRUE.equals(flag)) { // singleton bean (top-level or inner): register on the fly this.applicationContext.addApplicationListener((ApplicationListener<?>) bean); } else if (Boolean.FALSE.equals(flag)) { if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) { // inner bean with other scope - can't reliably process events logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " + "but is not reachable for event multicasting by its containing ApplicationContext " + "because it does not have singleton scope. Only top-level listener beans are allowed " + "to be of non-singleton scope."); } this.singletonNames.remove(beanName); } } return bean; }
@Test public void sendAndReceive() { this.input.send(new GenericMessage<>("foo")); Message<?> message = this.output.receive(100); assertNotNull(message); assertEquals("foo: 1", message.getPayload()); assertEquals(1, count); assertTrue(this.applicationContext.containsBean("annotatedEndpoint.process.serviceActivator")); assertTrue(this.applicationContext.containsBean("annotatedEndpoint2.process.serviceActivator")); }
@Test public void sendAndReceiveAsync() { this.inputAsync.send(new GenericMessage<>("foo")); Message<?> message = this.outputAsync.receive(100); assertNotNull(message); assertEquals("foo", message.getPayload()); assertTrue(this.applicationContext.containsBean("annotatedEndpoint3.process.serviceActivator")); }
.containsBean(IntegrationContextUtils.TO_STRING_FRIENDLY_JSON_NODE_TO_STRING_CONVERTER_BEAN_NAME));
public T lookupSharedChannel(String name) { T channel = null; if (applicationContext.containsBean(name)) { try { channel = applicationContext.getBean(name, requiredType); } catch (Exception e) { throw new IllegalArgumentException("bean '" + name + "' is already registered but does not match the required type"); } } return channel; } }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof ApplicationListener) { // potentially not detected as a listener by getBeanNamesForType retrieval Boolean flag = this.singletonNames.get(beanName); if (Boolean.TRUE.equals(flag)) { // singleton bean (top-level or inner): register on the fly this.applicationContext.addApplicationListener((ApplicationListener<?>) bean); } else if (Boolean.FALSE.equals(flag)) { if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) { // inner bean with other scope - can't reliably process events logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " + "but is not reachable for event multicasting by its containing ApplicationContext " + "because it does not have singleton scope. Only top-level listener beans are allowed " + "to be of non-singleton scope."); } this.singletonNames.remove(beanName); } } return bean; }
private boolean shouldWireDunctionToChannel(boolean producer) { if (!producer && this.producerBindingExist) { return false; } else { return this.streamFunctionProperties != null && StringUtils.hasText(this.streamFunctionProperties.getDefinition()) && ( !this.getApplicationContext().containsBean("integrationFlowCreator") || this.getApplicationContext().getBean("integrationFlowCreator").equals(null) ); } }
if (!context.containsBean("emailServer"))
if (!context.containsBean("emailServer"))
private int invokePartitionSelector(String partitionSelectorClassName, Object key, int partitionCount) { if (this.applicationContext.containsBean(partitionSelectorClassName)) { return this.applicationContext.getBean(partitionSelectorClassName, PartitionSelectorStrategy.class) .selectPartition(key, partitionCount); } Class<?> clazz; try { clazz = ClassUtils.forName(partitionSelectorClassName, this.applicationContext.getClassLoader()); } catch (Exception e) { logger.error("Failed to load partition selector", e); throw new MessageBusException("Failed to load partition selector: " + partitionSelectorClassName, e); } try { Object extractor = clazz.newInstance(); Assert.isInstanceOf(PartitionKeyExtractorStrategy.class, extractor); this.applicationContext.getBeanFactory().registerSingleton(partitionSelectorClassName, extractor); this.applicationContext.getBeanFactory().initializeBean(extractor, partitionSelectorClassName); return ((PartitionSelectorStrategy) extractor).selectPartition(key, partitionCount); } catch (Exception e) { logger.error("Failed to instantiate partition selector", e); throw new MessageBusException("Failed to instantiate partition selector: " + partitionSelectorClassName, e); } }
private Object invokeExtractor(String partitionKeyExtractorClassName, Message<?> message) { if (this.applicationContext.containsBean(partitionKeyExtractorClassName)) { return this.applicationContext.getBean(partitionKeyExtractorClassName, PartitionKeyExtractorStrategy.class) .extractKey(message); } Class<?> clazz; try { clazz = ClassUtils.forName(partitionKeyExtractorClassName, this.applicationContext.getClassLoader()); } catch (Exception e) { logger.error("Failed to load key extractor", e); throw new MessageBusException("Failed to load key extractor: " + partitionKeyExtractorClassName, e); } try { Object extractor = clazz.newInstance(); Assert.isInstanceOf(PartitionKeyExtractorStrategy.class, extractor); this.applicationContext.getBeanFactory().registerSingleton(partitionKeyExtractorClassName, extractor); this.applicationContext.getBeanFactory().initializeBean(extractor, partitionKeyExtractorClassName); return ((PartitionKeyExtractorStrategy) extractor).extractKey(message); } catch (Exception e) { logger.error("Failed to instantiate key extractor", e); throw new MessageBusException("Failed to instantiate key extractor: " + partitionKeyExtractorClassName, e); } }
private void destroyErrorInfrastructure(ProducerDestination destination) { String errorChannelName = errorsBaseName(destination); String errorBridgeHandlerName = getErrorBridgeName(destination); MessageHandler bridgeHandler = null; if (getApplicationContext().containsBean(errorBridgeHandlerName)) { bridgeHandler = getApplicationContext().getBean(errorBridgeHandlerName, MessageHandler.class); } if (getApplicationContext().containsBean(errorChannelName)) { SubscribableChannel channel = getApplicationContext().getBean(errorChannelName, SubscribableChannel.class); if (bridgeHandler != null) { channel.unsubscribe(bridgeHandler); ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory()) .destroySingleton(errorBridgeHandlerName); } ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory()) .destroySingleton(errorChannelName); } }
private void destroyErrorInfrastructure(ConsumerDestination destination, String group, C properties) { try { String recoverer = getErrorRecovererName(destination, group, properties); if (getApplicationContext().containsBean(recoverer)) { ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory()).destroySingleton(recoverer); String errorBridgeHandlerName = getErrorBridgeName(destination, group, properties); MessageHandler bridgeHandler = null; if (getApplicationContext().containsBean(errorBridgeHandlerName)) { bridgeHandler = getApplicationContext().getBean(errorBridgeHandlerName, MessageHandler.class); if (getApplicationContext().containsBean(errorMessageHandlerName)) { handler = getApplicationContext().getBean(errorMessageHandlerName, MessageHandler.class); if (getApplicationContext().containsBean(errorChannelName)) { SubscribableChannel channel = getApplicationContext().getBean(errorChannelName, SubscribableChannel.class); if (bridgeHandler != null) {
String errorChannelName = errorsBaseName(destination); SubscribableChannel errorChannel = null; if (getApplicationContext().containsBean(errorChannelName)) { Object errorChannelObject = getApplicationContext().getBean(errorChannelName); if (!(errorChannelObject instanceof SubscribableChannel)) { if (getApplicationContext().containsBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)) { defaultErrorChannel = getApplicationContext().getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, MessageChannel.class);
: IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME; if (!ackChannelBeanName.equals(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME) && !getApplicationContext().containsBean(ackChannelBeanName)) { GenericApplicationContext context = (GenericApplicationContext) getApplicationContext(); context.registerBean(ackChannelBeanName, DirectChannel.class, () -> new DirectChannel());
: IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME; if (!ackChannelBeanName.equals(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME) && !getApplicationContext().containsBean(ackChannelBeanName)) { GenericApplicationContext context = (GenericApplicationContext) getApplicationContext(); context.registerBean(ackChannelBeanName, DirectChannel.class, () -> new DirectChannel());
String errorChannelName = errorsBaseName(destination, group, consumerProperties); SubscribableChannel errorChannel = null; if (getApplicationContext().containsBean(errorChannelName)) { Object errorChannelObject = getApplicationContext().getBean(errorChannelName); if (!(errorChannelObject instanceof SubscribableChannel)) { if (getApplicationContext().containsBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)) { defaultErrorChannel = getApplicationContext().getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, MessageChannel.class);