@@ -84,6 +84,8 @@ public class Reactor2TcpClient<P> implements TcpOperations<P> {
84
84
85
85
private final EventLoopGroup eventLoopGroup ;
86
86
87
+ private final Environment environment ;
88
+
87
89
private final TcpClientFactory <Message <P >, Message <P >> tcpClientSpecFactory ;
88
90
89
91
private final List <TcpClient <Message <P >, Message <P >>> tcpClients =
@@ -108,12 +110,13 @@ public Reactor2TcpClient(final String host, final int port, final Codec<Buffer,
108
110
// Reactor 2.0.5 requires NioEventLoopGroup vs 2.0.6+ requires EventLoopGroup
109
111
final NioEventLoopGroup nioEventLoopGroup = initEventLoopGroup ();
110
112
this .eventLoopGroup = nioEventLoopGroup ;
113
+ this .environment = new Environment (new SynchronousDispatcherConfigReader ());
111
114
112
115
this .tcpClientSpecFactory = new TcpClientFactory <Message <P >, Message <P >>() {
113
116
@ Override
114
117
public TcpClientSpec <Message <P >, Message <P >> apply (TcpClientSpec <Message <P >, Message <P >> spec ) {
115
118
return spec
116
- .env (new Environment ( new SynchronousDispatcherConfigReader ()) )
119
+ .env (environment )
117
120
.codec (codec )
118
121
.connect (host , port )
119
122
.options (createClientSocketOptions ());
@@ -139,6 +142,7 @@ public Reactor2TcpClient(TcpClientFactory<Message<P>, Message<P>> tcpClientSpecF
139
142
Assert .notNull (tcpClientSpecFactory , "'tcpClientClientFactory' must not be null" );
140
143
this .tcpClientSpecFactory = tcpClientSpecFactory ;
141
144
this .eventLoopGroup = null ;
145
+ this .environment = null ;
142
146
}
143
147
144
148
@@ -269,6 +273,15 @@ public void operationComplete(Future<Object> future) throws Exception {
269
273
promise = eventLoopPromise ;
270
274
}
271
275
276
+ if (this .environment != null ) {
277
+ promise .onComplete (new Consumer <Promise <Void >>() {
278
+ @ Override
279
+ public void accept (Promise <Void > voidPromise ) {
280
+ environment .shutdown ();
281
+ }
282
+ });
283
+ }
284
+
272
285
return new PassThroughPromiseToListenableFutureAdapter <Void >(promise );
273
286
}
274
287
0 commit comments