use of org.springframework.integration.gateway.MessagingGatewaySupport in project spring-integration by spring-projects.
the class IntegrationGraphServer method gateways.
private void gateways(Collection<IntegrationNode> nodes, Collection<LinkNode> links, Map<String, MessageChannelNode> channelNodes) {
Map<String, MessagingGatewaySupport> gateways = this.applicationContext.getBeansOfType(MessagingGatewaySupport.class);
for (Entry<String, MessagingGatewaySupport> entry : gateways.entrySet()) {
MessagingGatewaySupport gateway = entry.getValue();
MessageGatewayNode gatewayNode = this.nodeFactory.gatewayNode(entry.getKey(), gateway);
nodes.add(gatewayNode);
producerLink(links, channelNodes, gatewayNode);
}
Map<String, GatewayProxyFactoryBean> gpfbs = this.applicationContext.getBeansOfType(GatewayProxyFactoryBean.class);
for (Entry<String, GatewayProxyFactoryBean> entry : gpfbs.entrySet()) {
Map<Method, MessagingGatewaySupport> methodMap = entry.getValue().getGateways();
for (Entry<Method, MessagingGatewaySupport> gwEntry : methodMap.entrySet()) {
MessagingGatewaySupport gateway = gwEntry.getValue();
Method method = gwEntry.getKey();
Class<?>[] parameterTypes = method.getParameterTypes();
String[] parameterTypeNames = new String[parameterTypes.length];
int i = 0;
for (Class<?> type : parameterTypes) {
parameterTypeNames[i++] = type.getName();
}
String signature = method.getName() + "(" + StringUtils.arrayToCommaDelimitedString(parameterTypeNames) + ")";
MessageGatewayNode gatewayNode = this.nodeFactory.gatewayNode(entry.getKey().substring(1) + "." + signature, gateway);
nodes.add(gatewayNode);
producerLink(links, channelNodes, gatewayNode);
}
}
}
use of org.springframework.integration.gateway.MessagingGatewaySupport in project spring-integration by spring-projects.
the class IntegrationMBeanExporter method enhanceSourceMonitor.
private MessageSourceMetrics enhanceSourceMonitor(MessageSourceMetrics monitor) {
MessageSourceMetrics result = monitor;
if (monitor.getManagedName() != null) {
return monitor;
}
// Assignment algorithm and bean id, with bean id pulled reflectively out of enclosing endpoint if possible
String[] names = this.applicationContext.getBeanNamesForType(AbstractEndpoint.class);
String name = null;
String endpointName = null;
String source = "endpoint";
Object endpoint = null;
for (String beanName : names) {
endpoint = this.applicationContext.getBean(beanName);
Object field = null;
if (monitor instanceof MessagingGatewaySupport && endpoint == monitor) {
field = monitor;
} else {
try {
field = extractTarget(getField(endpoint, "source"));
} catch (Exception e) {
logger.trace("Could not get source from bean = " + beanName);
}
}
if (field == monitor) {
name = beanName;
endpointName = beanName;
break;
}
}
if (endpointName == null) {
endpoint = null;
}
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.error("Could not get handler from bean = " + name);
}
}
}
Object outputChannel = null;
if (target instanceof MessagingGatewaySupport) {
outputChannel = ((MessagingGatewaySupport) target).getRequestChannel();
} else {
outputChannel = getField(target, "outputChannel");
}
if (outputChannel != null) {
if (!this.anonymousSourceCounters.containsKey(outputChannel)) {
this.anonymousSourceCounters.put(outputChannel, new AtomicLong());
}
AtomicLong count = this.anonymousSourceCounters.get(outputChannel);
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 = outputChannel + suffix;
source = "anonymous";
}
}
if (endpoint instanceof Lifecycle) {
// Wrap the monitor in a lifecycle so it exposes the start/stop operations
if (endpoint instanceof TrackableComponent) {
if (monitor instanceof MessageSourceManagement) {
result = new LifecycleTrackableMessageSourceManagement((Lifecycle) endpoint, (MessageSourceManagement) monitor);
} else {
result = new LifecycleTrackableMessageSourceMetrics((Lifecycle) endpoint, monitor);
}
} else {
if (monitor instanceof MessageSourceManagement) {
result = new LifecycleMessageSourceManagement((Lifecycle) endpoint, (MessageSourceManagement) monitor);
} else {
result = new LifecycleMessageSourceMetrics((Lifecycle) endpoint, monitor);
}
}
}
if (name == null) {
name = monitor.toString();
source = "source";
}
if (endpointName != null) {
this.beansByEndpointName.put(name, endpointName);
}
monitor.setManagedType(source);
monitor.setManagedName(name);
return result;
}
Aggregations