From f762b160efd5cafd919a6fd7f9587f578eceb454 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Sun, 02 Oct 2011 16:59:44 -0400 Subject: [PATCH] Merge branch 'master' into rpc --- src/com/gitblit/FileSettings.java | 26 ++++++++++++++++++++------ 1 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/com/gitblit/FileSettings.java b/src/com/gitblit/FileSettings.java index b70daa0..56aac8b 100644 --- a/src/com/gitblit/FileSettings.java +++ b/src/com/gitblit/FileSettings.java @@ -21,35 +21,42 @@ import java.util.Properties; /** - * Reads GitBlit settings file. + * Dynamically loads and reloads a properties file by keeping track of the last + * modification date. + * + * @author James Moger * */ public class FileSettings extends IStoredSettings { - private final File propertiesFile; + protected final File propertiesFile; private final Properties properties = new Properties(); - private volatile long lastread; + private volatile long lastModified; public FileSettings(String file) { super(FileSettings.class); this.propertiesFile = new File(file); } + /** + * Returns a properties object which contains the most recent contents of + * the properties file. + */ @Override protected synchronized Properties read() { - if (propertiesFile.exists() && (propertiesFile.lastModified() > lastread)) { + if (propertiesFile.exists() && (propertiesFile.lastModified() > lastModified)) { FileInputStream is = null; try { Properties props = new Properties(); is = new FileInputStream(propertiesFile); props.load(is); - + // load properties after we have successfully read file properties.clear(); properties.putAll(props); - lastread = propertiesFile.lastModified(); + lastModified = propertiesFile.lastModified(); } catch (FileNotFoundException f) { // IGNORE - won't happen because file.exists() check above } catch (Throwable t) { @@ -67,6 +74,13 @@ return properties; } + /** + * @return the last modification date of the properties file + */ + protected long lastModified() { + return lastModified; + } + @Override public String toString() { return propertiesFile.getAbsolutePath(); -- Gitblit v1.9.1