Class FileDataSourceBuilder
- java.lang.Object
-
- com.launchdarkly.sdk.server.integrations.FileDataSourceBuilder
-
- All Implemented Interfaces:
DataSourceFactory
public final class FileDataSourceBuilder extends java.lang.Object implements DataSourceFactory
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(DataSourceFactory)
.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.FileDataSourceBuilder
classpathResources(java.lang.String... resourceLocations)
Adds any number of classpath resources for loading flag data.DataSource
createDataSource(ClientContext context, DataSourceUpdates dataSourceUpdates)
Used internally by the LaunchDarkly client.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
-
createDataSource
public DataSource createDataSource(ClientContext context, DataSourceUpdates dataSourceUpdates)
Used internally by the LaunchDarkly client.- Specified by:
createDataSource
in interfaceDataSourceFactory
- Parameters:
context
- allows access to the client configurationdataSourceUpdates
- the component pushes data into the SDK via this interface- Returns:
- an
DataSource
-
-