INT-4037: Graph: Add Link Type To LinkNode

JIRA: https://jira.spring.io/browse/INT-4037

Provide type information in `LinkNode`s, input, output, error, discard.

This might be rendered as:

```
              +---(discard)
              |
         +----o----+
         |         |
         |         |
         |         |
(input)--o         o---(output)
         |         |
         |         |
         |         |
         +----o----+
              |
              +---(error)
```

  "links" : [ {
    "from" : 10,
    "to" : 9,
    "type" : "output"
  }, {
    "from" : 10,
    "to" : 1,
    "type" : "error"
  } ]

Document `link.type` in the `graph.adoc`
This commit is contained in:
Gary Russell
2016-05-24 13:26:02 -04:00
committed by Artem Bilan
parent f5488efcaa
commit e4d2484db6
3 changed files with 43 additions and 6 deletions

View File

@@ -205,7 +205,7 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat
nodes.add(handlerNode);
MessageChannelNode channelNode = channelNodes.get(handlerNode.getInput());
if (channelNode != null) {
links.add(new LinkNode(channelNode.getNodeId(), handlerNode.getNodeId()));
links.add(new LinkNode(channelNode.getNodeId(), handlerNode.getNodeId(), LinkNode.Type.input));
}
producerLink(links, channelNodes, handlerNode);
}
@@ -217,19 +217,19 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat
if (endpointNode.getOutput() != null) {
channelNode = channelNodes.get(endpointNode.getOutput());
if (channelNode != null) {
links.add(new LinkNode(endpointNode.getNodeId(), channelNode.getNodeId()));
links.add(new LinkNode(endpointNode.getNodeId(), channelNode.getNodeId(), LinkNode.Type.output));
}
}
if (endpointNode instanceof ErrorCapableNode) {
channelNode = channelNodes.get(((ErrorCapableNode) endpointNode).getErrors());
if (channelNode != null) {
links.add(new LinkNode(endpointNode.getNodeId(), channelNode.getNodeId()));
links.add(new LinkNode(endpointNode.getNodeId(), channelNode.getNodeId(), LinkNode.Type.error));
}
}
if (endpointNode instanceof DiscardingMessageHandlerNode) {
channelNode = channelNodes.get(((DiscardingMessageHandlerNode) endpointNode).getDiscards());
if (channelNode != null) {
links.add(new LinkNode(endpointNode.getNodeId(), channelNode.getNodeId()));
links.add(new LinkNode(endpointNode.getNodeId(), channelNode.getNodeId(), LinkNode.Type.discard));
}
}
}

View File

@@ -29,9 +29,12 @@ public class LinkNode {
private final int to;
public LinkNode(int from, int to) {
private final Type type;
public LinkNode(int from, int to, Type type) {
this.from = from;
this.to = to;
this.type = type;
}
public int getFrom() {
@@ -42,4 +45,12 @@ public class LinkNode {
return this.to;
}
public Type getType() {
return this.type;
}
public enum Type {
input, output, error, discard
}
}

View File

@@ -61,7 +61,8 @@ A simple Spring Integration application with only the default components would e
"links": [
{
"from": 2,
"to": 3
"to": 3,
"type": "input"
}
]
}
@@ -76,7 +77,32 @@ Other properties are provided by the framework and allows you to distinguish a s
The `links` graph element represents connections between nodes from the `nodes` graph element and, therefore, between integration components in the source Spring Integration application.
For example _from_ a `MessageChannel` _to_ an `EventDrivenConsumer` with some `MessageHandler`;
or _from_ an `AbstractReplyProducingMessageHandler` _to_ a `MessageChannel`.
For the convenience and to allow to determine a link purpose, the model is supplied with the `type` attribute.
The possible types are:
- _input_ - identify the direction from `MessageChannel` to the endpoint; `inputChannel` or `requestChannel` property;
- _output_ - the direction from `MessageHandler`, `MessageProducer` or `SourcePollingChannelAdapter` to the `MessageChannel` via an `outputChannel` or `replyChannel` property;
- _error_ - from `MessageHandler` on `PollingConsumer` or `MessageProducer` or `SourcePollingChannelAdapter` to the `MessageChannel` via an `errorChannel` property;
- _discard_ - from `DiscardingMessageHandler` (e.g. `MessageFilter`) to the `MessageChannel` via `errorChannel` property.
The information from this element can be used by a visualizing tool to render connections between nodes from the `nodes` graph element, where the `from` and `to` numbers represent the value from the `nodeId` property of the linked nodes.
For example the link `type` can be used to determine the proper _port_ on the target node:
----
+---(discard)
|
+----o----+
| |
| |
| |
(input)--o o---(output)
| |
| |
| |
+----o----+
|
+---(error)
----
The `nodes` graph element is perhaps the most interesting because its elements contain not only the runtime components with their `componentType` s and `name` s, but can also optionally contain metrics exposed by the component.
To enable the metrics, add an `@EnableIntegrationManagement` to some `@Configuration` class or add an `<int:management/>` element to your XML configuration.