GH-4013: TCP DSL Improvements
Resolves https://github.com/spring-projects/spring-integration/issues/4013 Add Net/NIO specific Server/Client connection factory specs. * Shorten DSL method names, as suggested.
This commit is contained in:
@@ -215,9 +215,20 @@ public abstract class AbstractConnectionFactorySpec
|
|||||||
/**
|
/**
|
||||||
* @param tcpSocketSupport the {@link TcpSocketSupport}.
|
* @param tcpSocketSupport the {@link TcpSocketSupport}.
|
||||||
* @return the spec.
|
* @return the spec.
|
||||||
|
* @deprecated in favor of {@link #socketSupport(TcpSocketSupport)}.
|
||||||
* @see AbstractConnectionFactory#setTcpSocketSupport(TcpSocketSupport)
|
* @see AbstractConnectionFactory#setTcpSocketSupport(TcpSocketSupport)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public S tcpSocketSupport(TcpSocketSupport tcpSocketSupport) {
|
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);
|
this.target.setTcpSocketSupport(tcpSocketSupport);
|
||||||
return _this();
|
return _this();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -39,8 +39,8 @@ public final class Tcp {
|
|||||||
* @param port the port to listen on.
|
* @param port the port to listen on.
|
||||||
* @return the spec.
|
* @return the spec.
|
||||||
*/
|
*/
|
||||||
public static TcpServerConnectionFactorySpec nioServer(int port) {
|
public static TcpNioServerConnectionFactorySpec nioServer(int port) {
|
||||||
return new TcpServerConnectionFactorySpec(port, true);
|
return new TcpNioServerConnectionFactorySpec(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +48,8 @@ public final class Tcp {
|
|||||||
* @param port the port to listen on.
|
* @param port the port to listen on.
|
||||||
* @return the spec.
|
* @return the spec.
|
||||||
*/
|
*/
|
||||||
public static TcpServerConnectionFactorySpec netServer(int port) {
|
public static TcpNetServerConnectionFactorySpec netServer(int port) {
|
||||||
return new TcpServerConnectionFactorySpec(port, false);
|
return new TcpNetServerConnectionFactorySpec(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,8 +58,8 @@ public final class Tcp {
|
|||||||
* @param port the port to connect to.
|
* @param port the port to connect to.
|
||||||
* @return the spec.
|
* @return the spec.
|
||||||
*/
|
*/
|
||||||
public static TcpClientConnectionFactorySpec nioClient(String host, int port) {
|
public static TcpNioClientConnectionFactorySpec nioClient(String host, int port) {
|
||||||
return new TcpClientConnectionFactorySpec(host, port, true);
|
return new TcpNioClientConnectionFactorySpec(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,8 +68,8 @@ public final class Tcp {
|
|||||||
* @param port the port to connect to.
|
* @param port the port to connect to.
|
||||||
* @return the spec.
|
* @return the spec.
|
||||||
*/
|
*/
|
||||||
public static TcpClientConnectionFactorySpec netClient(String host, int port) {
|
public static TcpNetClientConnectionFactorySpec netClient(String host, int port) {
|
||||||
return new TcpClientConnectionFactorySpec(host, port, false);
|
return new TcpNetClientConnectionFactorySpec(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +127,7 @@ public final class Tcp {
|
|||||||
* @param connectionFactory the connection factory spec.
|
* @param connectionFactory the connection factory spec.
|
||||||
* @return the spec.
|
* @return the spec.
|
||||||
*/
|
*/
|
||||||
public static TcpOutboundGatewaySpec outboundGateway(TcpClientConnectionFactorySpec connectionFactory) {
|
public static TcpOutboundGatewaySpec outboundGateway(TcpClientConnectionFactorySpec<?, ?> connectionFactory) {
|
||||||
return new TcpOutboundGatewaySpec(connectionFactory);
|
return new TcpOutboundGatewaySpec(connectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,27 +17,57 @@
|
|||||||
package org.springframework.integration.ip.dsl;
|
package org.springframework.integration.ip.dsl;
|
||||||
|
|
||||||
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
|
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.TcpNetClientConnectionFactory;
|
||||||
import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
|
import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link AbstractConnectionFactorySpec} for {@link AbstractClientConnectionFactory}s.
|
* An {@link AbstractConnectionFactorySpec} for {@link AbstractClientConnectionFactory}s.
|
||||||
*
|
*
|
||||||
|
* @param <S> the target {@link TcpServerConnectionFactorySpec} implementation type.
|
||||||
|
* @param <C> the target {@link AbstractServerConnectionFactory} implementation type.
|
||||||
|
*
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
* @author Artem Bilan
|
* @author Artem Bilan
|
||||||
*
|
*
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TcpClientConnectionFactorySpec
|
public abstract class TcpClientConnectionFactorySpec
|
||||||
extends AbstractConnectionFactorySpec<TcpClientConnectionFactorySpec, AbstractClientConnectionFactory> {
|
<S extends TcpClientConnectionFactorySpec<S, C>, C extends AbstractClientConnectionFactory>
|
||||||
|
extends AbstractConnectionFactorySpec<S, C> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
protected TcpClientConnectionFactorySpec(String host, int port) {
|
||||||
this(host, port, false);
|
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) {
|
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 @@ public class TcpClientConnectionFactorySpec
|
|||||||
* @return the spec.
|
* @return the spec.
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
public TcpClientConnectionFactorySpec connectTimeout(int connectTimeout) {
|
public S connectTimeout(int connectTimeout) {
|
||||||
this.target.setConnectTimeout(connectTimeout);
|
this.target.setConnectTimeout(connectTimeout);
|
||||||
return _this();
|
return _this();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<TcpNetClientConnectionFactorySpec, TcpNetClientConnectionFactory> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<TcpNetServerConnectionFactorySpec, TcpNetServerConnectionFactory> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<TcpNioClientConnectionFactorySpec, TcpNioClientConnectionFactory> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<TcpNioServerConnectionFactorySpec, TcpNioServerConnectionFactory> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -56,7 +56,7 @@ public class TcpOutboundGatewaySpec extends MessageHandlerSpec<TcpOutboundGatewa
|
|||||||
* Construct an instance using the supplied connection factory spec.
|
* Construct an instance using the supplied connection factory spec.
|
||||||
* @param connectionFactorySpec the spec.
|
* @param connectionFactorySpec the spec.
|
||||||
*/
|
*/
|
||||||
public TcpOutboundGatewaySpec(TcpClientConnectionFactorySpec connectionFactorySpec) {
|
public TcpOutboundGatewaySpec(TcpClientConnectionFactorySpec<?, ?> connectionFactorySpec) {
|
||||||
this.target = new TcpOutboundGateway();
|
this.target = new TcpOutboundGateway();
|
||||||
this.connectionFactory = connectionFactorySpec.get();
|
this.connectionFactory = connectionFactorySpec.get();
|
||||||
this.target.setConnectionFactory(this.connectionFactory);
|
this.target.setConnectionFactory(this.connectionFactory);
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,21 +23,48 @@ import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionF
|
|||||||
/**
|
/**
|
||||||
* An {@link AbstractConnectionFactorySpec} for {@link AbstractServerConnectionFactory}s.
|
* An {@link AbstractConnectionFactorySpec} for {@link AbstractServerConnectionFactory}s.
|
||||||
*
|
*
|
||||||
|
* @param <S> the target {@link TcpServerConnectionFactorySpec} implementation type.
|
||||||
|
* @param <C> the target {@link AbstractServerConnectionFactory} implementation type.
|
||||||
|
*
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
* @author Artem Bilan
|
* @author Artem Bilan
|
||||||
*
|
*
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TcpServerConnectionFactorySpec
|
public abstract class TcpServerConnectionFactorySpec
|
||||||
extends AbstractConnectionFactorySpec<TcpServerConnectionFactorySpec, AbstractServerConnectionFactory> {
|
<S extends TcpServerConnectionFactorySpec<S, C>, C extends AbstractServerConnectionFactory>
|
||||||
|
extends AbstractConnectionFactorySpec<S, C> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
protected TcpServerConnectionFactorySpec(int port) {
|
||||||
this(port, false);
|
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) {
|
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 @@ public class TcpServerConnectionFactorySpec
|
|||||||
* @return the spec.
|
* @return the spec.
|
||||||
* @see AbstractServerConnectionFactory#setLocalAddress(String)
|
* @see AbstractServerConnectionFactory#setLocalAddress(String)
|
||||||
*/
|
*/
|
||||||
public TcpServerConnectionFactorySpec localAddress(String localAddress) {
|
public S localAddress(String localAddress) {
|
||||||
this.target.setLocalAddress(localAddress);
|
this.target.setLocalAddress(localAddress);
|
||||||
return _this();
|
return _this();
|
||||||
}
|
}
|
||||||
@@ -55,7 +82,7 @@ public class TcpServerConnectionFactorySpec
|
|||||||
* @return the spec.
|
* @return the spec.
|
||||||
* @see AbstractServerConnectionFactory#setBacklog(int)
|
* @see AbstractServerConnectionFactory#setBacklog(int)
|
||||||
*/
|
*/
|
||||||
public TcpServerConnectionFactorySpec backlog(int backlog) {
|
public S backlog(int backlog) {
|
||||||
this.target.setBacklog(backlog);
|
this.target.setBacklog(backlog);
|
||||||
return _this();
|
return _this();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -81,6 +81,10 @@ public class TcpNetClientConnectionFactory extends
|
|||||||
this.tcpNetConnectionSupport = connectionSupport;
|
this.tcpNetConnectionSupport = connectionSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link TcpSocketFactorySupport} used to create server sockets.
|
||||||
|
* @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport}
|
||||||
|
*/
|
||||||
public void setTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) {
|
public void setTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) {
|
||||||
Assert.notNull(tcpSocketFactorySupport, "TcpSocketFactorySupport may not be null");
|
Assert.notNull(tcpSocketFactorySupport, "TcpSocketFactorySupport may not be null");
|
||||||
this.tcpSocketFactorySupport = tcpSocketFactorySupport;
|
this.tcpSocketFactorySupport = tcpSocketFactorySupport;
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -82,6 +82,10 @@ public class TcpNetServerConnectionFactory extends AbstractServerConnectionFacto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link TcpSocketFactorySupport} used to create server sockets.
|
||||||
|
* @param tcpSocketFactorySupport the {@link TcpSocketFactorySupport}
|
||||||
|
*/
|
||||||
public void setTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) {
|
public void setTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport) {
|
||||||
Assert.notNull(tcpSocketFactorySupport, "TcpSocketFactorySupport may not be null");
|
Assert.notNull(tcpSocketFactorySupport, "TcpSocketFactorySupport may not be null");
|
||||||
this.tcpSocketFactorySupport = tcpSocketFactorySupport;
|
this.tcpSocketFactorySupport = tcpSocketFactorySupport;
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -314,10 +314,18 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto
|
|||||||
super.stop();
|
super.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to true to use direct buffers.
|
||||||
|
* @param usingDirectBuffers true for direct.
|
||||||
|
*/
|
||||||
public void setUsingDirectBuffers(boolean usingDirectBuffers) {
|
public void setUsingDirectBuffers(boolean usingDirectBuffers) {
|
||||||
this.usingDirectBuffers = usingDirectBuffers;
|
this.usingDirectBuffers = usingDirectBuffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link TcpNioConnectionSupport} to use.
|
||||||
|
* @param tcpNioSupport the {@link TcpNioConnectionSupport}.
|
||||||
|
*/
|
||||||
public void setTcpNioConnectionSupport(TcpNioConnectionSupport tcpNioSupport) {
|
public void setTcpNioConnectionSupport(TcpNioConnectionSupport tcpNioSupport) {
|
||||||
Assert.notNull(tcpNioSupport, "TcpNioSupport must not be null");
|
Assert.notNull(tcpNioSupport, "TcpNioSupport must not be null");
|
||||||
this.tcpNioConnectionSupport = tcpNioSupport;
|
this.tcpNioConnectionSupport = tcpNioSupport;
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,21 +20,27 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
|
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
|
||||||
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
||||||
import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
|
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.TcpNetServerConnectionFactory;
|
||||||
import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
|
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.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.ip.util.TestingUtilities;
|
||||||
|
import org.springframework.integration.test.util.TestUtils;
|
||||||
import org.springframework.integration.transformer.ObjectToStringTransformer;
|
import org.springframework.integration.transformer.ObjectToStringTransformer;
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
@@ -89,4 +95,62 @@ public class ConnectionFacforyTests {
|
|||||||
assertThat(client instanceof TcpNetClientConnectionFactory).isTrue();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user