From: <ath...@us...> - 2014-04-17 08:05:43
|
Revision: 1596 http://sourceforge.net/p/webassembletool/code/1596 Author: athaveau Date: 2014-04-17 08:05:40 +0000 (Thu, 17 Apr 2014) Log Message: ----------- #305 : hot reload variables Modified Paths: -------------- trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-04-14 11:42:15 UTC (rev 1595) +++ trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-04-17 08:05:40 UTC (rev 1596) @@ -17,6 +17,7 @@ import org.esigate.Driver; import org.esigate.DriverFactory; import org.esigate.util.Parameter; +import org.esigate.vars.VariablesResolver; import org.esigate.util.ParameterLong; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +57,9 @@ protected static final Logger LOG = LoggerFactory.getLogger(ConfigReloadOnChange.class); private static File configuration = null; - private static long lastModified = -1; + private static File variables = null; + private static long configLastModified = -1; + private static long varsLastModified = -1; private static long delay = DEFAULT_RELOAD_DELAY; // this variable will be used in the future, when extension supports @@ -67,9 +70,10 @@ @Override public void run() { while (!stop) { + // configuration if (configuration != null && configuration.exists()) { - if (configuration.lastModified() != lastModified) { - lastModified = configuration.lastModified(); + if (configuration.lastModified() != configLastModified) { + configLastModified = configuration.lastModified(); // Reload LOG.warn("Configuration file changed : reloading."); @@ -77,6 +81,17 @@ } } + // variables + if (variables != null && variables.exists()){ + if (variables.lastModified() != varsLastModified) { + varsLastModified = variables.lastModified(); + + // Reload + LOG.warn("Variables file changed : reloading."); + VariablesResolver.configure(); + } + } + // Wait before checking again try { Thread.sleep(delay); @@ -133,9 +148,23 @@ } if (configuration != null && configuration.exists()) { - lastModified = configuration.lastModified(); + configLastModified = configuration.lastModified(); } + // variables + URL variablesUrl = VariablesResolver.getVariablessUrl(); + if (variablesUrl != null && "file".equalsIgnoreCase(variablesUrl.getProtocol())) { + try { + variables = new File(variablesUrl.toURI()); + } catch (URISyntaxException e) { + LOG.error("Unable to access variables file", e); + } + } + + if (variables != null && variables.exists()) { + varsLastModified = variables.lastModified(); + } + // Start watcher fileWatcher.start(); } Modified: trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java =================================================================== --- trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java 2014-04-14 11:42:15 UTC (rev 1595) +++ trunk/esigate-core/src/main/java/org/esigate/vars/VariablesResolver.java 2014-04-17 08:05:40 UTC (rev 1596) @@ -15,12 +15,6 @@ package org.esigate.vars; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.apache.commons.lang3.StringUtils; import org.apache.http.cookie.Cookie; import org.esigate.ConfigurationException; @@ -32,6 +26,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Manage variables replacement. * @@ -56,9 +57,16 @@ } /** + * Loads variables from properties + */ + public static void configure(Properties props) { + properties = props; + } + + /** * Loads variables according to default configuration file org/esigate/vars.properties. */ - private static void configure() { + public static void configure() { InputStream inputStream = null; try { LOG.debug("Loading esigate-vars.properties file"); @@ -84,6 +92,17 @@ } /** + * @return The URL of the variables file. + */ + public static URL getVariablessUrl() { + URL varsUrl = Driver.class.getResource("/esigate-vars.properties"); + if (varsUrl == null){ + varsUrl = Driver.class.getResource("vars.properties"); + } + return varsUrl; + } + + /** * Regexp to find variables */ private static final Pattern VAR_PATTERN = Pattern.compile("\\$\\((.*?)\\)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |