registerBeanLock = this.registerFlowsLock; registerBeanLock.lock(); flowId = generateBeanName(integrationFlow, null); builder.id(flowId); integrationFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null); builder.additionalBeans.forEach((key, value) -> registerBean(key, value, theFlowId));
/** * Destroy an {@link IntegrationFlow} bean (as well as all its dependant beans) * for provided {@code flowId} and clean up all the local cache for it. * @param flowId the bean name to destroy from */ @Override public void remove(String flowId) { if (this.registry.containsKey(flowId)) { IntegrationFlowRegistration flowRegistration = this.registry.remove(flowId); flowRegistration.stop(); removeDependantBeans(flowId); this.beanDefinitionRegistry.removeBeanDefinition(flowId); } else { throw new IllegalStateException("An IntegrationFlow with the id " + "[" + flowId + "] doesn't exist in the registry."); } }
@SuppressWarnings("unchecked") private Object registerBean(Object bean, @Nullable String beanNameArg, String parentName) { String beanName = beanNameArg; if (beanName == null) { beanName = generateBeanName(bean, parentName); } BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition((Class<Object>) bean.getClass(), () -> bean) .getRawBeanDefinition(); this.beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition); if (parentName != null) { this.beanFactory.registerDependentBean(parentName, beanName); } return this.beanFactory.getBean(beanName); }
@SuppressWarnings("unchecked") private Object registerBean(Object bean, @Nullable String beanNameArg, String parentName) { String beanName = beanNameArg; if (beanName == null) { beanName = generateBeanName(bean, parentName); } BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition((Class<Object>) bean.getClass(), () -> bean) .getRawBeanDefinition(); this.beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition); if (parentName != null) { this.beanFactory.registerDependentBean(parentName, beanName); } return this.beanFactory.getBean(beanName); }
registerBeanLock = this.registerFlowsLock; registerBeanLock.lock(); flowId = generateBeanName(integrationFlow, null); builder.id(flowId); integrationFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null); builder.additionalBeans.forEach((key, value) -> registerBean(key, value, theFlowId));
private void removeDependantBeans(String parentName) { String[] dependentBeans = this.beanFactory.getDependentBeans(parentName); for (String beanName : dependentBeans) { removeDependantBeans(beanName); this.beanDefinitionRegistry.removeBeanDefinition(beanName); // TODO until https://jira.spring.io/browse/SPR-16837 String[] aliases = this.beanDefinitionRegistry.getAliases(beanName); for (String alias : aliases) { this.beanDefinitionRegistry.removeAlias(alias); } } }
/** * Destroy an {@link IntegrationFlow} bean (as well as all its dependant beans) * for provided {@code flowId} and clean up all the local cache for it. * @param flowId the bean name to destroy from */ @Override public void remove(String flowId) { if (this.registry.containsKey(flowId)) { IntegrationFlowRegistration flowRegistration = this.registry.remove(flowId); flowRegistration.stop(); removeDependantBeans(flowId); this.beanDefinitionRegistry.removeBeanDefinition(flowId); } else { throw new IllegalStateException("An IntegrationFlow with the id " + "[" + flowId + "] doesn't exist in the registry."); } }
private void removeDependantBeans(String parentName) { String[] dependentBeans = this.beanFactory.getDependentBeans(parentName); for (String beanName : dependentBeans) { removeDependantBeans(beanName); this.beanDefinitionRegistry.removeBeanDefinition(beanName); // TODO until https://jira.spring.io/browse/SPR-16837 String[] aliases = this.beanDefinitionRegistry.getAliases(beanName); for (String alias : aliases) { this.beanDefinitionRegistry.removeAlias(alias); } } }