Class FileChangedReloadingStrategy
java.lang.Object
org.apache.commons.configuration.reloading.FileChangedReloadingStrategy
- All Implemented Interfaces:
ReloadingStrategy
A reloading strategy that will reload the configuration every time its underlying file is changed.
This reloading strategy does not actively monitor a configuration file, but is triggered by its associated configuration whenever properties are accessed. It then checks the configuration file's last modification date and causes a reload if this has changed.
To avoid permanent disc access on successive property lookups a refresh delay can be specified. This has the effect that the configuration file's last modification date is only checked once in this delay period. The default value for this refresh delay is 5 seconds.
This strategy only works with FileConfiguration instances.
- Since:
- 1.1
- Version:
- $Id: FileChangedReloadingStrategy.java 1210646 2011-12-05 21:25:01Z oheger $
- Author:
- Emmanuel Bourg
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FileConfiguration
Stores a reference to the configuration to be monitored.protected long
The last time the file was checked for changes.protected long
The last time the configuration file was modified.protected long
The minimum delay in milliseconds between checks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected File
getFile()
Returns the file that is monitored by this strategy.long
Return the minimal time in milliseconds between two reloadings.protected boolean
Check if the configuration has changed since the last time it was loaded.void
init()
Initialize the strategy.void
Notify the strategy that the file has been reloaded.boolean
Tell if the evaluation of the strategy requires to reload the configuration.void
setConfiguration
(FileConfiguration configuration) Set the configuration managed by this strategy.void
setRefreshDelay
(long refreshDelay) Set the minimal time between two reloadings.protected void
Update the last modified time.
-
Field Details
-
configuration
Stores a reference to the configuration to be monitored. -
lastModified
The last time the configuration file was modified. -
lastChecked
The last time the file was checked for changes. -
refreshDelay
The minimum delay in milliseconds between checks.
-
-
Constructor Details
-
FileChangedReloadingStrategy
public FileChangedReloadingStrategy()
-
-
Method Details
-
setConfiguration
Description copied from interface:ReloadingStrategy
Set the configuration managed by this strategy.- Specified by:
setConfiguration
in interfaceReloadingStrategy
- Parameters:
configuration
- the configuration to monitor
-
init
Description copied from interface:ReloadingStrategy
Initialize the strategy.- Specified by:
init
in interfaceReloadingStrategy
-
reloadingRequired
Description copied from interface:ReloadingStrategy
Tell if the evaluation of the strategy requires to reload the configuration.- Specified by:
reloadingRequired
in interfaceReloadingStrategy
- Returns:
- a flag whether a reload should be performed
-
reloadingPerformed
Description copied from interface:ReloadingStrategy
Notify the strategy that the file has been reloaded.- Specified by:
reloadingPerformed
in interfaceReloadingStrategy
-
getRefreshDelay
Return the minimal time in milliseconds between two reloadings.- Returns:
- the refresh delay (in milliseconds)
-
setRefreshDelay
Set the minimal time between two reloadings.- Parameters:
refreshDelay
- refresh delay in milliseconds
-
updateLastModified
Update the last modified time. -
hasChanged
Check if the configuration has changed since the last time it was loaded.- Returns:
- a flag whether the configuration has changed
-
getFile
Returns the file that is monitored by this strategy. Note that the return value can be null under some circumstances.- Returns:
- the monitored file
-