Skip to content

Commit

Permalink
Create LoopResources/PoolResources only in case the user does not spe…
Browse files Browse the repository at this point in the history
…cify their own.
  • Loading branch information
violetagg committed Sep 19, 2017
1 parent 59beb9d commit 336a4c1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/main/java/reactor/ipc/netty/http/client/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ public static HttpClient.Builder builder() {

private HttpClient(HttpClient.Builder builder) {
HttpClientOptions.Builder clientOptionsBuilder = HttpClientOptions.builder();
clientOptionsBuilder.loopResources(HttpResources.get())
.poolResources(HttpResources.get());
if (Objects.nonNull(builder.options)) {
builder.options.accept(clientOptionsBuilder);
}
clientOptionsBuilder.loopResources(HttpResources.get());
if (!clientOptionsBuilder.isPoolDisabled()) {
clientOptionsBuilder.poolResources(HttpResources.get());
}
this.options = clientOptionsBuilder.build();
this.client = new TcpBridgeClient(options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public static HttpServer.Builder builder() {

private HttpServer(HttpServer.Builder builder) {
HttpServerOptions.Builder serverOptionsBuilder = HttpServerOptions.builder();
serverOptionsBuilder.loopResources(HttpResources.get());
if (Objects.isNull(builder.options)) {
serverOptionsBuilder.host(builder.bindAddress)
.port(builder.port);
}
else {
builder.options.accept(serverOptionsBuilder);
}
serverOptionsBuilder.loopResources(HttpResources.get());
this.options = serverOptionsBuilder.build();
this.server = new TcpBridgeServer(this.options);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/reactor/ipc/netty/options/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public String toString() {
public static class Builder<BUILDER extends Builder<BUILDER>>
extends NettyOptions.Builder<Bootstrap, ClientOptions, BUILDER> {
private PoolResources poolResources;
private boolean poolDisabled = false;
private InternetProtocolFamily protocolFamily;
private String host;
private int port = -1;
Expand Down Expand Up @@ -299,6 +300,7 @@ public final BUILDER resolver(AddressResolverGroup<?> resolver) {
*/
public final BUILDER poolResources(PoolResources poolResources) {
this.poolResources = Objects.requireNonNull(poolResources, "poolResources");
this.poolDisabled = false;
return get();
}

Expand All @@ -309,9 +311,14 @@ public final BUILDER poolResources(PoolResources poolResources) {
*/
public BUILDER disablePool() {
this.poolResources = null;
this.poolDisabled = true;
return get();
}

public final boolean isPoolDisabled() {
return poolDisabled;
}

/**
* Configures the version family for the socket.
*
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/reactor/ipc/netty/tcp/TcpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ public static TcpClient.Builder builder() {

protected TcpClient(TcpClient.Builder builder) {
ClientOptions.Builder<?> clientOptionsBuilder = ClientOptions.builder();
clientOptionsBuilder.loopResources(TcpResources.get())
.poolResources(TcpResources.get());
if (Objects.nonNull(builder.options)) {
builder.options.accept(clientOptionsBuilder);
}
clientOptionsBuilder.loopResources(TcpResources.get());
if (!clientOptionsBuilder.isPoolDisabled()) {
clientOptionsBuilder.poolResources(TcpResources.get());
}
this.options = clientOptionsBuilder.build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/reactor/ipc/netty/tcp/TcpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ public static TcpServer.Builder builder() {

protected TcpServer(TcpServer.Builder builder) {
ServerOptions.Builder<?> serverOptionsBuilder = ServerOptions.builder();
serverOptionsBuilder.loopResources(TcpResources.get());
if (Objects.isNull(builder.options)) {
serverOptionsBuilder.host(builder.bindAddress)
.port(builder.port);
}
else {
builder.options.accept(serverOptionsBuilder);
}
serverOptionsBuilder.loopResources(TcpResources.get());
this.options = serverOptionsBuilder.build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/reactor/ipc/netty/udp/UdpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public static UdpClient.Builder builder() {

private UdpClient(UdpClient.Builder builder) {
UdpClientOptions.Builder clientOptionsBuilder = UdpClientOptions.builder();
clientOptionsBuilder.loopResources(DEFAULT_UDP_LOOPS);
if (Objects.nonNull(builder.options)) {
builder.options.accept(clientOptionsBuilder);
}
clientOptionsBuilder.loopResources(DEFAULT_UDP_LOOPS);
this.options = clientOptionsBuilder.build();
}

Expand Down

0 comments on commit 336a4c1

Please sign in to comment.