Skip to content

Commit e367374

Browse files
committed
Cleanup in the Core graph package
* Mostly code style and IDEA suggestions * Mitigate stress of NPE in the `TcpReceivingChannelAdapterTests`
1 parent aaae385 commit e367374

18 files changed

+145
-197
lines changed

spring-integration-core/src/main/java/org/springframework/integration/graph/CompositeMessageHandlerNode.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* Represents a composite message handler.
2828
*
2929
* @author Gary Russell
30+
* @author Artem Bilan
3031
*
3132
* @since 4.3
3233
*
@@ -35,8 +36,8 @@ public class CompositeMessageHandlerNode extends MessageHandlerNode {
3536

3637
private final List<InnerHandler> handlers = new ArrayList<>();
3738

38-
public CompositeMessageHandlerNode(int nodeId, String name, MessageHandler handler, String input, @Nullable String output,
39-
List<InnerHandler> handlers) {
39+
public CompositeMessageHandlerNode(int nodeId, String name, MessageHandler handler, String input,
40+
@Nullable String output, List<InnerHandler> handlers) {
4041

4142
super(nodeId, name, handler, input, output);
4243
this.handlers.addAll(handlers);
@@ -46,24 +47,7 @@ public List<InnerHandler> getHandlers() {
4647
return this.handlers;
4748
}
4849

49-
public static class InnerHandler {
50-
51-
private final String name;
52-
53-
private final String type;
54-
55-
public InnerHandler(String name, String type) {
56-
this.name = name;
57-
this.type = type;
58-
}
59-
60-
public String getName() {
61-
return this.name;
62-
}
63-
64-
public String getType() {
65-
return this.type;
66-
}
50+
public record InnerHandler(String name, String type) {
6751

6852
}
6953

spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableEndpointNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class ErrorCapableEndpointNode extends EndpointNode implements ErrorCapab
3030

3131
private final @Nullable String errors;
3232

33-
protected ErrorCapableEndpointNode(int nodeId, String name, Object nodeObject, @Nullable String output, @Nullable String errors) {
33+
protected ErrorCapableEndpointNode(int nodeId, String name, Object nodeObject, @Nullable String output,
34+
@Nullable String errors) {
35+
3436
super(nodeId, name, nodeObject, output);
3537
this.errors = errors;
3638
}

spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableMessageHandlerNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Represents a message handler that can produce errors (pollable).
2525
*
2626
* @author Gary Russell
27+
*
2728
* @since 4.3
2829
*
2930
*/

spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableRoutingNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class ErrorCapableRoutingNode extends RoutingMessageHandlerNode implement
3535

3636
private final @Nullable String errors;
3737

38-
public ErrorCapableRoutingNode(int nodeId, String name, MessageHandler handler, String input, @Nullable String output,
39-
@Nullable String errors, Collection<String> routes) {
38+
public ErrorCapableRoutingNode(int nodeId, String name, MessageHandler handler, String input,
39+
@Nullable String output, @Nullable String errors, Collection<String> routes) {
4040

4141
super(nodeId, name, handler, input, output, routes);
4242
this.errors = errors;

spring-integration-core/src/main/java/org/springframework/integration/graph/Graph.java

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,22 @@
2020
import java.util.Map;
2121

2222
/**
23-
* This object can be exposed, for example, as a JSON object over
24-
* HTTP.
23+
* This object can be exposed, for example, as a JSON object over HTTP.
24+
*
25+
* @param contentDescriptor the Spring Integration application attributes.
26+
* @param nodes the Spring Integration application endpoints.
27+
* @param links the Spring Integration application message channels between endpoints.
2528
*
2629
* @author Andy Clement
2730
* @author Gary Russell
31+
* @author Artem Bilan
2832
*
2933
* @since 4.3
3034
*
3135
*/
32-
public class Graph {
33-
34-
private final Map<String, Object> contentDescriptor;
35-
36-
private final Collection<IntegrationNode> nodes;
37-
38-
private final Collection<LinkNode> links;
39-
40-
public Graph(Map<String, Object> descriptor, Collection<IntegrationNode> nodes, Collection<LinkNode> links) {
41-
this.contentDescriptor = descriptor;
42-
this.nodes = nodes;
43-
this.links = links;
44-
}
45-
46-
public Map<String, Object> getContentDescriptor() {
47-
return this.contentDescriptor;
48-
}
49-
50-
public Collection<IntegrationNode> getNodes() {
51-
return this.nodes;
52-
}
53-
54-
public Collection<LinkNode> getLinks() {
55-
return this.links;
56-
}
36+
public record Graph(
37+
Map<String, Object> contentDescriptor,
38+
Collection<IntegrationNode> nodes,
39+
Collection<LinkNode> links) {
5740

5841
}

spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
* @author Gary Russell
6868
* @author Artem Bilan
6969
* @author Christian Tzolov
70+
* @author Glenn Renfro
7071
*
7172
* @since 4.3
7273
*

spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationNode.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public abstract class IntegrationNode {
4949

5050
private final String componentType;
5151

52-
@Nullable
53-
private final IntegrationPatternType integrationPatternType;
52+
private final @Nullable IntegrationPatternType integrationPatternType;
5453

5554
private final IntegrationPatternType.@Nullable IntegrationPatternCategory integrationPatternCategory;
5655

@@ -115,8 +114,7 @@ public final String getComponentType() {
115114
return this.componentType;
116115
}
117116

118-
@Nullable
119-
public IntegrationPatternType getIntegrationPatternType() {
117+
public @Nullable IntegrationPatternType getIntegrationPatternType() {
120118
return this.integrationPatternType;
121119
}
122120

spring-integration-core/src/main/java/org/springframework/integration/graph/LinkNode.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,17 @@
1919
/**
2020
* Represents a link between nodes.
2121
*
22+
* @param from the source node index
23+
* @param to the target node index
24+
* @param type the {@link Type} of this link
25+
*
2226
* @author Gary Russell
27+
* @author Artem Bilan
28+
*
2329
* @since 4.3
2430
*
2531
*/
26-
public class LinkNode {
27-
28-
private final int from;
29-
30-
private final int to;
31-
32-
private final Type type;
33-
34-
public LinkNode(int from, int to, Type type) {
35-
this.from = from;
36-
this.to = to;
37-
this.type = type;
38-
}
39-
40-
public int getFrom() {
41-
return this.from;
42-
}
43-
44-
public int getTo() {
45-
return this.to;
46-
}
47-
48-
public Type getType() {
49-
return this.type;
50-
}
32+
public record LinkNode(int from, int to, Type type) {
5133

5234
public enum Type {
5335
input, output, error, discard, route

spring-integration-core/src/main/java/org/springframework/integration/graph/MessageGatewayNode.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.graph;
1818

19+
import java.util.function.Supplier;
20+
1921
import org.jspecify.annotations.Nullable;
2022

2123
import org.springframework.integration.gateway.MessagingGatewaySupport;
@@ -24,14 +26,28 @@
2426
* Represents an inbound gateway.
2527
*
2628
* @author Gary Russell
29+
* @author Artem Bilan
2730
*
2831
* @since 4.3
2932
*
3033
*/
31-
public class MessageGatewayNode extends ErrorCapableEndpointNode {
34+
public class MessageGatewayNode extends ErrorCapableEndpointNode implements SendTimersAware {
35+
36+
private @Nullable Supplier<SendTimers> sendTimers;
37+
38+
public MessageGatewayNode(int nodeId, String name, MessagingGatewaySupport gateway, @Nullable String output,
39+
@Nullable String errors) {
3240

33-
public MessageGatewayNode(int nodeId, String name, MessagingGatewaySupport gateway, @Nullable String output, @Nullable String errors) {
3441
super(nodeId, name, gateway, output, errors);
3542
}
3643

44+
@Override
45+
public void sendTimers(Supplier<SendTimers> timers) {
46+
this.sendTimers = timers;
47+
}
48+
49+
public @Nullable SendTimers getSendTimers() {
50+
return this.sendTimers != null ? this.sendTimers.get() : null;
51+
}
52+
3753
}

spring-integration-core/src/main/java/org/springframework/integration/graph/MessageProducerNode.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.graph;
1818

19+
import java.util.function.Supplier;
20+
1921
import org.jspecify.annotations.Nullable;
2022

2123
import org.springframework.integration.endpoint.MessageProducerSupport;
@@ -24,14 +26,28 @@
2426
* Represents an inbound message producer.
2527
*
2628
* @author Gary Russell
29+
* @author Artem Bilan
2730
*
2831
* @since 4.3
2932
*
3033
*/
31-
public class MessageProducerNode extends ErrorCapableEndpointNode {
34+
public class MessageProducerNode extends ErrorCapableEndpointNode implements SendTimersAware {
35+
36+
private @Nullable Supplier<SendTimers> sendTimers;
37+
38+
public MessageProducerNode(int nodeId, String name, MessageProducerSupport producer, String output,
39+
@Nullable String errors) {
3240

33-
public MessageProducerNode(int nodeId, String name, MessageProducerSupport producer, String output, @Nullable String errors) {
3441
super(nodeId, name, producer, output, errors);
3542
}
3643

44+
@Override
45+
public void sendTimers(Supplier<SendTimers> timers) {
46+
this.sendTimers = timers;
47+
}
48+
49+
public @Nullable SendTimers getSendTimers() {
50+
return this.sendTimers != null ? this.sendTimers.get() : null;
51+
}
52+
3753
}

0 commit comments

Comments
 (0)