You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Component Overview

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="30d1a4c9-de46-4522-b432-27d009ff8c55"><ac:plain-text-body><![CDATA[

http://jakarta.apache.org/commons/component/images/component-logo-white.png

[http://jakarta.apache.org/commons/component/ Commons-Configuration] Tools to assist in the reading of configuration/preferences files in various formats.[BR] A lot of information is available on the [http://jakarta.apache.org/commons/configuration/ Commons-Configuration website]. If you don't find the information you need you can always contact us using one of the [http://jakarta.apache.org/site/mail2.html#Commons mailing lists].

]]></ac:plain-text-body></ac:structured-macro>

External Resources

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

Add your questions/answers here.

  • No labels