Package io.avaje.config
Interface Configuration
-
public interface Configuration
Configuration API for accessing property values and registering onChange listeners.Examples
int port = Config.getInt("app.port", 8090); String topicName = Config.get("app.topic.name"); List<Integer> codes = Config.getList().ofInt("my.codes", 42, 54);
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceConfiguration.ExpressionEvalExpression evaluation.static interfaceConfiguration.ListValueReturn a List of values for a configuration key.static interfaceConfiguration.SetValueReturn a Set of values configured.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description PropertiesasProperties()Return the loaded properties as standard Properties map.Propertieseval(Properties properties)Return a copy of the properties with 'eval' run on all the values.Stringget(String key)Return a required configuration value as String.Stringget(String key, String defaultValue)Return a configuration string value with a given default.booleangetBool(String key)Return a required boolean configuration value.booleangetBool(String key, boolean defaultValue)Return a configuration value as boolean given a default value.BigDecimalgetDecimal(String key)Return a decimal configuration value.BigDecimalgetDecimal(String key, String defaultValue)Return a decimal configuration value with a default value.<T extends Enum<T>>
TgetEnum(Class<T> type, String key)Return the enum configuration value.<T extends Enum<T>>
TgetEnum(Class<T> type, String key, T defaultValue)Return the enum configuration value with a default value.intgetInt(String key)Return a required int configuration value.intgetInt(String key, int defaultValue)Return a configuration value as int given a default value.Configuration.ListValuegetList()Return a List of values configured.longgetLong(String key)Return a required long configuration value.longgetLong(String key, long defaultValue)Return a configuration value as long given a default value.Optional<String>getOptional(String key)Return a configuration value that might not exist.Configuration.SetValuegetSet()Return a Set of values configured.URLgetURL(String key)Return a URL configuration value.URLgetURL(String key, String defaultValue)Return a URL configuration value with a default value.voidloadIntoSystemProperties()Put the loaded properties into System properties.voidonChange(String key, Consumer<String> callback)Register a callback for a change to the given configuration key.voidonChangeBool(String key, Consumer<Boolean> callback)Register a callback for a change to the given configuration key as an Boolean value.voidonChangeInt(String key, Consumer<Integer> callback)Register a callback for a change to the given configuration key as an Int value.voidonChangeLong(String key, Consumer<Long> callback)Register a callback for a change to the given configuration key as an Long value.voidschedule(long delay, long period, Runnable task)Schedule a task to run periodically with a given delay and period.voidsetProperty(String key, String value)Set a configuration value.intsize()Return the number of configuration properties.
-
-
-
Method Detail
-
asProperties
Properties asProperties()
Return the loaded properties as standard Properties map.
-
get
String get(String key)
Return a required configuration value as String.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
get
String get(String key, String defaultValue)
Return a configuration string value with a given default.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getOptional
Optional<String> getOptional(String key)
Return a configuration value that might not exist.- Parameters:
key- The configuration key- Returns:
- The configured value wrapped as optional
-
getBool
boolean getBool(String key)
Return a required boolean configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getBool
boolean getBool(String key, boolean defaultValue)
Return a configuration value as boolean given a default value.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getInt
int getInt(String key)
Return a required int configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getInt
int getInt(String key, int defaultValue)
Return a configuration value as int given a default value.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getLong
long getLong(String key)
Return a required long configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getLong
long getLong(String key, long defaultValue)
Return a configuration value as long given a default value.- Parameters:
key- The configuration keydefaultValue- The default value used- Returns:
- The configured or default value
-
getDecimal
BigDecimal getDecimal(String key)
Return a decimal configuration value.- Parameters:
key- The configuration key- Returns:
- The configured value
-
getDecimal
BigDecimal getDecimal(String key, String defaultValue)
Return a decimal configuration value with a default value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getURL
URL getURL(String key)
Return a URL configuration value.- Parameters:
key- The configuration key- Returns:
- The configured value
-
getURL
URL getURL(String key, String defaultValue)
Return a URL configuration value with a default value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getEnum
<T extends Enum<T>> T getEnum(Class<T> type, String key)
Return the enum configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
type- The enum typekey- The configuration key- Returns:
- The configured value
-
getEnum
<T extends Enum<T>> T getEnum(Class<T> type, String key, T defaultValue)
Return the enum configuration value with a default value.- Parameters:
type- The enum typekey- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getList
Configuration.ListValue getList()
Return a List of values configured.List<Integer> codes = Config.getList().ofInt("my.codes", 97, 45);
-
getSet
Configuration.SetValue getSet()
Return a Set of values configured.Set<String> operations = Config.getSet().of("my.operations", "put","delete");
-
setProperty
void setProperty(String key, String value)
Set a configuration value.This will fire an configuration callback listeners that are registered for this key.
-
onChange
void onChange(String key, Consumer<String> callback)
Register a callback for a change to the given configuration key.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
onChangeInt
void onChangeInt(String key, Consumer<Integer> callback)
Register a callback for a change to the given configuration key as an Int value.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
onChangeLong
void onChangeLong(String key, Consumer<Long> callback)
Register a callback for a change to the given configuration key as an Long value.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
onChangeBool
void onChangeBool(String key, Consumer<Boolean> callback)
Register a callback for a change to the given configuration key as an Boolean value.- Parameters:
key- The configuration key we want to detect changes tocallback- The callback handling to fire when the configuration changes.
-
loadIntoSystemProperties
void loadIntoSystemProperties()
Put the loaded properties into System properties.
-
size
int size()
Return the number of configuration properties.
-
schedule
void schedule(long delay, long period, Runnable task)
Schedule a task to run periodically with a given delay and period.- Parameters:
delay- delay in milliseconds before task is to be executed.period- time in milliseconds between successive task executions.task- task to be scheduled.
-
eval
Properties eval(Properties properties)
Return a copy of the properties with 'eval' run on all the values.
-
-