Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 54bd46e

Browse files
authored
Bugfix 191 (#192)
* Fixed issue with LoopResources no being injected
1 parent 475961d commit 54bd46e

File tree

3 files changed

+87
-11
lines changed

3 files changed

+87
-11
lines changed

services-gateway-client-transport/src/main/java/io/scalecube/services/gateway/transport/http/HttpGatewayClient.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,44 @@ public final class HttpGatewayClient implements GatewayClient {
2929
private final GatewayClientCodec<ByteBuf> codec;
3030
private final HttpClient httpClient;
3131
private final LoopResources loopResources;
32+
private final boolean ownsLoopResources;
3233

3334
private final Sinks.One<Void> close = Sinks.one();
3435
private final Sinks.One<Void> onClose = Sinks.one();
3536

3637
/**
37-
* Creates instance of http client transport.
38+
* Constructor.
3839
*
39-
* @param settings client settings
40+
* @param settings settings
41+
* @param codec codec
4042
*/
4143
public HttpGatewayClient(GatewayClientSettings settings, GatewayClientCodec<ByteBuf> codec) {
44+
this(settings, codec, LoopResources.create("http-gateway-client"), true);
45+
}
46+
47+
/**
48+
* Constructor.
49+
*
50+
* @param settings settings
51+
* @param codec codec
52+
* @param loopResources loopResources
53+
*/
54+
public HttpGatewayClient(
55+
GatewayClientSettings settings,
56+
GatewayClientCodec<ByteBuf> codec,
57+
LoopResources loopResources) {
58+
this(settings, codec, loopResources, false);
59+
}
60+
61+
private HttpGatewayClient(
62+
GatewayClientSettings settings,
63+
GatewayClientCodec<ByteBuf> codec,
64+
LoopResources loopResources,
65+
boolean ownsLoopResources) {
66+
4267
this.codec = codec;
43-
this.loopResources = LoopResources.create("http-gateway-client");
68+
this.loopResources = loopResources;
69+
this.ownsLoopResources = ownsLoopResources;
4470

4571
HttpClient httpClient =
4672
HttpClient.create(ConnectionProvider.create("http-gateway-client"))
@@ -111,7 +137,7 @@ public Mono<Void> onClose() {
111137
}
112138

113139
private Mono<Void> doClose() {
114-
return Mono.defer(loopResources::disposeLater);
140+
return ownsLoopResources ? Mono.defer(loopResources::disposeLater) : Mono.empty();
115141
}
116142

117143
private ServiceMessage toMessage(HttpClientResponse httpResponse, ByteBuf content) {

services-gateway-client-transport/src/main/java/io/scalecube/services/gateway/transport/rsocket/RSocketGatewayClient.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class RSocketGatewayClient implements GatewayClient {
3333
private final GatewayClientSettings settings;
3434
private final GatewayClientCodec<Payload> codec;
3535
private final LoopResources loopResources;
36+
private final boolean ownsLoopResources;
3637

3738
private final Sinks.One<Void> close = Sinks.one();
3839
private final Sinks.One<Void> onClose = Sinks.one();
@@ -41,15 +42,39 @@ public final class RSocketGatewayClient implements GatewayClient {
4142
private volatile Mono<?> rsocketMono;
4243

4344
/**
44-
* Constructor for gateway over rsocket client transport.
45+
* Constructor.
4546
*
46-
* @param settings client settings.
47-
* @param codec client codec.
47+
* @param settings settings
48+
* @param codec codec
4849
*/
4950
public RSocketGatewayClient(GatewayClientSettings settings, GatewayClientCodec<Payload> codec) {
51+
this(settings, codec, LoopResources.create("rsocket-gateway-client"), true);
52+
}
53+
54+
/**
55+
* Constructor.
56+
*
57+
* @param settings settings
58+
* @param codec codec
59+
* @param loopResources loopResources
60+
*/
61+
public RSocketGatewayClient(
62+
GatewayClientSettings settings,
63+
GatewayClientCodec<Payload> codec,
64+
LoopResources loopResources) {
65+
this(settings, codec, loopResources, false);
66+
}
67+
68+
private RSocketGatewayClient(
69+
GatewayClientSettings settings,
70+
GatewayClientCodec<Payload> codec,
71+
LoopResources loopResources,
72+
boolean ownsLoopResources) {
73+
5074
this.settings = settings;
5175
this.codec = codec;
52-
this.loopResources = LoopResources.create("rsocket-gateway-client");
76+
this.loopResources = loopResources;
77+
this.ownsLoopResources = ownsLoopResources;
5378

5479
// Setup cleanup
5580
close
@@ -106,7 +131,7 @@ public Mono<Void> onClose() {
106131
}
107132

108133
private Mono<Void> doClose() {
109-
return Mono.defer(loopResources::disposeLater);
134+
return ownsLoopResources ? Mono.defer(loopResources::disposeLater) : Mono.empty();
110135
}
111136

112137
private Mono<RSocket> getOrConnect() {

services-gateway-client-transport/src/main/java/io/scalecube/services/gateway/transport/websocket/WebsocketGatewayClient.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public final class WebsocketGatewayClient implements GatewayClient {
3939
private final GatewayClientSettings settings;
4040
private final HttpClient httpClient;
4141
private final LoopResources loopResources;
42+
private final boolean ownsLoopResources;
4243

4344
private final Sinks.One<Void> close = Sinks.one();
4445
private final Sinks.One<Void> onClose = Sinks.one();
@@ -53,9 +54,33 @@ public final class WebsocketGatewayClient implements GatewayClient {
5354
* @param codec client codec.
5455
*/
5556
public WebsocketGatewayClient(GatewayClientSettings settings, GatewayClientCodec<ByteBuf> codec) {
57+
this(settings, codec, LoopResources.create("websocket-gateway-client"), true);
58+
}
59+
60+
/**
61+
* Creates instance of websocket client transport.
62+
*
63+
* @param settings client settings
64+
* @param codec client codec.
65+
* @param loopResources loopResources.
66+
*/
67+
public WebsocketGatewayClient(
68+
GatewayClientSettings settings,
69+
GatewayClientCodec<ByteBuf> codec,
70+
LoopResources loopResources) {
71+
this(settings, codec, loopResources, false);
72+
}
73+
74+
private WebsocketGatewayClient(
75+
GatewayClientSettings settings,
76+
GatewayClientCodec<ByteBuf> codec,
77+
LoopResources loopResources,
78+
boolean ownsLoopResources) {
79+
5680
this.settings = settings;
5781
this.codec = codec;
58-
this.loopResources = LoopResources.create("websocket-gateway-client");
82+
this.loopResources = loopResources;
83+
this.ownsLoopResources = ownsLoopResources;
5984

6085
HttpClient httpClient =
6186
HttpClient.create(ConnectionProvider.newConnection())
@@ -131,7 +156,7 @@ public Mono<Void> onClose() {
131156
}
132157

133158
private Mono<Void> doClose() {
134-
return Mono.defer(loopResources::disposeLater);
159+
return ownsLoopResources ? Mono.defer(loopResources::disposeLater) : Mono.empty();
135160
}
136161

137162
private Mono<WebsocketGatewayClientSession> getOrConnect() {

0 commit comments

Comments
 (0)