20
20
import com .rabbitmq .client .SslEngineConfigurator ;
21
21
22
22
import javax .net .ssl .SSLEngine ;
23
- import java .io .IOException ;
24
23
import java .util .concurrent .ExecutorService ;
25
24
import java .util .concurrent .ThreadFactory ;
26
25
27
26
/**
28
27
* Parameters used to configure the NIO mode of a {@link com.rabbitmq.client.ConnectionFactory}.
28
+ *
29
29
* @since 4.0.0
30
30
*/
31
31
public class NioParams {
32
32
33
- /** size of the byte buffer used for inbound data */
33
+ /**
34
+ * size of the byte buffer used for inbound data
35
+ */
34
36
private int readByteBufferSize = 32768 ;
35
37
36
- /** size of the byte buffer used for outbound data */
38
+ /**
39
+ * size of the byte buffer used for outbound data
40
+ */
37
41
private int writeByteBufferSize = 32768 ;
38
42
39
- /** the max number of IO threads */
43
+ /**
44
+ * the max number of IO threads
45
+ */
40
46
private int nbIoThreads = 1 ;
41
47
42
- /** the timeout to enqueue outbound frames */
48
+ /**
49
+ * the timeout to enqueue outbound frames
50
+ */
43
51
private int writeEnqueuingTimeoutInMs = 10 * 1000 ;
44
52
45
- /** the capacity of the queue used for outbound frames */
53
+ /**
54
+ * the capacity of the queue used for outbound frames
55
+ */
46
56
private int writeQueueCapacity = 10000 ;
47
57
48
- /** the executor service used for IO threads and connections shutdown */
58
+ /**
59
+ * the executor service used for IO threads and connections shutdown
60
+ */
49
61
private ExecutorService nioExecutor ;
50
62
51
- /** the thread factory used for IO threads and connections shutdown */
63
+ /**
64
+ * the thread factory used for IO threads and connections shutdown
65
+ */
52
66
private ThreadFactory threadFactory ;
53
67
54
- /** the hook to configure the socket channel before it's open */
68
+ /**
69
+ * the hook to configure the socket channel before it's open
70
+ */
55
71
private SocketChannelConfigurator socketChannelConfigurator = new DefaultSocketChannelConfigurator ();
56
72
57
- /** the hook to configure the SSL engine before the connection is open */
58
- private SslEngineConfigurator sslEngineConfigurator = sslEngine -> { };
73
+ /**
74
+ * the hook to configure the SSL engine before the connection is open
75
+ */
76
+ private SslEngineConfigurator sslEngineConfigurator = sslEngine -> {
77
+ };
59
78
60
- /** the executor service used for connection shutdown */
79
+ /**
80
+ * the executor service used for connection shutdown
81
+ *
82
+ * @since 5.4.0
83
+ */
61
84
private ExecutorService connectionShutdownExecutor ;
62
85
63
86
public NioParams () {
@@ -82,7 +105,7 @@ public int getReadByteBufferSize() {
82
105
/**
83
106
* Sets the size in byte of the read {@link java.nio.ByteBuffer} used in the NIO loop.
84
107
* Default is 32768.
85
- *
108
+ * <p>
86
109
* This parameter isn't used when using SSL/TLS, where {@link java.nio.ByteBuffer}
87
110
* size is set up according to the {@link javax.net.ssl.SSLSession} packet size.
88
111
*
@@ -104,7 +127,7 @@ public int getWriteByteBufferSize() {
104
127
/**
105
128
* Sets the size in byte of the write {@link java.nio.ByteBuffer} used in the NIO loop.
106
129
* Default is 32768.
107
- *
130
+ * <p>
108
131
* This parameter isn't used when using SSL/TLS, where {@link java.nio.ByteBuffer}
109
132
* size is set up according to the {@link javax.net.ssl.SSLSession} packet size.
110
133
*
@@ -131,7 +154,7 @@ public int getNbIoThreads() {
131
154
* 10 connections have been created).
132
155
* Once a connection is created, it's assigned to a thread/task and
133
156
* all its IO activity is handled by this thread/task.
134
- *
157
+ * <p>
135
158
* When idle for a few seconds (i.e. without any connection to perform IO for),
136
159
* a thread/task stops and is recreated if necessary.
137
160
*
@@ -155,14 +178,14 @@ public int getWriteEnqueuingTimeoutInMs() {
155
178
* Every requests to the server is divided into frames
156
179
* that are then queued in a {@link java.util.concurrent.BlockingQueue} before
157
180
* being sent on the network by a IO thread.
158
- *
181
+ * <p>
159
182
* If the IO thread cannot cope with the frames dispatch, the
160
183
* {@link java.util.concurrent.BlockingQueue} gets filled up and blocks
161
184
* (blocking the calling thread by the same occasion). This timeout is the
162
185
* time the {@link java.util.concurrent.BlockingQueue} will wait before
163
186
* rejecting the outbound frame. The calling thread will then received
164
187
* an exception.
165
- *
188
+ * <p>
166
189
* The appropriate value depends on the application scenarios:
167
190
* rate of outbound data (published messages, acknowledgment, etc), network speed...
168
191
*
@@ -182,17 +205,17 @@ public ExecutorService getNioExecutor() {
182
205
/**
183
206
* Sets the {@link ExecutorService} to use for NIO threads/tasks.
184
207
* Default is to use the thread factory.
185
- *
208
+ * <p>
186
209
* The {@link ExecutorService} should be able to run the
187
210
* number of requested IO threads, plus a few more, as it's also
188
211
* used to dispatch the shutdown of connections.
189
- *
212
+ * <p>
190
213
* Connection shutdown can also be handled by a dedicated {@link ExecutorService},
191
214
* see {@link #setConnectionShutdownExecutor(ExecutorService)}.
192
- *
215
+ * <p>
193
216
* It's developer's responsibility to shut down the executor
194
217
* when it is no longer needed.
195
- *
218
+ * <p>
196
219
* The thread factory isn't used if an executor service is set up.
197
220
*
198
221
* @param nioExecutor {@link ExecutorService} used for IO threads and connection shutdown
@@ -214,7 +237,7 @@ public ThreadFactory getThreadFactory() {
214
237
* Sets the {@link ThreadFactory} to use for NIO threads/tasks.
215
238
* Default is to use the {@link com.rabbitmq.client.ConnectionFactory}'s
216
239
* {@link ThreadFactory}.
217
- *
240
+ * <p>
218
241
* The {@link ThreadFactory} is used to spawn the IO threads
219
242
* and dispatch the shutdown of connections.
220
243
*
@@ -248,6 +271,10 @@ public NioParams setWriteQueueCapacity(int writeQueueCapacity) {
248
271
return this ;
249
272
}
250
273
274
+ public SocketChannelConfigurator getSocketChannelConfigurator () {
275
+ return socketChannelConfigurator ;
276
+ }
277
+
251
278
/**
252
279
* Set the {@link java.nio.channels.SocketChannel} configurator.
253
280
* This gets a chance to "configure" a socket channel
@@ -260,8 +287,8 @@ public void setSocketChannelConfigurator(SocketChannelConfigurator configurator)
260
287
this .socketChannelConfigurator = configurator ;
261
288
}
262
289
263
- public SocketChannelConfigurator getSocketChannelConfigurator () {
264
- return socketChannelConfigurator ;
290
+ public SslEngineConfigurator getSslEngineConfigurator () {
291
+ return sslEngineConfigurator ;
265
292
}
266
293
267
294
/**
@@ -277,8 +304,8 @@ public void setSslEngineConfigurator(SslEngineConfigurator configurator) {
277
304
this .sslEngineConfigurator = configurator ;
278
305
}
279
306
280
- public SslEngineConfigurator getSslEngineConfigurator () {
281
- return sslEngineConfigurator ;
307
+ public ExecutorService getConnectionShutdownExecutor () {
308
+ return connectionShutdownExecutor ;
282
309
}
283
310
284
311
/**
@@ -303,13 +330,10 @@ public SslEngineConfigurator getSslEngineConfigurator() {
303
330
* @param connectionShutdownExecutor the executor service to use
304
331
* @return this {@link NioParams} instance
305
332
* @see NioParams#setNioExecutor(ExecutorService)
333
+ * @since 5.4.0
306
334
*/
307
335
public NioParams setConnectionShutdownExecutor (ExecutorService connectionShutdownExecutor ) {
308
336
this .connectionShutdownExecutor = connectionShutdownExecutor ;
309
337
return this ;
310
338
}
311
-
312
- public ExecutorService getConnectionShutdownExecutor () {
313
- return connectionShutdownExecutor ;
314
- }
315
339
}
0 commit comments