[vlma-devel] commit: Reload configuration whenever configuration file changes. ( Adrien Grand )

git version control git at videolan.org
Sat Jul 12 14:56:48 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sat Jul 12 14:46:42 2008 +0200| [425f32a4a9260f49d4ce4c16866950b5b9c5a7d6]

Reload configuration whenever configuration file changes.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=425f32a4a9260f49d4ce4c16866950b5b9c5a7d6
---

 .../src/main/java/org/videolan/vlma/VLMa.java      |   13 +++++++------
 vlma-webapp/pom.xml                                |    5 +++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/vlma-configuration/src/main/java/org/videolan/vlma/VLMa.java b/vlma-configuration/src/main/java/org/videolan/vlma/VLMa.java
index 73e6367..8b82b2f 100644
--- a/vlma-configuration/src/main/java/org/videolan/vlma/VLMa.java
+++ b/vlma-configuration/src/main/java/org/videolan/vlma/VLMa.java
@@ -21,12 +21,12 @@
 package org.videolan.vlma;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 import org.apache.commons.configuration.CompositeConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
 import org.apache.log4j.Logger;
 
 /**
@@ -55,10 +55,7 @@ public class VLMa extends CompositeConfiguration implements Configuration {
             try {
                 instance = new VLMa(getUserConfFile());
             } catch (ConfigurationException e) {
-                logger.error("Unable to read configuration file.", e);
-                instance = new VLMa();
-            } catch (IOException e) {
-                logger.error("Unable to read configuration file.", e);
+                logger.error("Unable to load " + getUserConfFile().getAbsolutePath(), e);
                 instance = new VLMa();
             }
         }
@@ -74,7 +71,7 @@ public class VLMa extends CompositeConfiguration implements Configuration {
         super();
     }
 
-    private static File getUserConfFile() throws IOException {
+    private static File getUserConfFile() {
         String confDir = System.getProperty("vlma.conf");
         if (confDir == null) {
             // If vlma.conf is not set, then read VLMa configuration
@@ -89,6 +86,10 @@ public class VLMa extends CompositeConfiguration implements Configuration {
     private static Configuration getUserConf(File f) throws ConfigurationException {
         PropertiesConfiguration configuration = new PropertiesConfiguration(f);
         configuration.setAutoSave(true);
+        // Reload configuration whenever the file changes
+        FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
+        reloadingStrategy.setConfiguration(configuration);
+        configuration.setReloadingStrategy(reloadingStrategy);
         return configuration;
     }
 
diff --git a/vlma-webapp/pom.xml b/vlma-webapp/pom.xml
index ba4d85e..72ba2e3 100644
--- a/vlma-webapp/pom.xml
+++ b/vlma-webapp/pom.xml
@@ -84,6 +84,11 @@
             <version>1.1.2</version>
         </dependency>
         <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.14</version>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
             <version>2.5</version>



More information about the vlma-devel mailing list