Class CafConfigurationSource

java.lang.Object
com.github.cafapi.common.config.source.CafConfigurationSource
All Implemented Interfaces:
ConfigurationMetricsReporter, ConfigurationSource, HealthReporter, ManagedConfigurationSource
Direct Known Subclasses:
FileConfigurationSource

public abstract class CafConfigurationSource extends Object implements ManagedConfigurationSource
Partial implementation of a ManagedConfigurationSource that performs hierarchical lookups based upon the service's ServicePath, and recursive lookup for configuration objects that themselves have configuration in marked with the @Configuration annotation.
  • Constructor Details

    • CafConfigurationSource

      public CafConfigurationSource(BootstrapConfiguration bootstrapProvider, Cipher cipher, ServicePath servicePath, Decoder decoder)
      Each ConfigurationProvider itself takes some initial source of configuration which it may or may not use to initialise itself. The initial "bootstrap" configuration comes from the worker core itself.
      Parameters:
      bootstrapProvider - the initial provider of configuration
      cipher - for decrypting information in a configuration file
      servicePath - to localise configuration for this service
      decoder - provides a mechanism to decode the configuration format
  • Method Details

    • getConfiguration

      public final <T> T getConfiguration(Class<T> configClass) throws ConfigurationException
      Acquire a configuration class from the provider. The requested class will be a simple Java object that when returned, and can be interacted with using getters and other standard mechanisms. Configuration classes may themselves contain other configuration objects, which will be recursively acquired if marked @Configuration. Any fields marked @Encrypted will be decrypted, any fields marked and any validation annotations will be processed.
      Specified by:
      getConfiguration in interface ConfigurationSource
      Type Parameters:
      T - the class that represents your configuration
      Parameters:
      configClass - the class that represents your configuration
      Returns:
      the configuration class requested, if it can be deserialised
      Throws:
      ConfigurationException - if the configuration class cannot be acquired or deserialised
    • getConfigurationRequests

      public final int getConfigurationRequests()
      Specified by:
      getConfigurationRequests in interface ConfigurationMetricsReporter
      Specified by:
      getConfigurationRequests in interface ManagedConfigurationSource
      Returns:
      the number of configuration requests handled to date
    • getConfigurationErrors

      public final int getConfigurationErrors()
      Specified by:
      getConfigurationErrors in interface ConfigurationMetricsReporter
      Specified by:
      getConfigurationErrors in interface ManagedConfigurationSource
      Returns:
      the number of failures/errors when retrieving configuration to date
    • getCipher

      protected Cipher getCipher()
    • getServicePath

      protected ServicePath getServicePath()
    • getValidator

      protected jakarta.validation.Validator getValidator()
    • getConfigurationStream

      protected abstract InputStream getConfigurationStream(Class configClass, Name relativePath) throws ConfigurationException
      Acquire and return a stream of the serialised data from the transport source.
      Parameters:
      configClass - the configuration class to be acquired
      relativePath - the partial service path that defines the scope to try and acquire the configuration in
      Returns:
      the stream containing the serailised configuration of the class
      Throws:
      ConfigurationException - if the stream cannot be acquired
    • incrementRequests

      protected void incrementRequests()
      Increase the number of configuration requests recorded.
    • incrementErrors

      protected void incrementErrors()
      Increase the number of configuration errors recorded.