Class SettingsAgent

  • All Implemented Interfaces:
    ISettingsService

    public class SettingsAgent
    extends java.lang.Object
    implements ISettingsService
    Agent that provides the settings service.
    • Field Detail

      • settingsdir

        protected java.io.File settingsdir
        Directory used to save settings.
      • filename

        protected java.lang.String filename
        The properties filename.
      • props

        protected Properties props
        The current properties.
      • providers

        protected java.util.Map<java.lang.String,​IPropertiesProvider> providers
        The registered properties provider (id->provider).
      • saveonexit

        protected boolean saveonexit
        Save settings on exit?.
      • readonly

        protected boolean readonly
        Do not save settings?.
    • Constructor Detail

      • SettingsAgent

        public SettingsAgent()
    • Method Detail

      • startService

        public IFuture<java.lang.Void> startService()
        Start the service.
        Returns:
        A future that is done when the service has completed starting.
      • shutdownService

        public IFuture<java.lang.Void> shutdownService()
        Shutdown the service.
        Returns:
        A future that is done when the service has completed its shutdown.
      • registerPropertiesProvider

        public IFuture<java.lang.Void> registerPropertiesProvider​(java.lang.String id,
                                                                  IPropertiesProvider provider)
        Register a property provider. Settings of registered property providers will be automatically saved and restored, when properties are loaded.
        Specified by:
        registerPropertiesProvider in interface ISettingsService
        Parameters:
        id - A unique id to identify the properties (e.g. component or service name).
        provider - The properties provider.
        Returns:
        A future indicating when registration is finished.
      • deregisterPropertiesProvider

        public IFuture<java.lang.Void> deregisterPropertiesProvider​(java.lang.String id)
        Deregister a property provider. Settings of a deregistered property provider will be saved before the property provider is removed.
        Specified by:
        deregisterPropertiesProvider in interface ISettingsService
        Parameters:
        id - A unique id to identify the properties (e.g. component or service name).
        Returns:
        A future indicating when registration is finished.
      • setProperties

        public IFuture<java.lang.Void> setProperties​(java.lang.String id,
                                                     Properties props)
        Set the properties for a given id. Overwrites existing settings (if any).
        Specified by:
        setProperties in interface ISettingsService
        Parameters:
        id - A unique id to identify the properties (e.g. component or service name).
        properties - The properties to set.
        save - Save platform properties after setting.
        Returns:
        A future indicating when properties have been set.
      • getProperties

        public IFuture<Properties> getProperties​(java.lang.String id)
        Get the properties for a given id.
        Specified by:
        getProperties in interface ISettingsService
        Parameters:
        id - A unique id to identify the properties (e.g. component or service name).
        Returns:
        A future containing the properties (if any).
      • loadProperties

        public IFuture<java.lang.Void> loadProperties()
        Load the default platform properties.
        Specified by:
        loadProperties in interface ISettingsService
        Returns:
        A future indicating when properties have been loaded.
      • readPropertiesFromStore

        protected IFuture<Properties> readPropertiesFromStore()
        Reads and returns the stored Properties, usually from a file.
        Returns:
        Properties
        Throws:
        java.io.FileNotFoundException
        java.lang.Exception
        java.io.IOException
      • saveProperties

        public IFuture<java.lang.Void> saveProperties()
        Save the platform properties to the default location.
        Specified by:
        saveProperties in interface ISettingsService
        Returns:
        A future indicating when properties have been saved.
      • saveProperties

        public IFuture<java.lang.Void> saveProperties​(boolean shutdown)
        Save the platform properties to the default location.
        Parameters:
        shutdown - Flag indicating if called during shutdown.
        Returns:
        A future indicating when properties have been saved.
      • setSaveOnExit

        public IFuture<java.lang.Void> setSaveOnExit​(boolean saveonexit)
        Set the save on exit policy.
        Specified by:
        setSaveOnExit in interface ISettingsService
        Parameters:
        saveonexit - The saveonexit flag.
      • writePropertiesToStore

        protected IFuture<java.lang.Void> writePropertiesToStore​(Properties props)
        Writes the given properties into a Store, usually a file.
        Throws:
        java.io.FileNotFoundException
        java.lang.Exception
        java.io.IOException