Class FileDataSourceBuilder

    • Constructor Detail

      • FileDataSourceBuilder

        public FileDataSourceBuilder()
    • 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 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"
        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 with 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.

        Parameters:
        autoUpdate - true if flags should be reloaded whenever a source file changes
        Returns:
        the same factory object
      • 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 interface ComponentConfigurer<DataSource>
        Parameters:
        context - provides configuration properties and other components from the current SDK client instance
        Returns:
        a instance of the component type