Skip to content

Commit e8a9f95

Browse files
authored
GH-4013: TCP DSL Improvements
Resolves #4013 Add Net/NIO specific Server/Client connection factory specs. * Shorten DSL method names, as suggested.
1 parent e6d0a4f commit e8a9f95

13 files changed

+406
-28
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/AbstractConnectionFactorySpec.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,20 @@ public S readDelay(long readDelay) {
215215
/**
216216
* @param tcpSocketSupport the {@link TcpSocketSupport}.
217217
* @return the spec.
218+
* @deprecated in favor of {@link #socketSupport(TcpSocketSupport)}.
218219
* @see AbstractConnectionFactory#setTcpSocketSupport(TcpSocketSupport)
219220
*/
221+
@Deprecated
220222
public S tcpSocketSupport(TcpSocketSupport tcpSocketSupport) {
223+
return socketSupport(tcpSocketSupport);
224+
}
225+
226+
/**
227+
* @param tcpSocketSupport the {@link TcpSocketSupport}.
228+
* @return the spec.
229+
* @see AbstractConnectionFactory#setTcpSocketSupport(TcpSocketSupport)
230+
*/
231+
public S socketSupport(TcpSocketSupport tcpSocketSupport) {
221232
this.target.setTcpSocketSupport(tcpSocketSupport);
222233
return _this();
223234
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/Tcp.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,17 +39,17 @@ private Tcp() {
3939
* @param port the port to listen on.
4040
* @return the spec.
4141
*/
42-
public static TcpServerConnectionFactorySpec nioServer(int port) {
43-
return new TcpServerConnectionFactorySpec(port, true);
42+
public static TcpNioServerConnectionFactorySpec nioServer(int port) {
43+
return new TcpNioServerConnectionFactorySpec(port);
4444
}
4545

4646
/**
4747
* Create a server spec that does not use NIO.
4848
* @param port the port to listen on.
4949
* @return the spec.
5050
*/
51-
public static TcpServerConnectionFactorySpec netServer(int port) {
52-
return new TcpServerConnectionFactorySpec(port, false);
51+
public static TcpNetServerConnectionFactorySpec netServer(int port) {
52+
return new TcpNetServerConnectionFactorySpec(port);
5353
}
5454

5555
/**
@@ -58,8 +58,8 @@ public static TcpServerConnectionFactorySpec netServer(int port) {
5858
* @param port the port to connect to.
5959
* @return the spec.
6060
*/
61-
public static TcpClientConnectionFactorySpec nioClient(String host, int port) {
62-
return new TcpClientConnectionFactorySpec(host, port, true);
61+
public static TcpNioClientConnectionFactorySpec nioClient(String host, int port) {
62+
return new TcpNioClientConnectionFactorySpec(host, port);
6363
}
6464

6565
/**
@@ -68,8 +68,8 @@ public static TcpClientConnectionFactorySpec nioClient(String host, int port) {
6868
* @param port the port to connect to.
6969
* @return the spec.
7070
*/
71-
public static TcpClientConnectionFactorySpec netClient(String host, int port) {
72-
return new TcpClientConnectionFactorySpec(host, port, false);
71+
public static TcpNetClientConnectionFactorySpec netClient(String host, int port) {
72+
return new TcpNetClientConnectionFactorySpec(host, port);
7373
}
7474

7575
/**
@@ -127,7 +127,7 @@ public static TcpOutboundGatewaySpec outboundGateway(AbstractClientConnectionFac
127127
* @param connectionFactory the connection factory spec.
128128
* @return the spec.
129129
*/
130-
public static TcpOutboundGatewaySpec outboundGateway(TcpClientConnectionFactorySpec connectionFactory) {
130+
public static TcpOutboundGatewaySpec outboundGateway(TcpClientConnectionFactorySpec<?, ?> connectionFactory) {
131131
return new TcpOutboundGatewaySpec(connectionFactory);
132132
}
133133

spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpClientConnectionFactorySpec.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,27 +17,57 @@
1717
package org.springframework.integration.ip.dsl;
1818

1919
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
20+
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
2021
import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
2122
import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
2223

2324
/**
2425
* An {@link AbstractConnectionFactorySpec} for {@link AbstractClientConnectionFactory}s.
2526
*
27+
* @param <S> the target {@link TcpServerConnectionFactorySpec} implementation type.
28+
* @param <C> the target {@link AbstractServerConnectionFactory} implementation type.
29+
*
2630
* @author Gary Russell
2731
* @author Artem Bilan
2832
*
2933
* @since 5.0
3034
*
3135
*/
32-
public class TcpClientConnectionFactorySpec
33-
extends AbstractConnectionFactorySpec<TcpClientConnectionFactorySpec, AbstractClientConnectionFactory> {
36+
public abstract class TcpClientConnectionFactorySpec
37+
<S extends TcpClientConnectionFactorySpec<S, C>, C extends AbstractClientConnectionFactory>
38+
extends AbstractConnectionFactorySpec<S, C> {
39+
40+
/**
41+
* Create an instance.
42+
* @param cf the connection factory.
43+
* @since 6.0.3
44+
*/
45+
protected TcpClientConnectionFactorySpec(C cf) {
46+
super(cf);
47+
}
3448

49+
/**
50+
* Create an instance.
51+
* @param host the host.
52+
* @param port the port.
53+
* @deprecated since 6.0.3; use a subclass.
54+
*/
55+
@Deprecated
3556
protected TcpClientConnectionFactorySpec(String host, int port) {
3657
this(host, port, false);
3758
}
3859

60+
/**
61+
* Create an instance.
62+
* @param host the host.
63+
* @param port the port.
64+
* @param nio true for NIO.
65+
* @deprecated since 6.0.3; use a subclass.
66+
*/
67+
@SuppressWarnings("unchecked")
68+
@Deprecated
3969
protected TcpClientConnectionFactorySpec(String host, int port, boolean nio) {
40-
super(nio ? new TcpNioClientConnectionFactory(host, port) : new TcpNetClientConnectionFactory(host, port));
70+
super(nio ? (C) new TcpNioClientConnectionFactory(host, port) : (C) new TcpNetClientConnectionFactory(host, port));
4171
}
4272

4373
/**
@@ -46,7 +76,7 @@ protected TcpClientConnectionFactorySpec(String host, int port, boolean nio) {
4676
* @return the spec.
4777
* @since 5.2
4878
*/
49-
public TcpClientConnectionFactorySpec connectTimeout(int connectTimeout) {
79+
public S connectTimeout(int connectTimeout) {
5080
this.target.setConnectTimeout(connectTimeout);
5181
return _this();
5282
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.ip.dsl;
18+
19+
import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
20+
import org.springframework.integration.ip.tcp.connection.TcpNetConnectionSupport;
21+
import org.springframework.integration.ip.tcp.connection.TcpSocketFactorySupport;
22+
23+
/**
24+
* {@link TcpClientConnectionFactorySpec} for {@link TcpNetClientConnectionFactory}s.
25+
*
26+
* @author Gary Russell
27+
* @since 6.0.3
28+
*/
29+
public class TcpNetClientConnectionFactorySpec
30+
extends TcpClientConnectionFactorySpec<TcpNetClientConnectionFactorySpec, TcpNetClientConnectionFactory> {
31+
32+
protected TcpNetClientConnectionFactorySpec(String host, int port) {
33+
super(new TcpNetClientConnectionFactory(host, port));
34+
}
35+
36+
/**
37+
* The {@link TcpNetConnectionSupport} to use to create connection objects.
38+
* @param connectionSupport the {@link TcpNetConnectionSupport}.
39+
* @return the spec.
40+
* @see TcpNetClientConnectionFactory#setTcpNetConnectionSupport(TcpNetConnectionSupport)
41+
*/
42+
public TcpNetClientConnectionFactorySpec connectionSupport(TcpNetConnectionSupport connectionSupport) {
43+
this.target.setTcpNetConnectionSupport(connectionSupport);
44+
return this;
45+
}
46+
47+
/**
48+
* Set the {@link TcpSocketFactorySupport} used to create server sockets.
49+
* @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport}
50+
* @return the spec.
51+
* @see TcpNetClientConnectionFactory#setTcpSocketFactorySupport(TcpSocketFactorySupport)
52+
*/
53+
public TcpNetClientConnectionFactorySpec socketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) {
54+
this.target.setTcpSocketFactorySupport(tcpSocketFactorySupport);
55+
return this;
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.ip.dsl;
18+
19+
import org.springframework.integration.ip.tcp.connection.TcpNetConnectionSupport;
20+
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
21+
import org.springframework.integration.ip.tcp.connection.TcpSocketFactorySupport;
22+
23+
/**
24+
* {@link TcpServerConnectionFactorySpec} for {@link TcpNetServerConnectionFactory}s.
25+
*
26+
* @author Gary Russell
27+
* @since 6.0.3
28+
*/
29+
public class TcpNetServerConnectionFactorySpec
30+
extends TcpServerConnectionFactorySpec<TcpNetServerConnectionFactorySpec, TcpNetServerConnectionFactory> {
31+
32+
protected TcpNetServerConnectionFactorySpec(int port) {
33+
super(new TcpNetServerConnectionFactory(port));
34+
}
35+
36+
/**
37+
* The {@link TcpNetConnectionSupport} to use to create connection objects.
38+
* @param connectionSupport the {@link TcpNetConnectionSupport}.
39+
* @return the spec.
40+
* @see TcpNetServerConnectionFactory#setTcpNetConnectionSupport(TcpNetConnectionSupport)
41+
*/
42+
public TcpNetServerConnectionFactorySpec connectionSupport(TcpNetConnectionSupport connectionSupport) {
43+
this.target.setTcpNetConnectionSupport(connectionSupport);
44+
return this;
45+
}
46+
47+
/**
48+
* Set the {@link TcpSocketFactorySupport} used to create server sockets.
49+
* @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport}
50+
* @return the spec.
51+
* @see TcpNetServerConnectionFactory#setTcpSocketFactorySupport(TcpSocketFactorySupport)
52+
*/
53+
public TcpNetServerConnectionFactorySpec socketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) {
54+
this.target.setTcpSocketFactorySupport(tcpSocketFactorySupport);
55+
return this;
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.ip.dsl;
18+
19+
import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
20+
import org.springframework.integration.ip.tcp.connection.TcpNioConnectionSupport;
21+
22+
/**
23+
* {@link TcpClientConnectionFactorySpec} for {@link TcpNioClientConnectionFactory}s.
24+
*
25+
* @author Gary Russell
26+
* @since 6.0.3
27+
*/
28+
public class TcpNioClientConnectionFactorySpec
29+
extends TcpClientConnectionFactorySpec<TcpNioClientConnectionFactorySpec, TcpNioClientConnectionFactory> {
30+
31+
protected TcpNioClientConnectionFactorySpec(String host, int port) {
32+
super(new TcpNioClientConnectionFactory(host, port));
33+
}
34+
35+
/**
36+
* True to use direct buffers.
37+
* @param usingDirectBuffers true for direct.
38+
* @return the spec.
39+
* @see TcpNioClientConnectionFactory#setUsingDirectBuffers(boolean)
40+
*/
41+
public TcpNioClientConnectionFactorySpec directBuffers(boolean usingDirectBuffers) {
42+
this.target.setUsingDirectBuffers(usingDirectBuffers);
43+
return this;
44+
}
45+
46+
/**
47+
* The {@link TcpNioConnectionSupport} to use.
48+
* @param tcpNioSupport the {@link TcpNioConnectionSupport}.
49+
* @return the spec.
50+
* @see TcpNioClientConnectionFactory#setTcpNioConnectionSupport(TcpNioConnectionSupport)
51+
*/
52+
public TcpNioClientConnectionFactorySpec connectionSupport(TcpNioConnectionSupport tcpNioSupport) {
53+
this.target.setTcpNioConnectionSupport(tcpNioSupport);
54+
return this;
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.ip.dsl;
18+
19+
import org.springframework.integration.ip.tcp.connection.TcpNioConnectionSupport;
20+
import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory;
21+
22+
/**
23+
* {@link TcpServerConnectionFactorySpec} for {@link TcpNioServerConnectionFactory}s.
24+
*
25+
* @author Gary Russell
26+
* @since 6.0.3
27+
*/
28+
public class TcpNioServerConnectionFactorySpec
29+
extends TcpServerConnectionFactorySpec<TcpNioServerConnectionFactorySpec, TcpNioServerConnectionFactory> {
30+
31+
protected TcpNioServerConnectionFactorySpec(int port) {
32+
super(new TcpNioServerConnectionFactory(port));
33+
}
34+
35+
/**
36+
* True to use direct buffers.
37+
* @param usingDirectBuffers true for direct.
38+
* @return the spec.
39+
* @see TcpNioServerConnectionFactory#setUsingDirectBuffers(boolean)
40+
*/
41+
public TcpNioServerConnectionFactorySpec directBuffers(boolean usingDirectBuffers) {
42+
this.target.setUsingDirectBuffers(usingDirectBuffers);
43+
return this;
44+
}
45+
46+
/**
47+
* The {@link TcpNioConnectionSupport} to use.
48+
* @param tcpNioSupport the {@link TcpNioConnectionSupport}.
49+
* @return the spec.
50+
* @see TcpNioServerConnectionFactory#setTcpNioConnectionSupport(TcpNioConnectionSupport)
51+
*/
52+
public TcpNioServerConnectionFactorySpec connectionSupport(TcpNioConnectionSupport tcpNioSupport) {
53+
this.target.setTcpNioConnectionSupport(tcpNioSupport);
54+
return this;
55+
}
56+
57+
}

0 commit comments

Comments
 (0)