Package org.dataloader
Class DataLoaderOptions
- java.lang.Object
-
- org.dataloader.DataLoaderOptions
-
@PublicApi public class DataLoaderOptions extends java.lang.Object
Configuration options forDataLoader
instances. This is an immutable class so each time you change a value it returns a new object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataLoaderOptions.Builder
-
Constructor Summary
Constructors Constructor Description DataLoaderOptions()
Creates a new data loader options with default settings.DataLoaderOptions(DataLoaderOptions other)
Clones the provided data loader options.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
batchingEnabled()
Option that determines whether to use batching (the default), or not.java.util.Optional<CacheKey>
cacheKeyFunction()
Gets an (optional) function to invoke for creation of the cache key, if caching is enabled.java.util.Optional<CacheMap<?,?>>
cacheMap()
Gets the (optional) cache map implementation that is used for caching, if caching is enabled.boolean
cachingEnabled()
Option that determines whether to use caching of futures (the default), or not.boolean
cachingExceptionsEnabled()
Option that determines whether to cache exceptional values (the default), or not.boolean
equals(java.lang.Object o)
BatchLoaderContextProvider
getBatchLoaderContextProvider()
BatchLoaderScheduler
getBatchLoaderScheduler()
DataLoaderInstrumentation
getInstrumentation()
StatisticsCollector
getStatisticsCollector()
ValueCacheOptions
getValueCacheOptions()
int
maxBatchSize()
Gets the maximum number of keys that will be presented to theBatchLoader
function before they are split into multiple classstatic DataLoaderOptions.Builder
newDataLoaderOptions(DataLoaderOptions otherOptions)
static DataLoaderOptions
newOptions()
static DataLoaderOptions.Builder
newOptionsBuilder()
DataLoaderOptions
setBatchingEnabled(boolean batchingEnabled)
Sets the option that determines whether batch loading is enabled.DataLoaderOptions
setBatchLoaderContextProvider(BatchLoaderContextProvider contextProvider)
Sets the batch loader environment provider that will be used to give context to batch load functionsDataLoaderOptions
setBatchLoaderScheduler(BatchLoaderScheduler batchLoaderScheduler)
Sets in a newBatchLoaderScheduler
that allows the call to aBatchLoader
function to be scheduled to some future time.DataLoaderOptions
setCacheKeyFunction(CacheKey<?> cacheKeyFunction)
Sets the function to use for creating the cache key, if caching is enabled.DataLoaderOptions
setCacheMap(CacheMap<?,?> cacheMap)
Sets the cache map implementation to use for caching, if caching is enabled.DataLoaderOptions
setCachingEnabled(boolean cachingEnabled)
Sets the option that determines whether caching is enabled.DataLoaderOptions
setCachingExceptionsEnabled(boolean cachingExceptionsEnabled)
Sets the option that determines whether exceptional values are cache enabled.DataLoaderOptions
setInstrumentation(DataLoaderInstrumentation instrumentation)
Sets in a newDataLoaderInstrumentation
DataLoaderOptions
setMaxBatchSize(int maxBatchSize)
Sets the maximum number of keys that will be presented to theBatchLoader
function before they are split into multiple classDataLoaderOptions
setStatisticsCollector(java.util.function.Supplier<StatisticsCollector> statisticsCollector)
Sets the statistics collector supplier that will be used with these data loader options.DataLoaderOptions
setValueCache(ValueCache<?,?> valueCache)
Sets the value cache implementation to use for caching values, if caching is enabled.DataLoaderOptions
setValueCacheOptions(ValueCacheOptions valueCacheOptions)
Sets theValueCacheOptions
that control how theValueCache
will be usedDataLoaderOptions
transform(java.util.function.Consumer<DataLoaderOptions.Builder> builderConsumer)
Will transform the current options in to a builder ands allow you to build a new set of optionsjava.util.Optional<ValueCache<?,?>>
valueCache()
Gets the (optional) cache store implementation that is used for value caching, if caching is enabled.
-
-
-
Constructor Detail
-
DataLoaderOptions
public DataLoaderOptions()
Creates a new data loader options with default settings.
-
DataLoaderOptions
public DataLoaderOptions(DataLoaderOptions other)
Clones the provided data loader options.- Parameters:
other
- the other options instance
-
-
Method Detail
-
newOptions
public static DataLoaderOptions newOptions()
- Returns:
- a new default data loader options that you can then customize
-
newOptionsBuilder
public static DataLoaderOptions.Builder newOptionsBuilder()
- Returns:
- a new default data loader options
DataLoaderOptions.Builder
that you can then customize
-
newDataLoaderOptions
public static DataLoaderOptions.Builder newDataLoaderOptions(DataLoaderOptions otherOptions)
- Parameters:
otherOptions
- the options to copy- Returns:
- a new default data loader options
DataLoaderOptions.Builder
from the specified one that you can then customize
-
transform
public DataLoaderOptions transform(java.util.function.Consumer<DataLoaderOptions.Builder> builderConsumer)
Will transform the current options in to a builder ands allow you to build a new set of options- Parameters:
builderConsumer
- the consumer of a builder that has this objects starting values- Returns:
- a new
DataLoaderOptions
object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
batchingEnabled
public boolean batchingEnabled()
Option that determines whether to use batching (the default), or not.- Returns:
true
when batching is enabled,false
otherwise
-
setBatchingEnabled
public DataLoaderOptions setBatchingEnabled(boolean batchingEnabled)
Sets the option that determines whether batch loading is enabled.- Parameters:
batchingEnabled
-true
to enable batch loading,false
otherwise- Returns:
- a new data loader options instance for fluent coding
-
cachingEnabled
public boolean cachingEnabled()
Option that determines whether to use caching of futures (the default), or not.- Returns:
true
when caching is enabled,false
otherwise
-
setCachingEnabled
public DataLoaderOptions setCachingEnabled(boolean cachingEnabled)
Sets the option that determines whether caching is enabled.- Parameters:
cachingEnabled
-true
to enable caching,false
otherwise- Returns:
- a new data loader options instance for fluent coding
-
cachingExceptionsEnabled
public boolean cachingExceptionsEnabled()
Option that determines whether to cache exceptional values (the default), or not.For short-lived caches (that is request caches) it makes sense to cache exceptions since it's likely the key is still poisoned. However, if you have long-lived caches, then it may make sense to set this to false since the downstream system may have recovered from its failure mode.
- Returns:
true
when exceptional values are cached is enabled,false
otherwise
-
setCachingExceptionsEnabled
public DataLoaderOptions setCachingExceptionsEnabled(boolean cachingExceptionsEnabled)
Sets the option that determines whether exceptional values are cache enabled.- Parameters:
cachingExceptionsEnabled
-true
to enable caching exceptional values,false
otherwise- Returns:
- a new data loader options instance for fluent coding
-
cacheKeyFunction
public java.util.Optional<CacheKey> cacheKeyFunction()
Gets an (optional) function to invoke for creation of the cache key, if caching is enabled.If missing the cache key defaults to the
key
type parameter of the data loader of typeK
.- Returns:
- an optional with the function, or empty optional
-
setCacheKeyFunction
public DataLoaderOptions setCacheKeyFunction(CacheKey<?> cacheKeyFunction)
Sets the function to use for creating the cache key, if caching is enabled.- Parameters:
cacheKeyFunction
- the cache key function to use- Returns:
- a new data loader options instance for fluent coding
-
cacheMap
public java.util.Optional<CacheMap<?,?>> cacheMap()
Gets the (optional) cache map implementation that is used for caching, if caching is enabled.If missing a standard
LinkedHashMap
will be used as the cache implementation.- Returns:
- an optional with the cache map instance, or empty
-
setCacheMap
public DataLoaderOptions setCacheMap(CacheMap<?,?> cacheMap)
Sets the cache map implementation to use for caching, if caching is enabled.- Parameters:
cacheMap
- the cache map instance- Returns:
- a new data loader options instance for fluent coding
-
maxBatchSize
public int maxBatchSize()
Gets the maximum number of keys that will be presented to theBatchLoader
function before they are split into multiple class- Returns:
- the maximum batch size or -1 if there is no limit
-
setMaxBatchSize
public DataLoaderOptions setMaxBatchSize(int maxBatchSize)
Sets the maximum number of keys that will be presented to theBatchLoader
function before they are split into multiple class- Parameters:
maxBatchSize
- the maximum batch size- Returns:
- a new data loader options instance for fluent coding
-
getStatisticsCollector
public StatisticsCollector getStatisticsCollector()
- Returns:
- the statistics collector to use with these options
-
setStatisticsCollector
public DataLoaderOptions setStatisticsCollector(java.util.function.Supplier<StatisticsCollector> statisticsCollector)
Sets the statistics collector supplier that will be used with these data loader options. Since it uses the supplier pattern, you can create a new statistics collector on each call, or you can reuse a common value- Parameters:
statisticsCollector
- the statistics collector to use- Returns:
- a new data loader options instance for fluent coding
-
getBatchLoaderContextProvider
public BatchLoaderContextProvider getBatchLoaderContextProvider()
- Returns:
- the batch environment provider that will be used to give context to batch load functions
-
setBatchLoaderContextProvider
public DataLoaderOptions setBatchLoaderContextProvider(BatchLoaderContextProvider contextProvider)
Sets the batch loader environment provider that will be used to give context to batch load functions- Parameters:
contextProvider
- the batch loader context provider- Returns:
- a new data loader options instance for fluent coding
-
valueCache
public java.util.Optional<ValueCache<?,?>> valueCache()
Gets the (optional) cache store implementation that is used for value caching, if caching is enabled.If missing, a no-op implementation will be used.
- Returns:
- an optional with the cache store instance, or empty
-
setValueCache
public DataLoaderOptions setValueCache(ValueCache<?,?> valueCache)
Sets the value cache implementation to use for caching values, if caching is enabled.- Parameters:
valueCache
- the value cache instance- Returns:
- a new data loader options instance for fluent coding
-
getValueCacheOptions
public ValueCacheOptions getValueCacheOptions()
- Returns:
- the
ValueCacheOptions
that control how theValueCache
will be used
-
setValueCacheOptions
public DataLoaderOptions setValueCacheOptions(ValueCacheOptions valueCacheOptions)
Sets theValueCacheOptions
that control how theValueCache
will be used- Parameters:
valueCacheOptions
- the value cache options- Returns:
- a new data loader options instance for fluent coding
-
getBatchLoaderScheduler
public BatchLoaderScheduler getBatchLoaderScheduler()
- Returns:
- the
BatchLoaderScheduler
to use, which can be null
-
setBatchLoaderScheduler
public DataLoaderOptions setBatchLoaderScheduler(BatchLoaderScheduler batchLoaderScheduler)
Sets in a newBatchLoaderScheduler
that allows the call to aBatchLoader
function to be scheduled to some future time.- Parameters:
batchLoaderScheduler
- the scheduler- Returns:
- a new data loader options instance for fluent coding
-
getInstrumentation
public DataLoaderInstrumentation getInstrumentation()
- Returns:
- the
DataLoaderInstrumentation
to use
-
setInstrumentation
public DataLoaderOptions setInstrumentation(DataLoaderInstrumentation instrumentation)
Sets in a newDataLoaderInstrumentation
- Parameters:
instrumentation
- the newDataLoaderInstrumentation
- Returns:
- a new data loader options instance for fluent coding
-
-