@NotThreadSafe public abstract class BaseProvider extends java.lang.Object implements ParamProvider
Modifier and Type | Field and Description |
---|---|
protected CacheManager |
cacheManager |
static java.lang.String |
PARAMETERS |
Constructor and Description |
---|
BaseProvider(CacheManager cacheManager) |
Modifier and Type | Method and Description |
---|---|
protected BaseProvider |
defaultMaxAge(int maxAge,
java.time.temporal.ChronoUnit unit)
(Optional) Set the default max age for the cache of all parameters.
|
java.lang.String |
get(java.lang.String key)
Get the value of a parameter, either from the underlying store or a cached value (if not expired).
Using this method, you can apply a basic transformation (to String). |
<T> T |
get(java.lang.String key,
java.lang.Class<T> targetClass)
Get the value of a parameter, either from the underlying store or a cached value (if not expired).
Using this method, you must apply a transformation (eg. |
java.util.Map<java.lang.String,java.lang.String> |
getMultiple(java.lang.String path)
Retrieve multiple parameter values either from the underlying store or a cached value (if not expired).
Cache all values with the 'path' as the key and also individually to be able to get(String) a single value laterDoes not support transformation. |
protected abstract java.util.Map<java.lang.String,java.lang.String> |
getMultipleValues(java.lang.String path)
Retrieve multiple parameter values from the underlying parameter store.
Abstract: Implement this method in a child class of BaseProvider |
protected abstract java.lang.String |
getValue(java.lang.String key)
Retrieve the parameter value from the underlying parameter store.
Abstract: Implement this method in a child class of BaseProvider |
protected java.time.Instant |
now() |
protected void |
resetToDefaults() |
protected void |
setTransformationManager(TransformationManager transformationManager) |
BaseProvider |
withMaxAge(int maxAge,
java.time.temporal.ChronoUnit unit)
(Optional) Builder method to call before
get(String) or get(String, Class)
to set cache max age for the parameter to get.The max age is reset to default (either 5 or a custom value set with defaultMaxAge(int, java.time.temporal.ChronoUnit) ) after each get,
so you need to use this method for each parameter to cache with non-default max age.Not Thread Safe: calling this method simultaneously by several threads can lead to unwanted cache time for some parameters. |
BaseProvider |
withTransformation(java.lang.Class<? extends Transformer> transformerClass)
Builder method to call before
get(String) (Optional) or get(String, Class) (Mandatory). |
public static final java.lang.String PARAMETERS
protected final CacheManager cacheManager
public BaseProvider(CacheManager cacheManager)
protected abstract java.lang.String getValue(java.lang.String key)
BaseProvider
key
- key of the parameterprotected abstract java.util.Map<java.lang.String,java.lang.String> getMultipleValues(java.lang.String path)
BaseProvider
path
- Parameter store pathprotected BaseProvider defaultMaxAge(int maxAge, java.time.temporal.ChronoUnit unit)
withMaxAge(int, ChronoUnit)
.withMaxAge(int, ChronoUnit)
after {#defaultMaxAge(int, ChronoUnit)} in the chain.maxAge
- Maximum time to cache the parameter, before calling the underlying parameter store.unit
- Unit of timeprovider.defaultMaxAge(10, SECONDS).get("key")).
public BaseProvider withMaxAge(int maxAge, java.time.temporal.ChronoUnit unit)
get(String)
or get(String, Class)
to set cache max age for the parameter to get.defaultMaxAge(int, java.time.temporal.ChronoUnit)
) after each get,
so you need to use this method for each parameter to cache with non-default max age.maxAge
- Maximum time to cache the parameter, before calling the underlying parameter store.unit
- Unit of timeprovider.withMaxAge(10, SECONDS).get("key")).
public BaseProvider withTransformation(java.lang.Class<? extends Transformer> transformerClass)
get(String)
(Optional) or get(String, Class)
(Mandatory).
to provide a Transformer
that will transform the String parameter into something else (String, Object, ...)
Base64Transformer
and JsonTransformer
are provided for respectively base64 and json content. You can also write your own (see Transformer
).
Not Thread Safe: calling this method simultaneously by several threads
can lead to errors (one Transformer for the wrong target type)
transformerClass
- Class of the transformer to apply. For convenience, you can use Transformer.json
or Transformer.base64
shortcuts.provider.withTransformation(json).get("key", MyObject.class)).
public java.util.Map<java.lang.String,java.lang.String> getMultiple(java.lang.String path)
get(String)
a single value latergetMultiple
in interface ParamProvider
path
- path of the parameterpublic java.lang.String get(java.lang.String key)
BasicTransformer
with withTransformation(Class)
.get(String, Class)
method instead of this one. get
in interface ParamProvider
key
- key of the parameterjava.lang.IllegalStateException
- if a wrong transformer class is provided through withTransformation(Class)
. Needs to be a BasicTransformer
.TransformationException
- if the transformation could not be done, because of a wrong format or an error during transformation.public <T> T get(java.lang.String key, java.lang.Class<T> targetClass)
Transformer
with withTransformation(Class)
.get(String)
method instead of this one.get
in interface ParamProvider
key
- key of the parametertargetClass
- class of the target Object (after transformation)java.lang.IllegalStateException
- if no transformation class was provided through withTransformation(Class)
TransformationException
- if the transformation could not be done, because of a wrong format or an error during transformation.protected java.time.Instant now()
protected void resetToDefaults()
protected void setTransformationManager(TransformationManager transformationManager)
Copyright © 2025. All rights reserved.