You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mike Lucas (JIRA)" <ji...@apache.org> on 2013/05/01 19:36:16 UTC

[jira] [Comment Edited] (CONFIGURATION-532) FileChangedReloadingStrategy should support reloading of rolled-back (older timestamp) files

    [ https://issues.apache.org/jira/browse/CONFIGURATION-532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13646737#comment-13646737 ] 

Mike Lucas edited comment on CONFIGURATION-532 at 5/1/13 5:34 PM:
------------------------------------------------------------------

In case anyone is interested, here is my subclass that overrides hasChanged(), useful until you can use 2.0:

{code}
public class FileChangedReloadingStrategy extends org.apache.commons.configuration.reloading.FileChangedReloadingStrategy {

  /**
   * Overrides the superclass method to do a not-equal-to comparison on the file timestamp, rather than
   * greater-than. This ensures that virtually any* change to the config file will result in a reload, subject
   * to the refreshDelay of course.
   * <p/>
   * * It is possible to make a change to the content and then set the timestamp to the exact same as it was
   * before, which won't result in a reload. But that would just be weird and very unlikely.
   * @see org.apache.commons.configuration.reloading.FileChangedReloadingStrategy#hasChanged()
   */
  @Override
  protected boolean hasChanged() {
	
        File file = getFile();
        if (file == null || !file.exists())
        {
            return false;
        }

        return file.lastModified() != lastModified;
  }

}
{code}
                
      was (Author: artellan):
    In case anyone is interested, here is my subclass that overrides isChanged(), useful until you can use 2.0:

{code}
public class FileChangedReloadingStrategy extends org.apache.commons.configuration.reloading.FileChangedReloadingStrategy {

  /**
   * Overrides the superclass method to do a not-equal-to comparison on the file timestamp, rather than
   * greater-than. This ensures that virtually any* change to the config file will result in a reload, subject
   * to the refreshDelay of course.
   * <p/>
   * * It is possible to make a change to the content and then set the timestamp to the exact same as it was
   * before, which won't result in a reload. But that would just be weird and very unlikely.
   * @see org.apache.commons.configuration.reloading.FileChangedReloadingStrategy#hasChanged()
   */
  @Override
  protected boolean hasChanged() {
	
        File file = getFile();
        if (file == null || !file.exists())
        {
            return false;
        }

        return file.lastModified() != lastModified;
  }

}
{code}
                  
> FileChangedReloadingStrategy should support reloading of rolled-back (older timestamp) files
> --------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-532
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-532
>             Project: Commons Configuration
>          Issue Type: Improvement
>          Components: File reloading
>    Affects Versions: 1.9
>            Reporter: Mike Lucas
>             Fix For: 2.0
>
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> Currently the {{FileChangedReloadingStrategy}} only reloads when the timestamp of the file on the filesystem is _newer_ than the timestamp it had when it was last loaded.
> This may not be the expected behaviour when, for example, an administrator makes a backup copy of the original configuration file before making changes. If the administrator wants to roll back to the original configuration, he may expect that copying/renaming the backup back to the original name, would cause the original configuration to take effect again.
> Another example where the current behaviour is problematic is when using a Deploy System (like we do at my company). We expect to be able to roll-back to a previous configuration by simply redeploying the Config artifact, but because the timestamps reflect when the Config artifact was _built_ (not when it was deployed), this roll-back will not work.
> The current behaviour could be kept as the default, simply adding {{setReloadOnRollback()}} or similarly named method to change the behaviour to reload when the timestamp is either older or newer (i.e. not equal to) the {{lastModified}} variable. Another option would to be to create subclass {{FileChangedOrRolledBackReloadingStrategy}} that overrides the {{hasChanged()}} method.
> In either option the actual change is to use {{!=}} instead of {{>}} in the {{hasChanged}} method's comparison:
> {code}
> return file.lastModified() > lastModified;
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira