diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/AbstractConnectionFactorySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/AbstractConnectionFactorySpec.java index b1146a32761..aa83d7993e6 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/AbstractConnectionFactorySpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/AbstractConnectionFactorySpec.java @@ -215,9 +215,20 @@ public S readDelay(long readDelay) { /** * @param tcpSocketSupport the {@link TcpSocketSupport}. * @return the spec. + * @deprecated in favor of {@link #socketSupport(TcpSocketSupport)}. * @see AbstractConnectionFactory#setTcpSocketSupport(TcpSocketSupport) */ + @Deprecated public S tcpSocketSupport(TcpSocketSupport tcpSocketSupport) { + return socketSupport(tcpSocketSupport); + } + + /** + * @param tcpSocketSupport the {@link TcpSocketSupport}. + * @return the spec. + * @see AbstractConnectionFactory#setTcpSocketSupport(TcpSocketSupport) + */ + public S socketSupport(TcpSocketSupport tcpSocketSupport) { this.target.setTcpSocketSupport(tcpSocketSupport); return _this(); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/Tcp.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/Tcp.java index 03f32c06d82..6c2459a188e 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/Tcp.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/Tcp.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,8 +39,8 @@ private Tcp() { * @param port the port to listen on. * @return the spec. */ - public static TcpServerConnectionFactorySpec nioServer(int port) { - return new TcpServerConnectionFactorySpec(port, true); + public static TcpNioServerConnectionFactorySpec nioServer(int port) { + return new TcpNioServerConnectionFactorySpec(port); } /** @@ -48,8 +48,8 @@ public static TcpServerConnectionFactorySpec nioServer(int port) { * @param port the port to listen on. * @return the spec. */ - public static TcpServerConnectionFactorySpec netServer(int port) { - return new TcpServerConnectionFactorySpec(port, false); + public static TcpNetServerConnectionFactorySpec netServer(int port) { + return new TcpNetServerConnectionFactorySpec(port); } /** @@ -58,8 +58,8 @@ public static TcpServerConnectionFactorySpec netServer(int port) { * @param port the port to connect to. * @return the spec. */ - public static TcpClientConnectionFactorySpec nioClient(String host, int port) { - return new TcpClientConnectionFactorySpec(host, port, true); + public static TcpNioClientConnectionFactorySpec nioClient(String host, int port) { + return new TcpNioClientConnectionFactorySpec(host, port); } /** @@ -68,8 +68,8 @@ public static TcpClientConnectionFactorySpec nioClient(String host, int port) { * @param port the port to connect to. * @return the spec. */ - public static TcpClientConnectionFactorySpec netClient(String host, int port) { - return new TcpClientConnectionFactorySpec(host, port, false); + public static TcpNetClientConnectionFactorySpec netClient(String host, int port) { + return new TcpNetClientConnectionFactorySpec(host, port); } /** @@ -127,7 +127,7 @@ public static TcpOutboundGatewaySpec outboundGateway(AbstractClientConnectionFac * @param connectionFactory the connection factory spec. * @return the spec. */ - public static TcpOutboundGatewaySpec outboundGateway(TcpClientConnectionFactorySpec connectionFactory) { + public static TcpOutboundGatewaySpec outboundGateway(TcpClientConnectionFactorySpec connectionFactory) { return new TcpOutboundGatewaySpec(connectionFactory); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpClientConnectionFactorySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpClientConnectionFactorySpec.java index 187190df785..e10cda7c94f 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpClientConnectionFactorySpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpClientConnectionFactorySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,27 +17,57 @@ package org.springframework.integration.ip.dsl; import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory; +import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory; import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory; /** * An {@link AbstractConnectionFactorySpec} for {@link AbstractClientConnectionFactory}s. * + * @param the target {@link TcpServerConnectionFactorySpec} implementation type. + * @param the target {@link AbstractServerConnectionFactory} implementation type. + * * @author Gary Russell * @author Artem Bilan * * @since 5.0 * */ -public class TcpClientConnectionFactorySpec - extends AbstractConnectionFactorySpec { +public abstract class TcpClientConnectionFactorySpec + , C extends AbstractClientConnectionFactory> + extends AbstractConnectionFactorySpec { + + /** + * Create an instance. + * @param cf the connection factory. + * @since 6.0.3 + */ + protected TcpClientConnectionFactorySpec(C cf) { + super(cf); + } + /** + * Create an instance. + * @param host the host. + * @param port the port. + * @deprecated since 6.0.3; use a subclass. + */ + @Deprecated protected TcpClientConnectionFactorySpec(String host, int port) { this(host, port, false); } + /** + * Create an instance. + * @param host the host. + * @param port the port. + * @param nio true for NIO. + * @deprecated since 6.0.3; use a subclass. + */ + @SuppressWarnings("unchecked") + @Deprecated protected TcpClientConnectionFactorySpec(String host, int port, boolean nio) { - super(nio ? new TcpNioClientConnectionFactory(host, port) : new TcpNetClientConnectionFactory(host, port)); + super(nio ? (C) new TcpNioClientConnectionFactory(host, port) : (C) new TcpNetClientConnectionFactory(host, port)); } /** @@ -46,7 +76,7 @@ protected TcpClientConnectionFactorySpec(String host, int port, boolean nio) { * @return the spec. * @since 5.2 */ - public TcpClientConnectionFactorySpec connectTimeout(int connectTimeout) { + public S connectTimeout(int connectTimeout) { this.target.setConnectTimeout(connectTimeout); return _this(); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNetClientConnectionFactorySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNetClientConnectionFactorySpec.java new file mode 100644 index 00000000000..175ab59ebca --- /dev/null +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNetClientConnectionFactorySpec.java @@ -0,0 +1,58 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.ip.dsl; + +import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory; +import org.springframework.integration.ip.tcp.connection.TcpNetConnectionSupport; +import org.springframework.integration.ip.tcp.connection.TcpSocketFactorySupport; + +/** + * {@link TcpClientConnectionFactorySpec} for {@link TcpNetClientConnectionFactory}s. + * + * @author Gary Russell + * @since 6.0.3 + */ +public class TcpNetClientConnectionFactorySpec + extends TcpClientConnectionFactorySpec { + + protected TcpNetClientConnectionFactorySpec(String host, int port) { + super(new TcpNetClientConnectionFactory(host, port)); + } + + /** + * The {@link TcpNetConnectionSupport} to use to create connection objects. + * @param connectionSupport the {@link TcpNetConnectionSupport}. + * @return the spec. + * @see TcpNetClientConnectionFactory#setTcpNetConnectionSupport(TcpNetConnectionSupport) + */ + public TcpNetClientConnectionFactorySpec connectionSupport(TcpNetConnectionSupport connectionSupport) { + this.target.setTcpNetConnectionSupport(connectionSupport); + return this; + } + + /** + * Set the {@link TcpSocketFactorySupport} used to create server sockets. + * @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport} + * @return the spec. + * @see TcpNetClientConnectionFactory#setTcpSocketFactorySupport(TcpSocketFactorySupport) + */ + public TcpNetClientConnectionFactorySpec socketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) { + this.target.setTcpSocketFactorySupport(tcpSocketFactorySupport); + return this; + } + +} diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNetServerConnectionFactorySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNetServerConnectionFactorySpec.java new file mode 100644 index 00000000000..7dcc98c56ae --- /dev/null +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNetServerConnectionFactorySpec.java @@ -0,0 +1,58 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.ip.dsl; + +import org.springframework.integration.ip.tcp.connection.TcpNetConnectionSupport; +import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory; +import org.springframework.integration.ip.tcp.connection.TcpSocketFactorySupport; + +/** + * {@link TcpServerConnectionFactorySpec} for {@link TcpNetServerConnectionFactory}s. + * + * @author Gary Russell + * @since 6.0.3 + */ +public class TcpNetServerConnectionFactorySpec + extends TcpServerConnectionFactorySpec { + + protected TcpNetServerConnectionFactorySpec(int port) { + super(new TcpNetServerConnectionFactory(port)); + } + + /** + * The {@link TcpNetConnectionSupport} to use to create connection objects. + * @param connectionSupport the {@link TcpNetConnectionSupport}. + * @return the spec. + * @see TcpNetServerConnectionFactory#setTcpNetConnectionSupport(TcpNetConnectionSupport) + */ + public TcpNetServerConnectionFactorySpec connectionSupport(TcpNetConnectionSupport connectionSupport) { + this.target.setTcpNetConnectionSupport(connectionSupport); + return this; + } + + /** + * Set the {@link TcpSocketFactorySupport} used to create server sockets. + * @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport} + * @return the spec. + * @see TcpNetServerConnectionFactory#setTcpSocketFactorySupport(TcpSocketFactorySupport) + */ + public TcpNetServerConnectionFactorySpec socketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) { + this.target.setTcpSocketFactorySupport(tcpSocketFactorySupport); + return this; + } + +} diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNioClientConnectionFactorySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNioClientConnectionFactorySpec.java new file mode 100644 index 00000000000..0848ca5a444 --- /dev/null +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNioClientConnectionFactorySpec.java @@ -0,0 +1,57 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.ip.dsl; + +import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory; +import org.springframework.integration.ip.tcp.connection.TcpNioConnectionSupport; + +/** + * {@link TcpClientConnectionFactorySpec} for {@link TcpNioClientConnectionFactory}s. + * + * @author Gary Russell + * @since 6.0.3 + */ +public class TcpNioClientConnectionFactorySpec + extends TcpClientConnectionFactorySpec { + + protected TcpNioClientConnectionFactorySpec(String host, int port) { + super(new TcpNioClientConnectionFactory(host, port)); + } + + /** + * True to use direct buffers. + * @param usingDirectBuffers true for direct. + * @return the spec. + * @see TcpNioClientConnectionFactory#setUsingDirectBuffers(boolean) + */ + public TcpNioClientConnectionFactorySpec directBuffers(boolean usingDirectBuffers) { + this.target.setUsingDirectBuffers(usingDirectBuffers); + return this; + } + + /** + * The {@link TcpNioConnectionSupport} to use. + * @param tcpNioSupport the {@link TcpNioConnectionSupport}. + * @return the spec. + * @see TcpNioClientConnectionFactory#setTcpNioConnectionSupport(TcpNioConnectionSupport) + */ + public TcpNioClientConnectionFactorySpec connectionSupport(TcpNioConnectionSupport tcpNioSupport) { + this.target.setTcpNioConnectionSupport(tcpNioSupport); + return this; + } + +} diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNioServerConnectionFactorySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNioServerConnectionFactorySpec.java new file mode 100644 index 00000000000..55d3534ced1 --- /dev/null +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpNioServerConnectionFactorySpec.java @@ -0,0 +1,57 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.ip.dsl; + +import org.springframework.integration.ip.tcp.connection.TcpNioConnectionSupport; +import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory; + +/** + * {@link TcpServerConnectionFactorySpec} for {@link TcpNioServerConnectionFactory}s. + * + * @author Gary Russell + * @since 6.0.3 + */ +public class TcpNioServerConnectionFactorySpec + extends TcpServerConnectionFactorySpec { + + protected TcpNioServerConnectionFactorySpec(int port) { + super(new TcpNioServerConnectionFactory(port)); + } + + /** + * True to use direct buffers. + * @param usingDirectBuffers true for direct. + * @return the spec. + * @see TcpNioServerConnectionFactory#setUsingDirectBuffers(boolean) + */ + public TcpNioServerConnectionFactorySpec directBuffers(boolean usingDirectBuffers) { + this.target.setUsingDirectBuffers(usingDirectBuffers); + return this; + } + + /** + * The {@link TcpNioConnectionSupport} to use. + * @param tcpNioSupport the {@link TcpNioConnectionSupport}. + * @return the spec. + * @see TcpNioServerConnectionFactory#setTcpNioConnectionSupport(TcpNioConnectionSupport) + */ + public TcpNioServerConnectionFactorySpec connectionSupport(TcpNioConnectionSupport tcpNioSupport) { + this.target.setTcpNioConnectionSupport(tcpNioSupport); + return this; + } + +} diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java index 7ef82adb55e..9e2ba4acbd2 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ public TcpOutboundGatewaySpec(AbstractClientConnectionFactory connectionFactoryB * Construct an instance using the supplied connection factory spec. * @param connectionFactorySpec the spec. */ - public TcpOutboundGatewaySpec(TcpClientConnectionFactorySpec connectionFactorySpec) { + public TcpOutboundGatewaySpec(TcpClientConnectionFactorySpec connectionFactorySpec) { this.target = new TcpOutboundGateway(); this.connectionFactory = connectionFactorySpec.get(); this.target.setConnectionFactory(this.connectionFactory); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpServerConnectionFactorySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpServerConnectionFactorySpec.java index 2e540cbb08b..6fa0458b11a 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpServerConnectionFactorySpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpServerConnectionFactorySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,21 +23,48 @@ /** * An {@link AbstractConnectionFactorySpec} for {@link AbstractServerConnectionFactory}s. * + * @param the target {@link TcpServerConnectionFactorySpec} implementation type. + * @param the target {@link AbstractServerConnectionFactory} implementation type. + * * @author Gary Russell * @author Artem Bilan * * @since 5.0 * */ -public class TcpServerConnectionFactorySpec - extends AbstractConnectionFactorySpec { +public abstract class TcpServerConnectionFactorySpec + , C extends AbstractServerConnectionFactory> + extends AbstractConnectionFactorySpec { + + /** + * Create an instance. + * @param cf the connection factory. + * @since 6.0.3 + */ + protected TcpServerConnectionFactorySpec(C cf) { + super(cf); + } + /** + * Create an instance. + * @param port the port. + * @deprecated since 6.0.3; use a subclass. + */ + @Deprecated protected TcpServerConnectionFactorySpec(int port) { this(port, false); } + /** + * Create an instance. + * @param port the port. + * @param nio true for NIO. + * @deprecated since 6.0.3; use a subclass. + */ + @Deprecated + @SuppressWarnings("unchecked") protected TcpServerConnectionFactorySpec(int port, boolean nio) { - super(nio ? new TcpNioServerConnectionFactory(port) : new TcpNetServerConnectionFactory(port)); + super(nio ? (C) new TcpNioServerConnectionFactory(port) : (C) new TcpNetServerConnectionFactory(port)); } /** @@ -45,7 +72,7 @@ protected TcpServerConnectionFactorySpec(int port, boolean nio) { * @return the spec. * @see AbstractServerConnectionFactory#setLocalAddress(String) */ - public TcpServerConnectionFactorySpec localAddress(String localAddress) { + public S localAddress(String localAddress) { this.target.setLocalAddress(localAddress); return _this(); } @@ -55,7 +82,7 @@ public TcpServerConnectionFactorySpec localAddress(String localAddress) { * @return the spec. * @see AbstractServerConnectionFactory#setBacklog(int) */ - public TcpServerConnectionFactorySpec backlog(int backlog) { + public S backlog(int backlog) { this.target.setBacklog(backlog); return _this(); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetClientConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetClientConnectionFactory.java index 97792b18cb3..38d3e3c4847 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetClientConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetClientConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,6 +81,10 @@ public void setTcpNetConnectionSupport(TcpNetConnectionSupport connectionSupport this.tcpNetConnectionSupport = connectionSupport; } + /** + * Set the {@link TcpSocketFactorySupport} used to create server sockets. + * @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport} + */ public void setTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) { Assert.notNull(tcpSocketFactorySupport, "TcpSocketFactorySupport may not be null"); this.tcpSocketFactorySupport = tcpSocketFactorySupport; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java index 18f6f58ae0a..e6b44ef9afe 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,6 +82,10 @@ public SocketAddress getServerSocketAddress() { } } + /** + * Set the {@link TcpSocketFactorySupport} used to create server sockets. + * @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport} + */ public void setTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) { Assert.notNull(tcpSocketFactorySupport, "TcpSocketFactorySupport may not be null"); this.tcpSocketFactorySupport = tcpSocketFactorySupport; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java index e73a6fb2751..56a5f29cbf4 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -314,10 +314,18 @@ public void stop() { super.stop(); } + /** + * Set to true to use direct buffers. + * @param usingDirectBuffers true for direct. + */ public void setUsingDirectBuffers(boolean usingDirectBuffers) { this.usingDirectBuffers = usingDirectBuffers; } + /** + * Set the {@link TcpNioConnectionSupport} to use. + * @param tcpNioSupport the {@link TcpNioConnectionSupport}. + */ public void setTcpNioConnectionSupport(TcpNioConnectionSupport tcpNioSupport) { Assert.notNull(tcpNioSupport, "TcpNioSupport must not be null"); this.tcpNioConnectionSupport = tcpNioSupport; diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java index 3525d40d22e..d30783520b5 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +20,27 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationEventPublisher; import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory; +import org.springframework.integration.ip.tcp.connection.TcpNetConnectionSupport; import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory; import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory; +import org.springframework.integration.ip.tcp.connection.TcpNioConnectionSupport; import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory; +import org.springframework.integration.ip.tcp.connection.TcpSocketFactorySupport; +import org.springframework.integration.ip.tcp.connection.TcpSocketSupport; import org.springframework.integration.ip.util.TestingUtilities; +import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.transformer.ObjectToStringTransformer; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; /** * @author Gary Russell @@ -89,4 +95,62 @@ public void shouldReturnNetFlavor() throws Exception { assertThat(client instanceof TcpNetClientConnectionFactory).isTrue(); } + @Test + void netCustomServer() { + TcpSocketSupport sockSupp = mock(TcpSocketSupport.class); + TcpNetConnectionSupport conSupp = mock(TcpNetConnectionSupport.class); + TcpSocketFactorySupport factSupp = mock(TcpSocketFactorySupport.class); + TcpNetServerConnectionFactory server = Tcp.netServer(0) + .socketSupport(sockSupp) + .connectionSupport(conSupp) + .socketFactorySupport(factSupp) + .get(); + assertThat(TestUtils.getPropertyValue(server, "tcpSocketSupport")).isSameAs(sockSupp); + assertThat(TestUtils.getPropertyValue(server, "tcpNetConnectionSupport")).isSameAs(conSupp); + assertThat(TestUtils.getPropertyValue(server, "tcpSocketFactorySupport")).isSameAs(factSupp); + } + + @Test + void nioCustomServer() { + TcpSocketSupport sockSupp = mock(TcpSocketSupport.class); + TcpNioConnectionSupport conSupp = mock(TcpNioConnectionSupport.class); + TcpNioServerConnectionFactory server = Tcp.nioServer(0) + .socketSupport(sockSupp) + .directBuffers(true) + .connectionSupport(conSupp) + .get(); + assertThat(TestUtils.getPropertyValue(server, "tcpSocketSupport")).isSameAs(sockSupp); + assertThat(TestUtils.getPropertyValue(server, "usingDirectBuffers", Boolean.class)).isTrue(); + assertThat(TestUtils.getPropertyValue(server, "tcpNioConnectionSupport")).isSameAs(conSupp); + } + + @Test + void netCustomClient() { + TcpSocketSupport sockSupp = mock(TcpSocketSupport.class); + TcpNetConnectionSupport conSupp = mock(TcpNetConnectionSupport.class); + TcpSocketFactorySupport factSupp = mock(TcpSocketFactorySupport.class); + TcpNetClientConnectionFactory client = Tcp.netClient("localhost", 0) + .socketSupport(sockSupp) + .connectionSupport(conSupp) + .socketFactorySupport(factSupp) + .get(); + assertThat(TestUtils.getPropertyValue(client, "tcpSocketSupport")).isSameAs(sockSupp); + assertThat(TestUtils.getPropertyValue(client, "tcpNetConnectionSupport")).isSameAs(conSupp); + assertThat(TestUtils.getPropertyValue(client, "tcpSocketFactorySupport")).isSameAs(factSupp); + } + + @Test + void nioCustomClient() { + TcpSocketSupport sockSupp = mock(TcpSocketSupport.class); + TcpNioConnectionSupport conSupp = mock(TcpNioConnectionSupport.class); + TcpNioClientConnectionFactory client = Tcp.nioClient("localhost", 0) + .socketSupport(sockSupp) + .directBuffers(true) + .connectionSupport(conSupp) + .get(); + assertThat(TestUtils.getPropertyValue(client, "tcpSocketSupport")).isSameAs(sockSupp); + assertThat(TestUtils.getPropertyValue(client, "usingDirectBuffers", Boolean.class)).isTrue(); + assertThat(TestUtils.getPropertyValue(client, "tcpNioConnectionSupport")).isSameAs(conSupp); + } + }