1
- // Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved.
1
+ // Copyright (c) 2020-2023 VMware, Inc. or its affiliates. All rights reserved.
2
2
//
3
3
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
4
4
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").
13
13
14
14
package com .rabbitmq .stream .impl ;
15
15
16
+ import static com .rabbitmq .stream .impl .Utils .noOpConsumer ;
17
+
16
18
import com .rabbitmq .stream .AddressResolver ;
17
19
import com .rabbitmq .stream .BackOffDelayPolicy ;
18
- import com .rabbitmq .stream .ChannelCustomizer ;
19
20
import com .rabbitmq .stream .ChunkChecksum ;
20
21
import com .rabbitmq .stream .Codec ;
21
22
import com .rabbitmq .stream .Environment ;
26
27
import com .rabbitmq .stream .metrics .MetricsCollector ;
27
28
import com .rabbitmq .stream .sasl .CredentialsProvider ;
28
29
import com .rabbitmq .stream .sasl .SaslConfiguration ;
30
+ import io .netty .bootstrap .Bootstrap ;
29
31
import io .netty .buffer .ByteBufAllocator ;
32
+ import io .netty .channel .Channel ;
30
33
import io .netty .channel .EventLoopGroup ;
31
34
import io .netty .handler .ssl .SslContext ;
32
35
import io .netty .handler .ssl .SslContextBuilder ;
37
40
import java .util .List ;
38
41
import java .util .Map ;
39
42
import java .util .concurrent .ScheduledExecutorService ;
43
+ import java .util .function .Consumer ;
40
44
import java .util .function .Function ;
41
45
import java .util .stream .Collectors ;
42
46
import javax .net .ssl .SSLException ;
@@ -50,6 +54,7 @@ public class StreamEnvironmentBuilder implements EnvironmentBuilder {
50
54
private String id = "rabbitmq-stream" ;
51
55
private final Client .ClientParameters clientParameters = new Client .ClientParameters ();
52
56
private final DefaultTlsConfiguration tls = new DefaultTlsConfiguration (this );
57
+ private final DefaultNettyConfiguration netty = new DefaultNettyConfiguration (this );
53
58
private ScheduledExecutorService scheduledExecutorService ;
54
59
private List <URI > uris = Collections .emptyList ();
55
60
private BackOffDelayPolicy recoveryBackOffDelayPolicy =
@@ -62,7 +67,6 @@ public class StreamEnvironmentBuilder implements EnvironmentBuilder {
62
67
ProducersCoordinator .MAX_TRACKING_CONSUMERS_PER_CLIENT ;
63
68
private int maxConsumersByConnection = ConsumersCoordinator .MAX_SUBSCRIPTIONS_PER_CLIENT ;
64
69
private CompressionCodecFactory compressionCodecFactory ;
65
- private ByteBufAllocator byteBufAllocator = ByteBufAllocator .DEFAULT ;
66
70
private boolean lazyInit = false ;
67
71
private Function <ClientConnectionType , String > connectionNamingStrategy ;
68
72
@@ -141,10 +145,10 @@ public EnvironmentBuilder id(String id) {
141
145
return this ;
142
146
}
143
147
148
+ @ SuppressWarnings ("deprecation" )
144
149
@ Override
145
150
public EnvironmentBuilder byteBufAllocator (ByteBufAllocator byteBufAllocator ) {
146
- this .byteBufAllocator = byteBufAllocator ;
147
- this .clientParameters .byteBufAllocator (byteBufAllocator );
151
+ this .netty ().byteBufAllocator (byteBufAllocator );
148
152
return this ;
149
153
}
150
154
@@ -189,8 +193,10 @@ public StreamEnvironmentBuilder requestedMaxFrameSize(int requestedMaxFrameSize)
189
193
return this ;
190
194
}
191
195
192
- public StreamEnvironmentBuilder channelCustomizer (ChannelCustomizer channelCustomizer ) {
193
- this .clientParameters .channelCustomizer (channelCustomizer );
196
+ @ SuppressWarnings ("deprecation" )
197
+ public StreamEnvironmentBuilder channelCustomizer (
198
+ com .rabbitmq .stream .ChannelCustomizer channelCustomizer ) {
199
+ this .netty ().channelCustomizer (ch -> channelCustomizer .customize (ch ));
194
200
return this ;
195
201
}
196
202
@@ -289,6 +295,11 @@ public TlsConfiguration tls() {
289
295
return this .tls ;
290
296
}
291
297
298
+ @ Override
299
+ public NettyConfiguration netty () {
300
+ return this .netty ;
301
+ }
302
+
292
303
@ Override
293
304
public Environment build () {
294
305
if (this .compressionCodecFactory == null ) {
@@ -298,6 +309,9 @@ public Environment build() {
298
309
}
299
310
this .id = this .id == null ? "rabbitmq-stream" : this .id ;
300
311
this .connectionNamingStrategy = Utils .defaultConnectionNamingStrategy (this .id + "-" );
312
+ this .clientParameters .byteBufAllocator (this .netty .byteBufAllocator );
313
+ this .clientParameters .channelCustomizer (this .netty .channelCustomizer );
314
+ this .clientParameters .bootstrapCustomizer (this .netty .bootstrapCustomizer );
301
315
return new StreamEnvironment (
302
316
scheduledExecutorService ,
303
317
clientParameters ,
@@ -309,7 +323,7 @@ public Environment build() {
309
323
maxTrackingConsumersByConnection ,
310
324
maxConsumersByConnection ,
311
325
tls ,
312
- byteBufAllocator ,
326
+ netty . byteBufAllocator ,
313
327
lazyInit ,
314
328
connectionNamingStrategy );
315
329
}
@@ -382,4 +396,40 @@ public SslContext sslContext() {
382
396
return sslContext ;
383
397
}
384
398
}
399
+
400
+ static class DefaultNettyConfiguration implements NettyConfiguration {
401
+
402
+ private final EnvironmentBuilder environmentBuilder ;
403
+
404
+ private DefaultNettyConfiguration (EnvironmentBuilder environmentBuilder ) {
405
+ this .environmentBuilder = environmentBuilder ;
406
+ }
407
+
408
+ private ByteBufAllocator byteBufAllocator = ByteBufAllocator .DEFAULT ;
409
+ private Consumer <Channel > channelCustomizer = noOpConsumer ();
410
+ private Consumer <Bootstrap > bootstrapCustomizer = noOpConsumer ();
411
+
412
+ @ Override
413
+ public NettyConfiguration byteBufAllocator (ByteBufAllocator byteBufAllocator ) {
414
+ this .byteBufAllocator = byteBufAllocator ;
415
+ return this ;
416
+ }
417
+
418
+ @ Override
419
+ public NettyConfiguration channelCustomizer (Consumer <Channel > channelCustomizer ) {
420
+ this .channelCustomizer = channelCustomizer ;
421
+ return this ;
422
+ }
423
+
424
+ @ Override
425
+ public NettyConfiguration bootstrapCustomizer (Consumer <Bootstrap > bootstrapCustomizer ) {
426
+ this .bootstrapCustomizer = bootstrapCustomizer ;
427
+ return this ;
428
+ }
429
+
430
+ @ Override
431
+ public EnvironmentBuilder environmentBuilder () {
432
+ return this .environmentBuilder ;
433
+ }
434
+ }
385
435
}
0 commit comments