Class ConfigurationLoader

  • All Implemented Interfaces:
    java.lang.Runnable

    
    public final class ConfigurationLoader
    extends HandlerThread
                        

    The main entry point, responsible for configuration retrieval, provider processing, retries, input and error callbacks. It attempts to retrieve configuration data from the queue of providers and returns the configuration data from the first successful provider.

    By default, the initial queue contents are:

    During execution of loadConfiguration, each provider is queried for configuration data. If data is successfully retrieved, it is persisted using the specified persistConfiguration method and the onCompletion handler is called with the provider-id and success. The first provider encountered that requires input will cause the ConfigurationLoader to build a list of all of the providers that expect input and call the onInputRequired handler. Input is returned to the loader by calling processRequestedInputs and will be provided to the associated provider. The provider will then return the successful configuration data retrieved or call the onError handler (allowing new input processing). If an empty or null input is provided, all providers that expect input will be skipped. Therefore, if none of the remaining non-input expected providers successfully retrieve configuration data, the ConfigurationLoader will call the onCompletion handler with a null provider id and unsuccessful.

    Users can override the default queue of providers by creating a ConfigurationLoader and adding the provider(s) of interest. Custom providers provide extensibility

    • Constructor Detail

      • ConfigurationLoader

        ConfigurationLoader(Context context, ConfigurationLoaderCallback callback, Array<ConfigurationProvider> providers)
        Create the loader, assign the Notification callback handlers and override the default provider queue.
        Parameters:
        context - An android Context providing access to the resources
        callback - A notification .ConfigurationLoaderCallback callback
        providers - An array of .ConfigurationProvider ConfigurationProviders
      • ConfigurationLoader

        ConfigurationLoader(Context context, ConfigurationLoaderCallback callback, Array<ConfigurationProvider> providers, UserInputs userInputs)
        Create the loader, assign the Notification callback handlers and override the default provider queue.
        Parameters:
        context - An android Context providing access to the resources
        callback - A notification .ConfigurationLoaderCallback callback
        providers - An array of .ConfigurationProvider ConfigurationProviders
        userInputs - Provide an initial set of userInput values
      • ConfigurationLoader

        ConfigurationLoader(Context context, ConfigurationLoaderCallback callback, ConfigurationPersister persistenceMethod)
        Create the loader, assign the Notification callback handlers and assign the method responsible for persisting the configuration data.
        Parameters:
        context - An android Context providing access to the resources
        callback - A notification .ConfigurationLoaderCallback callback
        persistenceMethod - A persistenceMethod that stores the configuration data
      • ConfigurationLoader

        ConfigurationLoader(Context context, String applicationId, ConfigurationLoaderCallback callback, ConfigurationPersister persistenceMethod)
        Create the loader, assign the Notification callback handlers and assign the method responsible for persisting the configuration data.
        Parameters:
        context - An android Context providing access to the resources
        applicationId - An Application Id to be used by the Discovery Service Provider.
        callback - A notification .ConfigurationLoaderCallback callback
        persistenceMethod - A persistenceMethod that stores the configuration data
      • ConfigurationLoader

        ConfigurationLoader(Context context, ConfigurationLoaderCallback callback, ConfigurationPersister persistenceMethod, UserInputs userInputs)
        Create the loader, assign the Notification callback handlers and assign the method responsible for persisting the configuration data.
        Parameters:
        context - An android Context providing access to the resources
        callback - A notification .ConfigurationLoaderCallback callback
        persistenceMethod - A persistenceMethod that stores the configuration data
        userInputs - Provide an initial set of UserInput values
      • ConfigurationLoader

        ConfigurationLoader(Context context, String applicationId, ConfigurationLoaderCallback callback, ConfigurationPersister persistenceMethod, UserInputs userInputs)
        Create the loader, assign the Notification callback handlers and assign the method responsible for persisting the configuration data.
        Parameters:
        context - An android Context providing access to the resources
        applicationId - An Application Id to be used by the Discovery Service Provider.
        callback - A notification .ConfigurationLoaderCallback callback
        persistenceMethod - A persistenceMethod that stores the configuration data
        userInputs - Provide an initial set of UserInput values
      • ConfigurationLoader

        ConfigurationLoader(ConfigurationLoaderCallback callback, Array<ConfigurationProvider> providers, ConfigurationPersister persistenceMethod)
        Create the loader, assign the Notification callback, override the default provider queue and assign the method responsible for persisting the configuration data
        Parameters:
        callback - A .ConfigurationLoaderCallback callback
        providers - An array of .ConfigurationProvider ConfigurationProviders
        persistenceMethod - A persistenceMethod that stores the configuration data
      • ConfigurationLoader

        ConfigurationLoader(ConfigurationLoaderCallback callback, Array<ConfigurationProvider> providers, ConfigurationPersister persistenceMethod, UserInputs userInputs)
        Create the loader, assign the Notification callback, override the default provider queue and assign the method responsible for persisting the configuration data
        Parameters:
        callback - A .ConfigurationLoaderCallback callback
        providers - An array of .ConfigurationProvider ConfigurationProviders
        persistenceMethod - A persistenceMethod that stores the configuration data
        userInputs - Provide an initial set of UserInput values
    • Method Detail

      • loadConfiguration

         boolean loadConfiguration()

        Starts a thread which will attempt to retrieve the configuration data from the queue of providers and store it using the designated persistence method. The returned configuration data will be from the first queries provider that returns data. If no provider is successful, then the thread terminates with failure. The OnCompletion callback will be invoked, indicating success or failure immediately before the thread terminates. The other callbacks, onInputRequired and onError, will be invoked when the first provider that needs input is tried and when an input required provider encounters an error, respectively.

        Returns:

        true if the thread was started and false if the thread was already running.

      • processRequestedInputs

         boolean processRequestedInputs(@NonNull() UserInputs requestedInputs)

        Provides user inputs to the load configuration thread so that it can continue processing. This method must be called in response to the onInputRequired and onError callback method invocations. If this is not called after either of these methods are invoked, the loadConfiguration method will not complete and the load configuration thread will run indefinitely.

        Parameters:
        requestedInputs - A UserInputs object.
        Returns:

        true if the load configuration thread is running and the inputs were successfully handed to it, false otherwise. Will return false if loadConfiguration() was not called prior to this or has already completed or if the message could not be queued.