Class Settings

  • All Implemented Interfaces:
    ISettings

    public class Settings
    extends Object
    implements ISettings
    A service that handles the general config of the deep agent.
    • Method Detail

      • build

        public static Settings build​(Map<String,​String> agentArgs)
        Build a new settings service from the input arguments from the agent.
        Parameters:
        agentArgs - the agent input arguments
        Returns:
        the new settings service
      • coerc

        public static <T> T coerc​(String str,
                                  Class<T> type)
        Coerce a value into a given type.
        Type Parameters:
        T - the type to return as
        Parameters:
        str - the value to coerce
        type - the type to change to
        Returns:
        the value as the given type, or null
      • getSettingAs

        public <T> T getSettingAs​(String key,
                                  Class<T> clazz)
        Description copied from interface: ISettings
        Get a setting from the config as a given type.

        When reading a config value, deep will scan the config file, system properties and environment variables. We will read the values in order:

        • Environment Variables
        • System Property
        • Config Value
        So a value read from environment variables will override values given as system properties.

        When we read a value we will scope the keys to suit the place from which we are reading. This means that if we are looking for 'service.name' we will use the following keys:

        • DEEP_SERVICE_NAME - When looking in Environment variables we uppercase and use underscores
        • deep.service.name - When looking in System Properties we lowercase and use dots
        • service.name - When looking in config file we use the normalised value
        The key provided should be the normalized key.
        Specified by:
        getSettingAs in interface ISettings
        Type Parameters:
        T - the type to return as
        Parameters:
        key - the key for the setting
        clazz - the type to return as
        Returns:
        the value as the given type
      • getMap

        public Map<String,​String> getMap​(String key)
        Description copied from interface: ISettings
        Get the property as a map.
        Specified by:
        getMap in interface ISettings
        Parameters:
        key - the for the setting
        Returns:
        the value as a map
      • getServiceHost

        public String getServiceHost()
        Get the deep service host name.
        Returns:
        the service host name
        Throws:
        Settings.InvalidConfigException - if the value cannot be obtained
      • getServicePort

        public int getServicePort()
        Get the deep service port number.
        Returns:
        the service port number
        Throws:
        Settings.InvalidConfigException - if the value cannot be obtained
      • setResource

        public void setResource​(Resource resource)
        Get the resource value for this agent.
        Parameters:
        resource - the resource that describes this agent
      • getAsList

        public List<String> getAsList​(String key)
        Get the value as a list.
        Specified by:
        getAsList in interface ISettings
        Parameters:
        key - the key for the setting
        Returns:
        the value as a list
      • getPluginByName

        public <T> T getPluginByName​(Class<T> clazz,
                                     String name)
        Get the plugin that is on the provided type and has the given name.
        Type Parameters:
        T - the type of the plugin
        Parameters:
        clazz - the type of the plugin to match
        name - the class name of the plugin to match
        Returns:
        the discovered plugin with the given name, or null if a plugin with the provided name and type cannot be found.
      • getPlugins

        public Collection<IDeepPlugin> getPlugins()
        Get all configured plugins.
        Returns:
        the full list on plugins
      • getPlugins

        public <T> Collection<T> getPlugins​(Class<T> target)
        Get all plugins of the provided type.
        Type Parameters:
        T - the type of the plugin
        Parameters:
        target - the type of plugin we want
        Returns:
        the list of plugins
      • setPlugins

        public void setPlugins​(Collection<IDeepPlugin> plugins)
        Set configured plugins.
        Parameters:
        plugins - the plugins to use
      • isActive

        public boolean isActive()
        Is deep currently active.
        Returns:
        true if deep is active, else false
      • setActive

        public void setActive​(boolean state)
        Allows enabling or disabled deep.

        A disabled deep will remove installed tracepoints and stop polling. It will not remove itself.

        Parameters:
        state - the new state
      • logTracepoint

        public void logTracepoint​(String logMsg,
                                  String tracepointId,
                                  String snapshotId)
        Log the tracepoint log via the configured logger.
        Parameters:
        logMsg - the log message
        tracepointId - the tracepoint id
        snapshotId - the snapshot id
      • getTracepointLogger

        public ITracepointLogger getTracepointLogger()
        Get the current tracepoint logger.
        Returns:
        the tracepoint logger
      • addPlugin

        public IRegistration<IDeepPlugin> addPlugin​(IDeepPlugin plugin)
        Add a plugin to the current config.
        Parameters:
        plugin - the new plugin
        Returns:
        the plugin registration
      • getPlugin

        public <T> T getPlugin​(Class<T> clazz)
        Get the first plugin that matches the given type.
        Type Parameters:
        T - the plugin type
        Parameters:
        clazz - the type of plugin we need
        Returns:
        the discovered plugin or null if we couldn't find a plugin of this type.