1717package org .dataloader ;
1818
1919import org .dataloader .annotations .PublicApi ;
20+ import org .dataloader .instrumentation .DataLoaderInstrumentation ;
21+ import org .dataloader .instrumentation .DataLoaderInstrumentationHelper ;
2022import org .dataloader .scheduler .BatchLoaderScheduler ;
2123import org .dataloader .stats .NoOpStatisticsCollector ;
2224import org .dataloader .stats .StatisticsCollector ;
@@ -52,6 +54,7 @@ public class DataLoaderOptions {
5254 private final BatchLoaderContextProvider environmentProvider ;
5355 private final ValueCacheOptions valueCacheOptions ;
5456 private final BatchLoaderScheduler batchLoaderScheduler ;
57+ private final DataLoaderInstrumentation instrumentation ;
5558
5659 /**
5760 * Creates a new data loader options with default settings.
@@ -68,6 +71,7 @@ public DataLoaderOptions() {
6871 environmentProvider = NULL_PROVIDER ;
6972 valueCacheOptions = DEFAULT_VALUE_CACHE_OPTIONS ;
7073 batchLoaderScheduler = null ;
74+ instrumentation = DataLoaderInstrumentationHelper .NOOP_INSTRUMENTATION ;
7175 }
7276
7377 private DataLoaderOptions (Builder builder ) {
@@ -82,6 +86,7 @@ private DataLoaderOptions(Builder builder) {
8286 this .environmentProvider = builder .environmentProvider ;
8387 this .valueCacheOptions = builder .valueCacheOptions ;
8488 this .batchLoaderScheduler = builder .batchLoaderScheduler ;
89+ this .instrumentation = builder .instrumentation ;
8590 }
8691
8792 /**
@@ -101,7 +106,8 @@ public DataLoaderOptions(DataLoaderOptions other) {
101106 this .statisticsCollector = other .statisticsCollector ;
102107 this .environmentProvider = other .environmentProvider ;
103108 this .valueCacheOptions = other .valueCacheOptions ;
104- batchLoaderScheduler = other .batchLoaderScheduler ;
109+ this .batchLoaderScheduler = other .batchLoaderScheduler ;
110+ this .instrumentation = other .instrumentation ;
105111 }
106112
107113 /**
@@ -169,7 +175,7 @@ public boolean batchingEnabled() {
169175 * Sets the option that determines whether batch loading is enabled.
170176 *
171177 * @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
173179 */
174180 public DataLoaderOptions setBatchingEnabled (boolean batchingEnabled ) {
175181 return builder ().setBatchingEnabled (batchingEnabled ).build ();
@@ -188,7 +194,7 @@ public boolean cachingEnabled() {
188194 * Sets the option that determines whether caching is enabled.
189195 *
190196 * @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
192198 */
193199 public DataLoaderOptions setCachingEnabled (boolean cachingEnabled ) {
194200 return builder ().setCachingEnabled (cachingEnabled ).build ();
@@ -212,7 +218,7 @@ public boolean cachingExceptionsEnabled() {
212218 * Sets the option that determines whether exceptional values are cache enabled.
213219 *
214220 * @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
216222 */
217223 public DataLoaderOptions setCachingExceptionsEnabled (boolean cachingExceptionsEnabled ) {
218224 return builder ().setCachingExceptionsEnabled (cachingExceptionsEnabled ).build ();
@@ -233,7 +239,7 @@ public Optional<CacheKey> cacheKeyFunction() {
233239 * Sets the function to use for creating the cache key, if caching is enabled.
234240 *
235241 * @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
237243 */
238244 public DataLoaderOptions setCacheKeyFunction (CacheKey <?> cacheKeyFunction ) {
239245 return builder ().setCacheKeyFunction (cacheKeyFunction ).build ();
@@ -254,7 +260,7 @@ public DataLoaderOptions setCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
254260 * Sets the cache map implementation to use for caching, if caching is enabled.
255261 *
256262 * @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
258264 */
259265 public DataLoaderOptions setCacheMap (CacheMap <?, ?> cacheMap ) {
260266 return builder ().setCacheMap (cacheMap ).build ();
@@ -275,7 +281,7 @@ public int maxBatchSize() {
275281 * before they are split into multiple class
276282 *
277283 * @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
279285 */
280286 public DataLoaderOptions setMaxBatchSize (int maxBatchSize ) {
281287 return builder ().setMaxBatchSize (maxBatchSize ).build ();
@@ -294,7 +300,7 @@ public StatisticsCollector getStatisticsCollector() {
294300 * a common value
295301 *
296302 * @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
298304 */
299305 public DataLoaderOptions setStatisticsCollector (Supplier <StatisticsCollector > statisticsCollector ) {
300306 return builder ().setStatisticsCollector (nonNull (statisticsCollector )).build ();
@@ -311,7 +317,7 @@ public BatchLoaderContextProvider getBatchLoaderContextProvider() {
311317 * Sets the batch loader environment provider that will be used to give context to batch load functions
312318 *
313319 * @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
315321 */
316322 public DataLoaderOptions setBatchLoaderContextProvider (BatchLoaderContextProvider contextProvider ) {
317323 return builder ().setBatchLoaderContextProvider (nonNull (contextProvider )).build ();
@@ -332,7 +338,7 @@ public DataLoaderOptions setBatchLoaderContextProvider(BatchLoaderContextProvide
332338 * Sets the value cache implementation to use for caching values, if caching is enabled.
333339 *
334340 * @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
336342 */
337343 public DataLoaderOptions setValueCache (ValueCache <?, ?> valueCache ) {
338344 return builder ().setValueCache (valueCache ).build ();
@@ -349,7 +355,7 @@ public ValueCacheOptions getValueCacheOptions() {
349355 * Sets the {@link ValueCacheOptions} that control how the {@link ValueCache} will be used
350356 *
351357 * @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
353359 */
354360 public DataLoaderOptions setValueCacheOptions (ValueCacheOptions valueCacheOptions ) {
355361 return builder ().setValueCacheOptions (nonNull (valueCacheOptions )).build ();
@@ -367,12 +373,29 @@ public BatchLoaderScheduler getBatchLoaderScheduler() {
367373 * to some future time.
368374 *
369375 * @param batchLoaderScheduler the scheduler
370- * @return the data loader options for fluent coding
376+ * @return a new data loader options instance for fluent coding
371377 */
372378 public DataLoaderOptions setBatchLoaderScheduler (BatchLoaderScheduler batchLoaderScheduler ) {
373379 return builder ().setBatchLoaderScheduler (batchLoaderScheduler ).build ();
374380 }
375381
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+
376399 private Builder builder () {
377400 return new Builder (this );
378401 }
@@ -389,6 +412,7 @@ public static class Builder {
389412 private BatchLoaderContextProvider environmentProvider ;
390413 private ValueCacheOptions valueCacheOptions ;
391414 private BatchLoaderScheduler batchLoaderScheduler ;
415+ private DataLoaderInstrumentation instrumentation ;
392416
393417 public Builder () {
394418 this (new DataLoaderOptions ()); // use the defaults of the DataLoaderOptions for this builder
@@ -406,6 +430,7 @@ public Builder() {
406430 this .environmentProvider = other .environmentProvider ;
407431 this .valueCacheOptions = other .valueCacheOptions ;
408432 this .batchLoaderScheduler = other .batchLoaderScheduler ;
433+ this .instrumentation = other .instrumentation ;
409434 }
410435
411436 public Builder setBatchingEnabled (boolean batchingEnabled ) {
@@ -463,6 +488,11 @@ public Builder setBatchLoaderScheduler(BatchLoaderScheduler batchLoaderScheduler
463488 return this ;
464489 }
465490
491+ public Builder setInstrumentation (DataLoaderInstrumentation instrumentation ) {
492+ this .instrumentation = nonNull (instrumentation );
493+ return this ;
494+ }
495+
466496 public DataLoaderOptions build () {
467497 return new DataLoaderOptions (this );
468498 }
0 commit comments