public final class FileDataSourceBuilder extends java.lang.Object implements DataSourceFactory
FileData.dataSource()
;
call the builder method filePaths(String...)
to specify file path(s), and/or
classpathResources(String...)
to specify classpath data resources; then pass the resulting
object to LDConfig.Builder.dataSource(DataSourceFactory)
.
For more details, see FileData
.
Constructor and Description |
---|
FileDataSourceBuilder() |
Modifier and Type | Method and 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 |
filePaths(java.nio.file.Path... filePaths)
Adds any number of source files for loading flag data, specifying each file path as a Path.
|
FileDataSourceBuilder |
filePaths(java.lang.String... filePaths)
Adds any number of source files for loading flag data, specifying each file path as a string.
|
public FileDataSourceBuilder filePaths(java.lang.String... filePaths) throws java.nio.file.InvalidPathException
Files will be parsed as JSON if their first non-whitespace character is '{'. Otherwise, they will be parsed as YAML.
filePaths
- path(s) to the source file(s); may be absolute or relative to the current working directoryjava.nio.file.InvalidPathException
- if one of the parameters is not a valid file pathpublic FileDataSourceBuilder filePaths(java.nio.file.Path... filePaths)
Files will be parsed as JSON if their first non-whitespace character is '{'. Otherwise, they will be parsed as YAML.
filePaths
- path(s) to the source file(s); may be absolute or relative to the current working directorypublic FileDataSourceBuilder classpathResources(java.lang.String... resourceLocations)
Files will be parsed as JSON if their first non-whitespace character is '{'. Otherwise, they will be parsed as YAML.
resourceLocations
- resource location(s) in the format used by ClassLoader.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"public FileDataSourceBuilder autoUpdate(boolean autoUpdate)
classpathResources(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.
autoUpdate
- true if flags should be reloaded whenever a source file changespublic DataSource createDataSource(ClientContext context, DataSourceUpdates dataSourceUpdates)
createDataSource
in interface DataSourceFactory
context
- allows access to the client configurationdataSourceUpdates
- the component pushes data into the SDK via this interfaceDataSource