Class FileDataSourceBuilder
- java.lang.Object
-
- com.launchdarkly.sdk.server.integrations.FileDataSourceBuilder
-
- All Implemented Interfaces:
ComponentConfigurer<DataSource>
public final class FileDataSourceBuilder extends java.lang.Object implements ComponentConfigurer<DataSource>
To use the file data source, obtain a new instance of this class withFileData.dataSource()
; call the builder methodfilePaths(String...)
to specify file path(s), and/orclasspathResources(String...)
to specify classpath data resources; then pass the resulting object toLDConfig.Builder.dataSource(ComponentConfigurer)
.For more details, see
FileData
.- Since:
- 4.12.0
-
-
Constructor Summary
Constructors Constructor Description FileDataSourceBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileDataSourceBuilder
autoUpdate(boolean autoUpdate)
Specifies whether the data source should watch for changes to the source file(s) and reload flags whenever there is a change.DataSource
build(ClientContext context)
Called internally by the SDK to create an implementation instance.FileDataSourceBuilder
classpathResources(java.lang.String... resourceLocations)
Adds any number of classpath resources for loading flag data.FileDataSourceBuilder
duplicateKeysHandling(FileData.DuplicateKeysHandling duplicateKeysHandling)
Specifies how to handle keys that are duplicated across files.FileDataSourceBuilder
filePaths(java.lang.String... filePaths)
Adds any number of source files for loading flag data, specifying each file path as a string.FileDataSourceBuilder
filePaths(java.nio.file.Path... filePaths)
Adds any number of source files for loading flag data, specifying each file path as a Path.
-
-
-
Method Detail
-
filePaths
public FileDataSourceBuilder filePaths(java.lang.String... filePaths) throws java.nio.file.InvalidPathException
Adds any number of source files for loading flag data, specifying each file path as a string. The files will not actually be loaded until the LaunchDarkly client starts up.Files will be parsed as JSON if their first non-whitespace character is '{'. Otherwise, they will be parsed as YAML.
- Parameters:
filePaths
- path(s) to the source file(s); may be absolute or relative to the current working directory- Returns:
- the same factory object
- Throws:
java.nio.file.InvalidPathException
- if one of the parameters is not a valid file path
-
filePaths
public FileDataSourceBuilder filePaths(java.nio.file.Path... filePaths)
Adds any number of source files for loading flag data, specifying each file path as a Path. The files will not actually be loaded until the LaunchDarkly client starts up.Files will be parsed as JSON if their first non-whitespace character is '{'. Otherwise, they will be parsed as YAML.
- Parameters:
filePaths
- path(s) to the source file(s); may be absolute or relative to the current working directory- Returns:
- the same factory object
-
classpathResources
public FileDataSourceBuilder classpathResources(java.lang.String... resourceLocations)
Adds any number of classpath resources for loading flag data. The resources will not actually be loaded until the LaunchDarkly client starts up.Files will be parsed as JSON if their first non-whitespace character is '{'. Otherwise, they will be parsed as YAML.
- Parameters:
resourceLocations
- resource location(s) in the format used byClassLoader.getResource()
; these are absolute paths, so for instance a resource called "data.json" in the package "com.mypackage" would have the location "/com/mypackage/data.json"- Returns:
- the same factory object
-
autoUpdate
public FileDataSourceBuilder autoUpdate(boolean autoUpdate)
Specifies whether the data source should watch for changes to the source file(s) and reload flags whenever there is a change. By default, it will not, so the flags will only be loaded once. This feature only works with real files, not withclasspathResources(String...)
.Note that auto-updating will only work if all of the files you specified have valid directory paths at startup time; if a directory does not exist, creating it later will not result in files being loaded from it.
The performance of this feature depends on what implementation of
java.nio.file.WatchService
is available in the Java runtime. On Linux and Windows, an implementation based on native filesystem APIs should be available. On MacOS, there is a long-standing known issue where due to the lack of such an implementation, it must use a file polling approach that can take up to 10 seconds to detect a change.- Parameters:
autoUpdate
- true if flags should be reloaded whenever a source file changes- Returns:
- the same factory object
-
duplicateKeysHandling
public FileDataSourceBuilder duplicateKeysHandling(FileData.DuplicateKeysHandling duplicateKeysHandling)
Specifies how to handle keys that are duplicated across files.By default, data loading will fail if keys are duplicated across files (
FileData.DuplicateKeysHandling.FAIL
).- Parameters:
duplicateKeysHandling
- specifies how to handle duplicate keys- Returns:
- the same factory object
- Since:
- 5.3.0
-
build
public DataSource build(ClientContext context)
Description copied from interface:ComponentConfigurer
Called internally by the SDK to create an implementation instance. Applications should not need to call this method.- Specified by:
build
in interfaceComponentConfigurer<DataSource>
- Parameters:
context
- provides configuration properties and other components from the current SDK client instance- Returns:
- a instance of the component type
-
-