15
15
package com .rabbitmq .stream .impl ;
16
16
17
17
import static com .rabbitmq .stream .Constants .*;
18
+ import static com .rabbitmq .stream .impl .ThreadUtils .threadFactory ;
18
19
import static com .rabbitmq .stream .impl .Utils .DEFAULT_USERNAME ;
19
20
import static com .rabbitmq .stream .impl .Utils .encodeRequestCode ;
20
21
import static com .rabbitmq .stream .impl .Utils .encodeResponseCode ;
45
46
import com .rabbitmq .stream .impl .Client .ShutdownContext .ShutdownReason ;
46
47
import com .rabbitmq .stream .impl .ServerFrameHandler .FrameHandler ;
47
48
import com .rabbitmq .stream .impl .ServerFrameHandler .FrameHandlerInfo ;
48
- import com .rabbitmq .stream .impl .Utils .NamedThreadFactory ;
49
49
import com .rabbitmq .stream .metrics .MetricsCollector ;
50
50
import com .rabbitmq .stream .metrics .NoOpMetricsCollector ;
51
51
import com .rabbitmq .stream .sasl .CredentialsProvider ;
@@ -164,7 +164,7 @@ public class Client implements AutoCloseable {
164
164
final CompressionCodecFactory compressionCodecFactory ;
165
165
private final Consumer <ShutdownContext .ShutdownReason > shutdownListenerCallback ;
166
166
private final ToLongFunction <Object > publishSequenceFunction =
167
- new ToLongFunction <Object >() {
167
+ new ToLongFunction <>() {
168
168
private final AtomicLong publishSequence = new AtomicLong (0 );
169
169
170
170
@ Override
@@ -302,6 +302,7 @@ public void initChannel(SocketChannel ch) {
302
302
}
303
303
});
304
304
305
+ this .nettyClosing = Utils .makeIdempotent (this ::closeNetty );
305
306
ChannelFuture f ;
306
307
String clientConnectionName = parameters .clientProperties .getOrDefault ("connection_name" , "" );
307
308
try {
@@ -326,13 +327,11 @@ public void initChannel(SocketChannel ch) {
326
327
throw new StreamException (message , e );
327
328
}
328
329
}
329
-
330
330
this .channel = f .channel ();
331
- this .nettyClosing = Utils .makeIdempotent (this ::closeNetty );
332
331
ExecutorServiceFactory executorServiceFactory = parameters .executorServiceFactory ;
333
332
if (executorServiceFactory == null ) {
334
333
this .executorService =
335
- Executors .newSingleThreadExecutor (new NamedThreadFactory (clientConnectionName + "-" ));
334
+ Executors .newSingleThreadExecutor (threadFactory (clientConnectionName + "-" ));
336
335
} else {
337
336
this .executorService = executorServiceFactory .get ();
338
337
}
@@ -341,7 +340,7 @@ public void initChannel(SocketChannel ch) {
341
340
if (dispatchingExecutorServiceFactory == null ) {
342
341
this .dispatchingExecutorService =
343
342
Executors .newSingleThreadExecutor (
344
- new NamedThreadFactory ("dispatching-" + clientConnectionName + "-" ));
343
+ threadFactory ("dispatching-" + clientConnectionName + "-" ));
345
344
} else {
346
345
this .dispatchingExecutorService = dispatchingExecutorServiceFactory .get ();
347
346
}
@@ -1443,7 +1442,7 @@ void closingSequence(ShutdownContext.ShutdownReason reason) {
1443
1442
1444
1443
private void closeNetty () {
1445
1444
try {
1446
- if (this .channel .isOpen ()) {
1445
+ if (this .channel != null && this . channel .isOpen ()) {
1447
1446
LOGGER .debug ("Closing Netty channel" );
1448
1447
this .channel .close ().get (10 , TimeUnit .SECONDS );
1449
1448
}
0 commit comments