1818
1919import org .dataloader .annotations .PublicApi ;
2020import org .dataloader .impl .Assertions ;
21+ import org .dataloader .instrumentation .DataLoaderInstrumentation ;
22+ import org .dataloader .instrumentation .DataLoaderInstrumentationHelper ;
2123import org .dataloader .scheduler .BatchLoaderScheduler ;
2224import org .dataloader .stats .NoOpStatisticsCollector ;
2325import org .dataloader .stats .StatisticsCollector ;
@@ -48,6 +50,7 @@ public class DataLoaderOptions {
4850 private BatchLoaderContextProvider environmentProvider ;
4951 private ValueCacheOptions valueCacheOptions ;
5052 private BatchLoaderScheduler batchLoaderScheduler ;
53+ private DataLoaderInstrumentation instrumentation ;
5154
5255 /**
5356 * Creates a new data loader options with default settings.
@@ -61,6 +64,7 @@ public DataLoaderOptions() {
6164 environmentProvider = NULL_PROVIDER ;
6265 valueCacheOptions = ValueCacheOptions .newOptions ();
6366 batchLoaderScheduler = null ;
67+ instrumentation = DataLoaderInstrumentationHelper .NOOP_INSTRUMENTATION ;
6468 }
6569
6670 /**
@@ -80,7 +84,8 @@ public DataLoaderOptions(DataLoaderOptions other) {
8084 this .statisticsCollector = other .statisticsCollector ;
8185 this .environmentProvider = other .environmentProvider ;
8286 this .valueCacheOptions = other .valueCacheOptions ;
83- batchLoaderScheduler = other .batchLoaderScheduler ;
87+ this .batchLoaderScheduler = other .batchLoaderScheduler ;
88+ this .instrumentation = other .instrumentation ;
8489 }
8590
8691 /**
@@ -103,7 +108,6 @@ public boolean batchingEnabled() {
103108 * Sets the option that determines whether batch loading is enabled.
104109 *
105110 * @param batchingEnabled {@code true} to enable batch loading, {@code false} otherwise
106- *
107111 * @return the data loader options for fluent coding
108112 */
109113 public DataLoaderOptions setBatchingEnabled (boolean batchingEnabled ) {
@@ -124,7 +128,6 @@ public boolean cachingEnabled() {
124128 * Sets the option that determines whether caching is enabled.
125129 *
126130 * @param cachingEnabled {@code true} to enable caching, {@code false} otherwise
127- *
128131 * @return the data loader options for fluent coding
129132 */
130133 public DataLoaderOptions setCachingEnabled (boolean cachingEnabled ) {
@@ -134,7 +137,7 @@ public DataLoaderOptions setCachingEnabled(boolean cachingEnabled) {
134137
135138 /**
136139 * Option that determines whether to cache exceptional values (the default), or not.
137- *
140+ * <p>
138141 * For short-lived caches (that is request caches) it makes sense to cache exceptions since
139142 * it's likely the key is still poisoned. However, if you have long-lived caches, then it may make
140143 * sense to set this to false since the downstream system may have recovered from its failure
@@ -150,7 +153,6 @@ public boolean cachingExceptionsEnabled() {
150153 * Sets the option that determines whether exceptional values are cache enabled.
151154 *
152155 * @param cachingExceptionsEnabled {@code true} to enable caching exceptional values, {@code false} otherwise
153- *
154156 * @return the data loader options for fluent coding
155157 */
156158 public DataLoaderOptions setCachingExceptionsEnabled (boolean cachingExceptionsEnabled ) {
@@ -173,7 +175,6 @@ public Optional<CacheKey> cacheKeyFunction() {
173175 * Sets the function to use for creating the cache key, if caching is enabled.
174176 *
175177 * @param cacheKeyFunction the cache key function to use
176- *
177178 * @return the data loader options for fluent coding
178179 */
179180 public DataLoaderOptions setCacheKeyFunction (CacheKey <?> cacheKeyFunction ) {
@@ -196,7 +197,6 @@ public DataLoaderOptions setCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
196197 * Sets the cache map implementation to use for caching, if caching is enabled.
197198 *
198199 * @param cacheMap the cache map instance
199- *
200200 * @return the data loader options for fluent coding
201201 */
202202 public DataLoaderOptions setCacheMap (CacheMap <?, ?> cacheMap ) {
@@ -219,7 +219,6 @@ public int maxBatchSize() {
219219 * before they are split into multiple class
220220 *
221221 * @param maxBatchSize the maximum batch size
222- *
223222 * @return the data loader options for fluent coding
224223 */
225224 public DataLoaderOptions setMaxBatchSize (int maxBatchSize ) {
@@ -240,7 +239,6 @@ public StatisticsCollector getStatisticsCollector() {
240239 * a common value
241240 *
242241 * @param statisticsCollector the statistics collector to use
243- *
244242 * @return the data loader options for fluent coding
245243 */
246244 public DataLoaderOptions setStatisticsCollector (Supplier <StatisticsCollector > statisticsCollector ) {
@@ -259,7 +257,6 @@ public BatchLoaderContextProvider getBatchLoaderContextProvider() {
259257 * Sets the batch loader environment provider that will be used to give context to batch load functions
260258 *
261259 * @param contextProvider the batch loader context provider
262- *
263260 * @return the data loader options for fluent coding
264261 */
265262 public DataLoaderOptions setBatchLoaderContextProvider (BatchLoaderContextProvider contextProvider ) {
@@ -282,7 +279,6 @@ public DataLoaderOptions setBatchLoaderContextProvider(BatchLoaderContextProvide
282279 * Sets the value cache implementation to use for caching values, if caching is enabled.
283280 *
284281 * @param valueCache the value cache instance
285- *
286282 * @return the data loader options for fluent coding
287283 */
288284 public DataLoaderOptions setValueCache (ValueCache <?, ?> valueCache ) {
@@ -301,7 +297,6 @@ public ValueCacheOptions getValueCacheOptions() {
301297 * Sets the {@link ValueCacheOptions} that control how the {@link ValueCache} will be used
302298 *
303299 * @param valueCacheOptions the value cache options
304- *
305300 * @return the data loader options for fluent coding
306301 */
307302 public DataLoaderOptions setValueCacheOptions (ValueCacheOptions valueCacheOptions ) {
@@ -321,11 +316,28 @@ public BatchLoaderScheduler getBatchLoaderScheduler() {
321316 * to some future time.
322317 *
323318 * @param batchLoaderScheduler the scheduler
324- *
325319 * @return the data loader options for fluent coding
326320 */
327321 public DataLoaderOptions setBatchLoaderScheduler (BatchLoaderScheduler batchLoaderScheduler ) {
328322 this .batchLoaderScheduler = batchLoaderScheduler ;
329323 return this ;
330324 }
325+
326+ /**
327+ * @return the {@link DataLoaderInstrumentation} to use
328+ */
329+ public DataLoaderInstrumentation getInstrumentation () {
330+ return instrumentation ;
331+ }
332+
333+ /**
334+ * Sets in a new {@link DataLoaderInstrumentation}
335+ *
336+ * @param instrumentation the new {@link DataLoaderInstrumentation}
337+ * @return the data loader options for fluent coding
338+ */
339+ public DataLoaderOptions setInstrumentation (DataLoaderInstrumentation instrumentation ) {
340+ this .instrumentation = nonNull (instrumentation );
341+ return this ;
342+ }
331343}
0 commit comments