17
17
package org .dataloader ;
18
18
19
19
import org .dataloader .annotations .PublicApi ;
20
+ import org .dataloader .instrumentation .DataLoaderInstrumentation ;
21
+ import org .dataloader .instrumentation .DataLoaderInstrumentationHelper ;
20
22
import org .dataloader .scheduler .BatchLoaderScheduler ;
21
23
import org .dataloader .stats .NoOpStatisticsCollector ;
22
24
import org .dataloader .stats .StatisticsCollector ;
@@ -52,6 +54,7 @@ public class DataLoaderOptions {
52
54
private final BatchLoaderContextProvider environmentProvider ;
53
55
private final ValueCacheOptions valueCacheOptions ;
54
56
private final BatchLoaderScheduler batchLoaderScheduler ;
57
+ private final DataLoaderInstrumentation instrumentation ;
55
58
56
59
/**
57
60
* Creates a new data loader options with default settings.
@@ -68,6 +71,7 @@ public DataLoaderOptions() {
68
71
environmentProvider = NULL_PROVIDER ;
69
72
valueCacheOptions = DEFAULT_VALUE_CACHE_OPTIONS ;
70
73
batchLoaderScheduler = null ;
74
+ instrumentation = DataLoaderInstrumentationHelper .NOOP_INSTRUMENTATION ;
71
75
}
72
76
73
77
private DataLoaderOptions (Builder builder ) {
@@ -82,6 +86,7 @@ private DataLoaderOptions(Builder builder) {
82
86
this .environmentProvider = builder .environmentProvider ;
83
87
this .valueCacheOptions = builder .valueCacheOptions ;
84
88
this .batchLoaderScheduler = builder .batchLoaderScheduler ;
89
+ this .instrumentation = builder .instrumentation ;
85
90
}
86
91
87
92
/**
@@ -101,7 +106,8 @@ public DataLoaderOptions(DataLoaderOptions other) {
101
106
this .statisticsCollector = other .statisticsCollector ;
102
107
this .environmentProvider = other .environmentProvider ;
103
108
this .valueCacheOptions = other .valueCacheOptions ;
104
- batchLoaderScheduler = other .batchLoaderScheduler ;
109
+ this .batchLoaderScheduler = other .batchLoaderScheduler ;
110
+ this .instrumentation = other .instrumentation ;
105
111
}
106
112
107
113
/**
@@ -169,7 +175,7 @@ public boolean batchingEnabled() {
169
175
* Sets the option that determines whether batch loading is enabled.
170
176
*
171
177
* @param batchingEnabled {@code true} to enable batch loading, {@code false} otherwise
172
- * @return the data loader options for fluent coding
178
+ * @return a new data loader options instance for fluent coding
173
179
*/
174
180
public DataLoaderOptions setBatchingEnabled (boolean batchingEnabled ) {
175
181
return builder ().setBatchingEnabled (batchingEnabled ).build ();
@@ -188,7 +194,7 @@ public boolean cachingEnabled() {
188
194
* Sets the option that determines whether caching is enabled.
189
195
*
190
196
* @param cachingEnabled {@code true} to enable caching, {@code false} otherwise
191
- * @return the data loader options for fluent coding
197
+ * @return a new data loader options instance for fluent coding
192
198
*/
193
199
public DataLoaderOptions setCachingEnabled (boolean cachingEnabled ) {
194
200
return builder ().setCachingEnabled (cachingEnabled ).build ();
@@ -212,7 +218,7 @@ public boolean cachingExceptionsEnabled() {
212
218
* Sets the option that determines whether exceptional values are cache enabled.
213
219
*
214
220
* @param cachingExceptionsEnabled {@code true} to enable caching exceptional values, {@code false} otherwise
215
- * @return the data loader options for fluent coding
221
+ * @return a new data loader options instance for fluent coding
216
222
*/
217
223
public DataLoaderOptions setCachingExceptionsEnabled (boolean cachingExceptionsEnabled ) {
218
224
return builder ().setCachingExceptionsEnabled (cachingExceptionsEnabled ).build ();
@@ -233,7 +239,7 @@ public Optional<CacheKey> cacheKeyFunction() {
233
239
* Sets the function to use for creating the cache key, if caching is enabled.
234
240
*
235
241
* @param cacheKeyFunction the cache key function to use
236
- * @return the data loader options for fluent coding
242
+ * @return a new data loader options instance for fluent coding
237
243
*/
238
244
public DataLoaderOptions setCacheKeyFunction (CacheKey <?> cacheKeyFunction ) {
239
245
return builder ().setCacheKeyFunction (cacheKeyFunction ).build ();
@@ -254,7 +260,7 @@ public DataLoaderOptions setCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
254
260
* Sets the cache map implementation to use for caching, if caching is enabled.
255
261
*
256
262
* @param cacheMap the cache map instance
257
- * @return the data loader options for fluent coding
263
+ * @return a new data loader options instance for fluent coding
258
264
*/
259
265
public DataLoaderOptions setCacheMap (CacheMap <?, ?> cacheMap ) {
260
266
return builder ().setCacheMap (cacheMap ).build ();
@@ -275,7 +281,7 @@ public int maxBatchSize() {
275
281
* before they are split into multiple class
276
282
*
277
283
* @param maxBatchSize the maximum batch size
278
- * @return the data loader options for fluent coding
284
+ * @return a new data loader options instance for fluent coding
279
285
*/
280
286
public DataLoaderOptions setMaxBatchSize (int maxBatchSize ) {
281
287
return builder ().setMaxBatchSize (maxBatchSize ).build ();
@@ -294,7 +300,7 @@ public StatisticsCollector getStatisticsCollector() {
294
300
* a common value
295
301
*
296
302
* @param statisticsCollector the statistics collector to use
297
- * @return the data loader options for fluent coding
303
+ * @return a new data loader options instance for fluent coding
298
304
*/
299
305
public DataLoaderOptions setStatisticsCollector (Supplier <StatisticsCollector > statisticsCollector ) {
300
306
return builder ().setStatisticsCollector (nonNull (statisticsCollector )).build ();
@@ -311,7 +317,7 @@ public BatchLoaderContextProvider getBatchLoaderContextProvider() {
311
317
* Sets the batch loader environment provider that will be used to give context to batch load functions
312
318
*
313
319
* @param contextProvider the batch loader context provider
314
- * @return the data loader options for fluent coding
320
+ * @return a new data loader options instance for fluent coding
315
321
*/
316
322
public DataLoaderOptions setBatchLoaderContextProvider (BatchLoaderContextProvider contextProvider ) {
317
323
return builder ().setBatchLoaderContextProvider (nonNull (contextProvider )).build ();
@@ -332,7 +338,7 @@ public DataLoaderOptions setBatchLoaderContextProvider(BatchLoaderContextProvide
332
338
* Sets the value cache implementation to use for caching values, if caching is enabled.
333
339
*
334
340
* @param valueCache the value cache instance
335
- * @return the data loader options for fluent coding
341
+ * @return a new data loader options instance for fluent coding
336
342
*/
337
343
public DataLoaderOptions setValueCache (ValueCache <?, ?> valueCache ) {
338
344
return builder ().setValueCache (valueCache ).build ();
@@ -349,7 +355,7 @@ public ValueCacheOptions getValueCacheOptions() {
349
355
* Sets the {@link ValueCacheOptions} that control how the {@link ValueCache} will be used
350
356
*
351
357
* @param valueCacheOptions the value cache options
352
- * @return the data loader options for fluent coding
358
+ * @return a new data loader options instance for fluent coding
353
359
*/
354
360
public DataLoaderOptions setValueCacheOptions (ValueCacheOptions valueCacheOptions ) {
355
361
return builder ().setValueCacheOptions (nonNull (valueCacheOptions )).build ();
@@ -367,12 +373,29 @@ public BatchLoaderScheduler getBatchLoaderScheduler() {
367
373
* to some future time.
368
374
*
369
375
* @param batchLoaderScheduler the scheduler
370
- * @return the data loader options for fluent coding
376
+ * @return a new data loader options instance for fluent coding
371
377
*/
372
378
public DataLoaderOptions setBatchLoaderScheduler (BatchLoaderScheduler batchLoaderScheduler ) {
373
379
return builder ().setBatchLoaderScheduler (batchLoaderScheduler ).build ();
374
380
}
375
381
382
+ /**
383
+ * @return the {@link DataLoaderInstrumentation} to use
384
+ */
385
+ public DataLoaderInstrumentation getInstrumentation () {
386
+ return instrumentation ;
387
+ }
388
+
389
+ /**
390
+ * Sets in a new {@link DataLoaderInstrumentation}
391
+ *
392
+ * @param instrumentation the new {@link DataLoaderInstrumentation}
393
+ * @return a new data loader options instance for fluent coding
394
+ */
395
+ public DataLoaderOptions setInstrumentation (DataLoaderInstrumentation instrumentation ) {
396
+ return builder ().setInstrumentation (instrumentation ).build ();
397
+ }
398
+
376
399
private Builder builder () {
377
400
return new Builder (this );
378
401
}
@@ -389,6 +412,7 @@ public static class Builder {
389
412
private BatchLoaderContextProvider environmentProvider ;
390
413
private ValueCacheOptions valueCacheOptions ;
391
414
private BatchLoaderScheduler batchLoaderScheduler ;
415
+ private DataLoaderInstrumentation instrumentation ;
392
416
393
417
public Builder () {
394
418
this (new DataLoaderOptions ()); // use the defaults of the DataLoaderOptions for this builder
@@ -406,6 +430,7 @@ public Builder() {
406
430
this .environmentProvider = other .environmentProvider ;
407
431
this .valueCacheOptions = other .valueCacheOptions ;
408
432
this .batchLoaderScheduler = other .batchLoaderScheduler ;
433
+ this .instrumentation = other .instrumentation ;
409
434
}
410
435
411
436
public Builder setBatchingEnabled (boolean batchingEnabled ) {
@@ -463,6 +488,11 @@ public Builder setBatchLoaderScheduler(BatchLoaderScheduler batchLoaderScheduler
463
488
return this ;
464
489
}
465
490
491
+ public Builder setInstrumentation (DataLoaderInstrumentation instrumentation ) {
492
+ this .instrumentation = nonNull (instrumentation );
493
+ return this ;
494
+ }
495
+
466
496
public DataLoaderOptions build () {
467
497
return new DataLoaderOptions (this );
468
498
}
0 commit comments