commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From commons-...@jakarta.apache.org
Subject [Jakarta Commons Wiki] Updated: Configuration
Date Thu, 02 Dec 2004 18:43:56 GMT
   Date: 2004-12-02T10:43:55
   Editor: AndresValdez <avaldini@yahoo.com>
   Wiki: Jakarta Commons Wiki
   Page: Configuration
   URL: http://wiki.apache.org/jakarta-commons/Configuration

   I donĀ“t know how to use the wiki very well, I hope someone edit this

Change Log:

------------------------------------------------------------------------------
@@ -7,7 +7,87 @@
 
  ||Do you have a good example, add it here!||
 I have made an Auto-configuration-Reloading Class.
+This class implements the Runnable interface and inherits from PropertiesConfiguration.
+This class alsa has a Singleton behavior, so there is only one Configuration class at time,
provided every X milliseconds.
+
 You can see the implementation here:
+
+public class Configuration extends PropertiesConfiguration implements Runnable {
+    //Logger
+    static Log log = LogFactory.getLog(Configuration.class);
+
+    //Cargar el archivo de queries al inicializar la clase
+    private static String configFile;
+    private static boolean goOn = true;
+
+    static {
+        configFile = "config.txt";
+    }
+
+    /**
+     * Holds singleton instance
+     */
+    private static Configuration instance;
+
+    /**
+     * prevents instantiation
+     */
+    private Configuration() {
+        // prevent creation
+    }
+
+    private Configuration(String file) throws ConfigurationException {
+        super(file);
+    }
+
+    /**
+     * Returns the "singleton" instance.
+     @return        the singleton instance
+     */
+    static public Configuration getInstance() {
+        if (instance == null) {
+            try {
+                instance = new Configuration(configFile);
+                log.debug("Loaded:" + ((PropertiesConfiguration) instance).toString());
+            } catch (ConfigurationException e) {
+                log.error("Error reading configuration file: " + configFile);
+            }
+        }            
+        return instance;
+    }
+
+    public static void main(String[] args) {
+        Thread t = new Thread(Configuration.getInstance());
+        t.start();
+    }
+
+    /* Runner
+     * @see java.lang.Runnable#run()
+     */
+    public void run() {
+        while (goOn) {
+            try {
+                instance = new Configuration(configFile);
+                log.debug("Loaded:" + ((PropertiesConfiguration) instance).toString());
+            } catch (ConfigurationException e) {
+                log.error("Error reading configuration file: " + configFile);
+            } catch (Exception e) {
+                log.error("Error reading configuration file: " + configFile);
+            }
+
+            try {
+                Thread.sleep(instance.getLong("reload.config.after"));
+            } catch (InterruptedException e) {
+                log.error("Error reading configuration file: " + configFile);
+                log.error(": " + e.getLocalizedMessage());
+            }
+        }
+    }
+
+   }
+
+
+
 
 = FAQ =
 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message