the file (or other) source
Setting the max age to, say, 10000 will mean that the file timestamp is only checked at most once every ten seconds, minimising the overhead of logic and thread synchronisation.
a function that will be invoked when a change in the file has been detected. It receives a boolean
indicating whether the source should be reloaded. For file-based sources, this is true if the
file exists and is newer than the last time it was opened; if the file has recently been deleted,
refresh
will be invoked with the false value.
For readable-once sources and classpath sources, the value will only ever be true the first time.
Many threads may concurrently call pollForUpdate
or updateNow
, but if they result
in a refresh
, this will occur within a monitor lock on the source change detector.
This ensures that calls to refresh
will only ever happen one at a time.
Be careful not to attempt to obtain other locks inside refresh
in a way that night cause deadlock.
Checks whether the source is newer and needs reloading.
Checks whether the source is newer and needs reloading. For the large part of the max-age period, this method does almost nothing. At infrequent periods, it will inspect the file's last-modified timestamp and potentially signal for the file to be reloaded. Therefore it is safe to call this method frequently, every time a value is needed from the cache of file contents.
true if the refresh callback was invoked with its argument set to true
Triggers an immediate change detection.
Triggers an immediate change detection. Use this if it is known by some other means that the cache has become stale.
true if the refresh callback was invoked with its argument set to true
Provides a tool for detecting changes in a
ConfigSourceJ
, typically intended for observing changed files via their last modified timestamps. Polling is done economically: (a) it is only done by the calling thread (no background threads are needed), and (b) a max-age parameter sets a band of time during which updates are ignored.