Interface DynamicConfiguration

All Superinterfaces:
AutoCloseable, Configuration
All Known Implementing Classes:
AbstractDynamicConfiguration, CompositeDynamicConfiguration, NopDynamicConfiguration, TreePathDynamicConfiguration

public interface DynamicConfiguration extends Configuration, AutoCloseable
Dynamic Configuration
From the use scenario internally inside framework, there are mainly three kinds of methods:
  1. getProperties(String, String, long), get configuration file from Config Center at start up.
  2. addListener(String, String, ConfigurationListener)/ removeListener(String, String, ConfigurationListener) , add or remove listeners for governance rules or config items that need to watch.
  3. Configuration.getProperty(String, Object), get a single config item.
  4. getConfig(String, String, long), get the specified config
See Also:
  • Field Details

  • Method Details

    • addListener

      default void addListener(String key, ConfigurationListener listener)
      Parameters:
      key - the key to represent a configuration
      listener - configuration listener
    • removeListener

      default void removeListener(String key, ConfigurationListener listener)
      Parameters:
      key - the key to represent a configuration
      listener - configuration listener
    • addListener

      void addListener(String key, String group, ConfigurationListener listener)
      Register a configuration listener for a specified key The listener only works for service governance purpose, so the target group would always be the value user specifies at startup or 'dubbo' by default. This method will only register listener, which means it will not trigger a notification that contains the current value.
      Parameters:
      key - the key to represent a configuration
      group - the group where the key belongs to
      listener - configuration listener
    • removeListener

      void removeListener(String key, String group, ConfigurationListener listener)
      Stops one listener from listening to value changes in the specified key.
      Parameters:
      key - the key to represent a configuration
      group - the group where the key belongs to
      listener - configuration listener
    • getConfig

      default String getConfig(String key, String group)
      Get the configuration mapped to the given key and the given group with the default timeout
      Parameters:
      key - the key to represent a configuration
      group - the group where the key belongs to
      Returns:
      target configuration mapped to the given key and the given group
    • getConfigItem

      default ConfigItem getConfigItem(String key, String group)
      get configItem which contains content and stat info.
      Parameters:
      key -
      group -
      Returns:
    • getConfig

      String getConfig(String key, String group, long timeout) throws IllegalStateException
      Get the configuration mapped to the given key and the given group. If the configuration fails to fetch after timeout exceeds, IllegalStateException will be thrown.
      Parameters:
      key - the key to represent a configuration
      group - the group where the key belongs to
      timeout - timeout value for fetching the target config
      Returns:
      target configuration mapped to the given key and the given group, IllegalStateException will be thrown if timeout exceeds.
      Throws:
      IllegalStateException
    • getProperties

      default String getProperties(String key, String group) throws IllegalStateException
      This method are mostly used to get a compound config file with the default timeout, such as a complete dubbo.properties file.
      Throws:
      IllegalStateException
    • getProperties

      default String getProperties(String key, String group, long timeout) throws IllegalStateException
      This method are mostly used to get a compound config file, such as a complete dubbo.properties file.
      Throws:
      IllegalStateException
    • publishConfig

      default boolean publishConfig(String key, String content) throws UnsupportedOperationException
      Publish Config mapped to the given key under the default group
      Parameters:
      key - the key to represent a configuration
      content - the content of configuration
      Returns:
      true if success, or false
      Throws:
      UnsupportedOperationException - If the under layer does not support
      Since:
      2.7.5
    • publishConfig

      default boolean publishConfig(String key, String group, String content) throws UnsupportedOperationException
      Publish Config mapped to the given key and the given group.
      Parameters:
      key - the key to represent a configuration
      group - the group where the key belongs to
      content - the content of configuration
      Returns:
      true if success, or false
      Throws:
      UnsupportedOperationException - If the under layer does not support
      Since:
      2.7.5
    • publishConfigCas

      default boolean publishConfigCas(String key, String group, String content, Object ticket) throws UnsupportedOperationException
      publish config mapped to this given key and given group with stat.
      Parameters:
      key -
      group -
      content -
      ticket -
      Returns:
      Throws:
      UnsupportedOperationException
    • getDefaultGroup

      default String getDefaultGroup()
      Get the default group for the operations
      Returns:
      The default value is "dubbo"
      Since:
      2.7.5
    • getDefaultTimeout

      default long getDefaultTimeout()
      Get the default timeout for the operations in milliseconds
      Returns:
      The default value is -1L
      Since:
      2.7.5
    • close

      default void close() throws Exception
      Close the configuration
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
      Since:
      2.7.5
    • getRuleKey

      static String getRuleKey(URL url)
      The format is '{interfaceName}:[version]:[group]'
      Returns:
    • removeConfig

      default boolean removeConfig(String key, String group)
      Parameters:
      key - the key to represent a configuration
      group - the group where the key belongs to
      Returns:
      true if success, or false
      Since:
      2.7.8