Class CafConfigurationSource
java.lang.Object
com.github.cafapi.common.config.source.CafConfigurationSource
- All Implemented Interfaces:
ConfigurationMetricsReporter
,ConfigurationSource
,HealthReporter
,ManagedConfigurationSource
- Direct Known Subclasses:
FileConfigurationSource
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 Summary
ConstructorsConstructorDescriptionCafConfigurationSource
(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. -
Method Summary
Modifier and TypeMethodDescriptionprotected Cipher
final <T> T
getConfiguration
(Class<T> configClass) Acquire a configuration class from the provider.final int
final int
protected abstract InputStream
getConfigurationStream
(Class configClass, Name relativePath) Acquire and return a stream of the serialised data from the transport source.protected ServicePath
protected jakarta.validation.Validator
protected void
Increase the number of configuration errors recorded.protected void
Increase the number of configuration requests recorded.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.cafapi.common.api.HealthReporter
healthCheck, livenessCheck
Methods inherited from interface com.github.cafapi.common.api.ManagedConfigurationSource
shutdown
-
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 configurationcipher
- for decrypting information in a configuration fileservicePath
- to localise configuration for this servicedecoder
- provides a mechanism to decode the configuration format
-
-
Method Details
-
getConfiguration
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 interfaceConfigurationSource
- 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 interfaceConfigurationMetricsReporter
- Specified by:
getConfigurationRequests
in interfaceManagedConfigurationSource
- Returns:
- the number of configuration requests handled to date
-
getConfigurationErrors
public final int getConfigurationErrors()- Specified by:
getConfigurationErrors
in interfaceConfigurationMetricsReporter
- Specified by:
getConfigurationErrors
in interfaceManagedConfigurationSource
- Returns:
- the number of failures/errors when retrieving configuration to date
-
getCipher
-
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 acquiredrelativePath
- 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.
-