Skip to content

GH-4013: TCP DSL Improvements #4015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,17 +39,17 @@ 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);
}

/**
* Create a server spec that does not use NIO.
* @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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 <S> the target {@link TcpServerConnectionFactorySpec} implementation type.
* @param <C> the target {@link AbstractServerConnectionFactory} implementation type.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.0
*
*/
public class TcpClientConnectionFactorySpec
extends AbstractConnectionFactorySpec<TcpClientConnectionFactorySpec, AbstractClientConnectionFactory> {
public abstract class TcpClientConnectionFactorySpec
<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) {
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));
}

/**
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading