Class AbstractConfig

  • Direct Known Subclasses:
    AdminClientConfig, ConsumerConfig, ProducerConfig

    public class AbstractConfig
    extends java.lang.Object
    A convenient base class for configurations to extend.

    This class holds both the original configuration that was provided as well as the parsed

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      protected java.lang.Object get​(java.lang.String key)  
      java.lang.Boolean getBoolean​(java.lang.String key)  
      java.lang.Class<?> getClass​(java.lang.String key)  
      <T> T getConfiguredInstance​(java.lang.String key, java.lang.Class<T> t)
      Get a configured instance of the give class specified by the given configuration key.
      <T> java.util.List<T> getConfiguredInstances​(java.lang.String key, java.lang.Class<T> t)
      Get a list of configured instances of the given class specified by the given configuration key.
      <T> java.util.List<T> getConfiguredInstances​(java.lang.String key, java.lang.Class<T> t, java.util.Map<java.lang.String,​java.lang.Object> configOverrides)
      Get a list of configured instances of the given class specified by the given configuration key.
      <T> java.util.List<T> getConfiguredInstances​(java.util.List<java.lang.String> classNames, java.lang.Class<T> t, java.util.Map<java.lang.String,​java.lang.Object> configOverrides)
      Get a list of configured instances of the given class specified by the given configuration key.
      java.lang.Double getDouble​(java.lang.String key)  
      java.lang.Integer getInt​(java.lang.String key)  
      java.util.List<java.lang.String> getList​(java.lang.String key)  
      java.lang.Long getLong​(java.lang.String key)  
      org.apache.kafka.common.config.types.Password getPassword​(java.lang.String key)  
      java.lang.Short getShort​(java.lang.String key)  
      java.lang.String getString​(java.lang.String key)  
      int hashCode()  
      void ignore​(java.lang.String key)  
      void logUnused()
      Log warnings for any unused configurations
      java.util.Map<java.lang.String,​java.lang.Object> originals()  
      java.util.Map<java.lang.String,​java.lang.String> originalsStrings()
      Get all the original settings, ensuring that all values are of type String.
      java.util.Map<java.lang.String,​java.lang.Object> originalsWithPrefix​(java.lang.String prefix)
      Gets all original settings with the given prefix, stripping the prefix before adding it to the output.
      java.util.Map<java.lang.String,​java.lang.Object> originalsWithPrefix​(java.lang.String prefix, boolean strip)
      Gets all original settings with the given prefix.
      protected java.util.Map<java.lang.String,​java.lang.Object> postProcessParsedConfig​(java.util.Map<java.lang.String,​java.lang.Object> parsedValues)
      Called directly after user configs got parsed (and thus default values got set).
      ConfigDef.Type typeOf​(java.lang.String key)  
      java.util.Set<java.lang.String> unused()  
      java.util.Map<java.lang.String,​?> values()  
      java.util.Map<java.lang.String,​java.lang.Object> valuesWithPrefixAllOrNothing​(java.lang.String prefix)
      If at least one key with prefix exists, all prefixed values will be parsed and put into map.
      java.util.Map<java.lang.String,​java.lang.Object> valuesWithPrefixOverride​(java.lang.String prefix)
      Put all keys that do not start with prefix and their parsed values in the result map and then put all the remaining keys with the prefix stripped and their parsed values in the result map.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractConfig

        public AbstractConfig​(ConfigDef definition,
                              java.util.Map<?,​?> originals,
                              boolean doLog)
      • AbstractConfig

        public AbstractConfig​(ConfigDef definition,
                              java.util.Map<?,​?> originals)
    • Method Detail

      • postProcessParsedConfig

        protected java.util.Map<java.lang.String,​java.lang.Object> postProcessParsedConfig​(java.util.Map<java.lang.String,​java.lang.Object> parsedValues)
        Called directly after user configs got parsed (and thus default values got set). This allows to change default values for "secondary defaults" if required.
        Parameters:
        parsedValues - unmodifiable map of current configuration
        Returns:
        a map of updates that should be applied to the configuration (will be validated to prevent bad updates)
      • get

        protected java.lang.Object get​(java.lang.String key)
      • ignore

        public void ignore​(java.lang.String key)
      • getShort

        public java.lang.Short getShort​(java.lang.String key)
      • getInt

        public java.lang.Integer getInt​(java.lang.String key)
      • getLong

        public java.lang.Long getLong​(java.lang.String key)
      • getDouble

        public java.lang.Double getDouble​(java.lang.String key)
      • getList

        public java.util.List<java.lang.String> getList​(java.lang.String key)
      • getBoolean

        public java.lang.Boolean getBoolean​(java.lang.String key)
      • getString

        public java.lang.String getString​(java.lang.String key)
      • getPassword

        public org.apache.kafka.common.config.types.Password getPassword​(java.lang.String key)
      • getClass

        public java.lang.Class<?> getClass​(java.lang.String key)
      • unused

        public java.util.Set<java.lang.String> unused()
      • originals

        public java.util.Map<java.lang.String,​java.lang.Object> originals()
      • originalsStrings

        public java.util.Map<java.lang.String,​java.lang.String> originalsStrings()
        Get all the original settings, ensuring that all values are of type String.
        Returns:
        the original settings
        Throws:
        java.lang.ClassCastException - if any of the values are not strings
      • originalsWithPrefix

        public java.util.Map<java.lang.String,​java.lang.Object> originalsWithPrefix​(java.lang.String prefix)
        Gets all original settings with the given prefix, stripping the prefix before adding it to the output.
        Parameters:
        prefix - the prefix to use as a filter
        Returns:
        a Map containing the settings with the prefix
      • originalsWithPrefix

        public java.util.Map<java.lang.String,​java.lang.Object> originalsWithPrefix​(java.lang.String prefix,
                                                                                          boolean strip)
        Gets all original settings with the given prefix.
        Parameters:
        prefix - the prefix to use as a filter
        strip - strip the prefix before adding to the output if set true
        Returns:
        a Map containing the settings with the prefix
      • valuesWithPrefixOverride

        public java.util.Map<java.lang.String,​java.lang.Object> valuesWithPrefixOverride​(java.lang.String prefix)
        Put all keys that do not start with prefix and their parsed values in the result map and then put all the remaining keys with the prefix stripped and their parsed values in the result map. This is useful if one wants to allow prefixed configs to override default ones.

        Two forms of prefixes are supported:

        • listener.name.{listenerName}.some.prop: If the provided prefix is `listener.name.{listenerName}.`, the key `some.prop` with the value parsed using the definition of `some.prop` is returned.
        • listener.name.{listenerName}.{mechanism}.some.prop: If the provided prefix is `listener.name.{listenerName}.`, the key `{mechanism}.some.prop` with the value parsed using the definition of `some.prop` is returned. This is used to provide per-mechanism configs for a broker listener (e.g sasl.jaas.config)

      • valuesWithPrefixAllOrNothing

        public java.util.Map<java.lang.String,​java.lang.Object> valuesWithPrefixAllOrNothing​(java.lang.String prefix)
        If at least one key with prefix exists, all prefixed values will be parsed and put into map. If no value with prefix exists all unprefixed values will be returned. This is useful if one wants to allow prefixed configs to override default ones, but wants to use either only prefixed configs or only regular configs, but not mix them.
      • values

        public java.util.Map<java.lang.String,​?> values()
      • logUnused

        public void logUnused()
        Log warnings for any unused configurations
      • getConfiguredInstance

        public <T> T getConfiguredInstance​(java.lang.String key,
                                           java.lang.Class<T> t)
        Get a configured instance of the give class specified by the given configuration key. If the object implements Configurable configure it using the configuration.
        Parameters:
        key - The configuration key for the class
        t - The interface the class should implement
        Returns:
        A configured instance of the class
      • getConfiguredInstances

        public <T> java.util.List<T> getConfiguredInstances​(java.lang.String key,
                                                            java.lang.Class<T> t)
        Get a list of configured instances of the given class specified by the given configuration key. The configuration may specify either null or an empty string to indicate no configured instances. In both cases, this method returns an empty list to indicate no configured instances.
        Parameters:
        key - The configuration key for the class
        t - The interface the class should implement
        Returns:
        The list of configured instances
      • getConfiguredInstances

        public <T> java.util.List<T> getConfiguredInstances​(java.lang.String key,
                                                            java.lang.Class<T> t,
                                                            java.util.Map<java.lang.String,​java.lang.Object> configOverrides)
        Get a list of configured instances of the given class specified by the given configuration key. The configuration may specify either null or an empty string to indicate no configured instances. In both cases, this method returns an empty list to indicate no configured instances.
        Parameters:
        key - The configuration key for the class
        t - The interface the class should implement
        configOverrides - Configuration overrides to use.
        Returns:
        The list of configured instances
      • getConfiguredInstances

        public <T> java.util.List<T> getConfiguredInstances​(java.util.List<java.lang.String> classNames,
                                                            java.lang.Class<T> t,
                                                            java.util.Map<java.lang.String,​java.lang.Object> configOverrides)
        Get a list of configured instances of the given class specified by the given configuration key. The configuration may specify either null or an empty string to indicate no configured instances. In both cases, this method returns an empty list to indicate no configured instances.
        Parameters:
        classNames - The list of class names of the instances to create
        t - The interface the class should implement
        configOverrides - Configuration overrides to use.
        Returns:
        The list of configured instances
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object