@Retention(RUNTIME) @Target(TYPE) @Documented public static @interface Config.HotReload
Config.Sources
(hot
reloading can't be applied to all types of URIs).
It is possible to specify an interval to indicate how frequently the library shall check the files for modifications and perform the reload.
Examples:@HotReload // will check for file changes every 5 seconds. @Sources("file:foo/bar/baz.properties") interface MyConfig extends Config { ... } @HotReload(2) // will check for file changes every 2 seconds. @Sources("file:foo/bar/baz.properties") interface MyConfig extends Config { ... } @HotReload(500, unit = TimeUnit.MILLISECONDS); // will check for file changes every 500 milliseconds. @Sources("file:foo/bar/baz.properties") interface MyConfig extends Config { ... } @HotReload(type=HotReloadType.ASYNC); // will use ASYNC reload type: will span a separate thread // that will check for the file change every 5 seconds (default). @Sources("file:foo/bar/baz.properties") interface MyConfig extends Config { ... } @HotReload(2, type=HotReloadType.ASYNC); // will use ASYNC reload type and will check every 2 seconds. @Sources("file:foo/bar/baz.properties") interface MyConfig extends Config { ... }
To intercept the ReloadEvent
see Reloadable.addReloadListener(org.aeonbits.owner.event.ReloadListener)
.
Modifier and Type | Optional Element | Description |
---|---|---|
Config.HotReloadType |
type |
The type of HotReload to use.
|
TimeUnit |
unit |
The time unit for the interval.
|
long |
value |
The interval, expressed in seconds (by default), to perform checks on the filesystem to identify modified
files and eventually perform the reloading of the properties.
|
long value
TimeUnit unit
The time unit for the interval. By default it is TimeUnit.SECONDS
.
Date resolution vary from filesystem to filesystem.
For instance, for Ext3, ReiserFS and HSF+ the date resolution is of 1 second.
For FAT32 the date resolution for the last modified time is 2 seconds.
For Ext4 the date resolution is in nanoseconds.
So, it is a good idea to express the time unit in seconds or more, since higher time resolution will probably not be supported by the underlying filesystem.
Config.HotReloadType type
Synchronous
: the configuration file is checked when a method is invoked on the
config object. So if the config object is not used for some time, the configuration doesn't get reloaded,
until its next usage. i.e. until next method invocation.
Config.HotReloadType.ASYNC
: the configuration file is checked by a background thread despite the fact that
the config object is used or not.
Copyright © 2012–2020 Luigi R. Viggiano. All rights reserved.