public class FileChangedReloadingStrategy extends Object implements 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.
Modifier and Type | Field and Description |
---|---|
protected FileConfiguration |
configuration
Stores a reference to the configuration to be monitored.
|
protected long |
lastChecked
The last time the file was checked for changes.
|
protected long |
lastModified
The last time the configuration file was modified.
|
protected long |
refreshDelay
The minimum delay in milliseconds between checks.
|
Constructor and Description |
---|
FileChangedReloadingStrategy() |
Modifier and Type | Method and Description |
---|---|
protected File |
getFile()
Returns the file that is monitored by this strategy.
|
long |
getRefreshDelay()
Return the minimal time in milliseconds between two reloadings.
|
protected boolean |
hasChanged()
Check if the configuration has changed since the last time it was loaded.
|
void |
init()
Initialize the strategy.
|
void |
reloadingPerformed()
Notify the strategy that the file has been reloaded.
|
boolean |
reloadingRequired()
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 |
updateLastModified()
Update the last modified time.
|
protected FileConfiguration configuration
protected long lastModified
protected long lastChecked
protected long refreshDelay
public void setConfiguration(FileConfiguration configuration)
ReloadingStrategy
setConfiguration
in interface ReloadingStrategy
configuration
- the configuration to monitorpublic void init()
ReloadingStrategy
init
in interface ReloadingStrategy
public boolean reloadingRequired()
ReloadingStrategy
reloadingRequired
in interface ReloadingStrategy
public void reloadingPerformed()
ReloadingStrategy
reloadingPerformed
in interface ReloadingStrategy
public long getRefreshDelay()
public void setRefreshDelay(long refreshDelay)
refreshDelay
- refresh delay in millisecondsprotected void updateLastModified()
protected boolean hasChanged()
protected File getFile()
Copyright © 2018 JBoss by Red Hat. All rights reserved.