Skip to content

Commit

Permalink
Added isSecured option to the RSocketClientTransportFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v committed Jul 6, 2020
1 parent 81caedb commit 19bd016
Showing 1 changed file with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,30 @@ public interface RSocketClientTransportFactory {
* @return factory function for {@link RSocketClientTransportFactory}
*/
static Function<LoopResources, RSocketClientTransportFactory> tcp() {
return tcp(false);
}

/**
* Returns default rsocket tcp client transport factory.
*
* @see TcpClientTransport
* @param isSecured is client transport secured
* @return factory function for {@link RSocketClientTransportFactory}
*/
static Function<LoopResources, RSocketClientTransportFactory> tcp(boolean isSecured) {
return (LoopResources loopResources) ->
(RSocketClientTransportFactory)
address ->
TcpClientTransport.create(
TcpClient.newConnection()
.host(address.host())
.port(address.port())
.runOn(loopResources));
address -> {
TcpClient tcpClient =
TcpClient.newConnection()
.runOn(loopResources)
.host(address.host())
.port(address.port())
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.SO_REUSEADDR, true);
return TcpClientTransport.create(isSecured ? tcpClient.secure() : tcpClient);
};
}

/**
Expand All @@ -36,20 +52,34 @@ static Function<LoopResources, RSocketClientTransportFactory> tcp() {
* @return factory function for {@link RSocketClientTransportFactory}
*/
static Function<LoopResources, RSocketClientTransportFactory> websocket() {
return websocket(false);
}

/**
* Returns default rsocket websocket client transport factory.
*
* @see WebsocketClientTransport
* @param isSecured is client transport secured
* @return factory function for {@link RSocketClientTransportFactory}
*/
static Function<LoopResources, RSocketClientTransportFactory> websocket(boolean isSecured) {
return (LoopResources loopResources) ->
(RSocketClientTransportFactory)
address ->
WebsocketClientTransport.create(
HttpClient.newConnection()
.tcpConfiguration(
tcpClient ->
tcpClient
.runOn(loopResources)
.host(address.host())
.port(address.port())
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.SO_REUSEADDR, true)),
tcpClient -> {
TcpClient tcpClient1 =
tcpClient
.runOn(loopResources)
.host(address.host())
.port(address.port())
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.SO_REUSEADDR, true);
return isSecured ? tcpClient1.secure() : tcpClient1;
}),
"/");
}

Expand Down

0 comments on commit 19bd016

Please sign in to comment.