private void registerSources() { for (SimpleMessageSourceMetrics source : sources) { MessageSourceMetrics monitor = enhanceSourceMonitor(source); String name = monitor.getName(); this.allSourcesByName.put(name, monitor); if (!PatternMatchUtils.simpleMatch(this.componentNamePatterns, name)) { continue; } // Only register once... if (!sourcesByName.containsKey(name)) { String beanKey = getSourceBeanKey(monitor); if (name != null) { sourcesByName.put(name, monitor); } registerBeanNameOrInstance(monitor, beanKey); // Expose the raw bean if it is managed MessageSource<?> bean = source.getMessageSource(); if (assembler.includeBean(bean.getClass(), source.getName())) { registerBeanInstance(bean, this.getMonitoredIntegrationObjectBeanKey(bean, name)); } } } }
private MessageSourceMetrics enhanceSourceMonitor(SimpleMessageSourceMetrics monitor) { MessageSourceMetrics result = monitor; if (monitor.getName() != null && monitor.getSource() != null) { return monitor; } // Assignment algorithm and bean id, with bean id pulled reflectively out of enclosing endpoint // if possible String[] names = beanFactory.getBeanNamesForType(AbstractEndpoint.class); String name = null; String endpointName = null; String source = "endpoint"; Object endpoint = null; for (String beanName : names) { endpoint = beanFactory.getBean(beanName); Object field = null; try { field = extractTarget(getField(endpoint, "source")); } catch (Exception e) { logger.trace("Could not get source from bean = " + beanName); } if (field == monitor.getMessageSource()) { name = beanName; endpointName = beanName; break; } } if (name != null && endpoint != null && name.startsWith("_org.springframework.integration")) { name = getInternalComponentName(name); source = "internal"; } if (name != null && endpoint != null && name.startsWith("org.springframework.integration")) { Object target = endpoint; if (endpoint instanceof Advised) { TargetSource targetSource = ((Advised) endpoint).getTargetSource(); if (targetSource != null) { try { target = targetSource.getTarget(); } catch (Exception e) { logger.debug("Could not get handler from bean = " + name); } } } Object field = getField(target, "outputChannel"); if (field != null) { if (!anonymousSourceCounters.containsKey(field)) { anonymousSourceCounters.put(field, new AtomicLong()); } AtomicLong count = anonymousSourceCounters.get(field); long total = count.incrementAndGet(); String suffix = ""; /* * Short hack to makes sure object names are unique if more than one endpoint has the same input channel */ if (total > 1) { suffix = "#" + total; } name = field + suffix; source = "anonymous"; } } if (endpoint instanceof Lifecycle) { // Wrap the monitor in a lifecycle so it exposes the start/stop operations result = new LifecycleMessageSourceMetrics((Lifecycle) endpoint, monitor); } if (name == null) { name = monitor.getMessageSource().toString(); source = "handler"; } if (endpointName != null) { beansByEndpointName.put(name, endpointName); } monitor.setSource(source); monitor.setName(name); return result; }