The application can register onChange listeners to handle changes to configuration properties at runtime. Plugins or code can dynamically load and change properties and this can fire any registered callback handlers.
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);
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigurationReturn the underlying configuration.static PropertiesReturn the loaded properties as standard Properties map.static booleanReturn boolean configuration value with the given default value.static booleanReturn boolean configuration value with the given default value.static StringReturn a required configuration value as String.static StringReturn a configuration string value with a given default.static booleanReturn a required boolean configuration value.static booleanReturn a configuration value as boolean given a default value.static BigDecimalgetDecimal(String key) Return a decimal configuration value.static BigDecimalgetDecimal(String key, String defaultValue) Return a decimal configuration value with a default value.static DurationgetDuration(String key) Return a Duration configuration value.static DurationgetDuration(String key, String defaultValue) Return a Duration configuration value with a default value.static <T extends Enum<T>>
TReturn the enum configuration value.static <T extends Enum<T>>
TReturn the enum configuration value with a default value.static intReturn a required int configuration value.static intReturn a configuration value as int given a default value.static Configuration.ListValuegetList()Deprecated.static longReturn a required long configuration value.static longReturn a configuration value as long given a default value.getOptional(String key) Return a configuration value that might not exist.static Configuration.SetValuegetSet()Deprecated.static URIReturn a URI configuration value.static URIReturn a URI configuration value with a default value.static URLReturn a URL configuration value.static URLReturn a URL configuration value with a default value.static Configuration.ListValuelist()Return a List of values configured.static voidPut all loaded properties into System properties.static voidRegister a callback for a change to the given configuration key.static voidonChangeBool(String key, Consumer<Boolean> callback) Register a callback for a change to the given configuration key as an Boolean value.static voidonChangeInt(String key, Consumer<Integer> callback) Register a callback for a change to the given configuration key as an Int value.static voidonChangeLong(String key, Consumer<Long> callback) Register a callback for a change to the given configuration key as an Long value.static Configuration.SetValueset()Return a Set of values configured.static voidsetProperty(String key, String value) Set a configuration value.
-
Method Details
-
asProperties
Return the loaded properties as standard Properties map. -
asConfiguration
Return the underlying configuration. -
loadIntoSystemProperties
public static void loadIntoSystemProperties()Put all loaded properties into System properties. -
get
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
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
Return a configuration value that might not exist.- Parameters:
key- The configuration key- Returns:
- The configured value wrapped as optional
-
enabled
Return boolean configuration value with the given default value.IllegalStateException is thrown if the value is not defined in configuration.
if (Config.enabled("feature.cleanup")) { ... }- Parameters:
key- The configuration key- Returns:
- True when configuration value is true
-
enabled
Return boolean configuration value with the given default value.if (Config.enabled("feature.cleanup", true)) { ... }- Parameters:
key- The configuration key- Returns:
- True when configuration value is true
-
getBool
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
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
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
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
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
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
Return a decimal configuration value.- Parameters:
key- The configuration key- Returns:
- The configured value
-
getDecimal
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
Return a URL configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getURL
Return a URL configuration value with a default value.- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getURI
Return a URI configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getURI
Return a URI configuration value with a default value.- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getDuration
Return a Duration configuration value.IllegalStateException is thrown if the value is not defined in configuration.
- Parameters:
key- The configuration key- Returns:
- The configured value
-
getDuration
Return a Duration configuration value with a default value.- Parameters:
key- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
getEnum
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
Return the enum configuration value with a default value.- Parameters:
type- The enum typekey- The configuration keydefaultValue- The default value- Returns:
- The configured value
-
list
Return a List of values configured.List<Integer> codes = Config.list().ofInt("my.codes", 97, 45); -
getList
Deprecated.Deprecated migrate to list(). -
set
Return a Set of values configured.Set<String> operations = Config.set().of("my.operations", "put","delete"); -
getSet
Deprecated.Deprecated migrate to set(). -
setProperty
Set a configuration value.This will fire an configuration callback listeners that are registered for this key.
-
onChange
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
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
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
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.
-