Example usage for org.apache.commons.configuration PropertiesConfiguration setReloadingStrategy

List of usage examples for org.apache.commons.configuration PropertiesConfiguration setReloadingStrategy

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration setReloadingStrategy.

Prototype

public void setReloadingStrategy(ReloadingStrategy strategy) 

Source Link

Usage

From source file:com.freemedforms.openreact.engine.Configuration.java

public static void loadConfiguration(String defaultConfig, String overrideConfig) {
    logger.trace("Entered loadConfiguration");
    if (compositeConfiguration == null) {
        logger.info("Configuration object not present, instantiating");
        compositeConfiguration = new CompositeConfiguration();

        PropertiesConfiguration defaults = null;
        try {// w  ww.  ja  v  a 2 s  .co  m
            logger.info("Attempting to create PropertiesConfiguration object for DEFAULT_CONFIG");
            defaults = new PropertiesConfiguration(defaultConfig);
            logger.info("Loading default configuration from " + defaultConfig);
            defaults.load();
        } catch (ConfigurationException e) {
            logger.error("Could not load default configuration from " + defaultConfig);
            logger.error(e);
        }
        if (overrideConfig != null) {
            PropertiesConfiguration overrides = null;
            try {
                logger.info("Attempting to create PropertiesConfiguration object for OVERRIDE_CONFIG");
                overrides = new PropertiesConfiguration();
                logger.info("Setting file for OVERRIDE_CONFIG");
                overrides.setFile(new File(overrideConfig));
                logger.info("Setting reload strategy for OVERRIDE_CONFIG");
                overrides.setReloadingStrategy(new FileChangedReloadingStrategy());
                logger.info("Loading OVERRIDE_CONFIG");
                overrides.load();
            } catch (ConfigurationException e) {
                logger.error("Could not load overrides", e);
            } catch (Exception ex) {
                logger.error(ex);
            }
            if (overrides != null) {
                compositeConfiguration.addConfiguration(overrides);
            }
        }
        // Afterwards, add defaults so they're read second.
        compositeConfiguration.addConfiguration(defaults);
    }
}

From source file:com.dc.gameserver.baseConfig.Config.java

/**
 * ??//from w w  w. j  av a 2  s .co  m
 * @throws org.apache.commons.configuration.ConfigurationException
 */
public static void IntiConfig() throws ConfigurationException {
    PropertiesConfiguration server_config = new PropertiesConfiguration(DEFAULT_VALUE.FILE_PATH.SERVER);
    PropertiesConfiguration game_config = new PropertiesConfiguration(DEFAULT_VALUE.FILE_PATH.GAME);
    FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); //default 5000
    if (server_config.getBoolean("autoReload")) {
        strategy.setRefreshDelay(server_config.getInt("refreshDelay", 5000));
        server_config.setReloadingStrategy(strategy);
        game_config.setReloadingStrategy(strategy);
    }
    /*********************************************************************************/
    //   ??
    /*********************************************************************************/
    DEFAULT_VALUE.SERVER_VALUE.gameserverPort = server_config.getInt("gameserverPort", 8888);

    DEFAULT_VALUE.SERVER_VALUE.readTimeOut = server_config.getInt("readTimeOut");
    DEFAULT_VALUE.SERVER_VALUE.writeTimeOut = server_config.getInt("writeTimeOut");
    DEFAULT_VALUE.SERVER_VALUE.connect_timeout = server_config.getInt("connect_timeout");
    DEFAULT_VALUE.SERVER_VALUE.maxConnection = server_config.getInt("maxConnection");
    DEFAULT_VALUE.SERVER_VALUE.checkInterval = server_config.getInt("checkInterval");

    //????
    DEFAULT_VALUE.SERVER_VALUE.maxFrameLength = server_config.getInt("maxFrameLength", 1048576);
    DEFAULT_VALUE.SERVER_VALUE.lengthFieldOffset = server_config.getInt("lengthFieldOffset", 0);
    DEFAULT_VALUE.SERVER_VALUE.lengthFieldLength = server_config.getInt("lengthFieldLength", 2);
    DEFAULT_VALUE.SERVER_VALUE.lengthAdjustment = server_config.getInt("lengthAdjustment", 0);
    DEFAULT_VALUE.SERVER_VALUE.initialBytesToStrip = server_config.getInt("initialBytesToStrip", 2);

    DEFAULT_VALUE.SERVER_VALUE.useMultleThread = server_config.getBoolean("useMultleThread", false);

    //??
    DEFAULT_VALUE.SERVER_VALUE.RoundIntervalTimerNum = server_config.getInt("RoundIntervalTimerNum");
    DEFAULT_VALUE.SERVER_VALUE.RoundTimeOutTimerNum = server_config.getInt("RoundTimeOutTimerNum");
    DEFAULT_VALUE.SERVER_VALUE.buffTimerNum = server_config.getInt("buffTimerNum");
    DEFAULT_VALUE.SERVER_VALUE.calculateThreads = server_config.getInt("calculateThreads");
    DEFAULT_VALUE.SERVER_VALUE.purgeTaskNum = server_config.getInt("purgeTaskNum");
    DEFAULT_VALUE.SERVER_VALUE.AIthreadNum = server_config.getInt("AIthreadNum");

    /*********************************************************************************/
    /*   ???
    /*********************************************************************************/
    DEFAULT_VALUE.GAME_VALUE.rulePoint = game_config.getBoolean("rulePoint", false);
    DEFAULT_VALUE.GAME_VALUE.DizzinessTimes = game_config.getInt("DizzinessTimes");
    DEFAULT_VALUE.GAME_VALUE.roundOutCardIntervalTimeOut = game_config.getLong("roundOutCardIntervalTimeOut",
            30000);
    DEFAULT_VALUE.GAME_VALUE.roundInterval = game_config.getLong("roundInterval");

    /**   ->  ->  ->    1,2,3,4 */
    DEFAULT_VALUE.GAME_VALUE.soualProbability = game_config.getFloat("soualProbability");
    DEFAULT_VALUE.GAME_VALUE.defenceProbability = game_config.getFloat("defenceProbability");
    DEFAULT_VALUE.GAME_VALUE.attackProbability = game_config.getFloat("attackProbability");
    DEFAULT_VALUE.GAME_VALUE.magicProbability = game_config.getFloat("magicProbability");

    DEFAULT_VALUE.GAME_VALUE.cardBoxNum = game_config.getInt("cardBoxNum");
    DEFAULT_VALUE.GAME_VALUE.cardNum = game_config.getInt("cardNum");
    DEFAULT_VALUE.GAME_VALUE.PrograssPageSize = game_config.getInt("PrograssPageSize", 5);
    DEFAULT_VALUE.GAME_VALUE.MAX_ROUND = game_config.getInt("MAX_ROUND", 10);

    DEFAULT_VALUE.GAME_VALUE.useItemLog = game_config.getBoolean("useItemLog", true);
    DEFAULT_VALUE.GAME_VALUE.defenceRecoverySheild = game_config.getInt("defenceRecoverySheild");
    DEFAULT_VALUE.GAME_VALUE.hurt = game_config.getInt("hurt");
    DEFAULT_VALUE.GAME_VALUE.equipAndBooksAttrRandomRange = game_config
            .getDouble("equipAndBooksAttrRandomRange");

    DEFAULT_VALUE.GAME_VALUE.PinJieModulus = game_config.getDouble("PinJieModulus");
    DEFAULT_VALUE.GAME_VALUE.PinZhiModulus = game_config.getDouble("PinZhiModulus");

    DEFAULT_VALUE.GAME_VALUE.minDizziness = game_config.getInt("minDizziness");
    DEFAULT_VALUE.GAME_VALUE.maxDizziness = game_config.getInt("maxDizziness");
    DEFAULT_VALUE.GAME_VALUE.minHurtSoul = game_config.getInt("minHurtSoul");
    DEFAULT_VALUE.GAME_VALUE.maxHurtSoul = game_config.getInt("maxHurtSoul");
    DEFAULT_VALUE.GAME_VALUE.minSpike = game_config.getInt("minSpike");
    DEFAULT_VALUE.GAME_VALUE.maxSpike = game_config.getInt("maxSpike");

    //?
    //??
    //?
    //?
    //???
    //??
    //?
    DEFAULT_VALUE.GAME_VALUE.dizinnessCardNum = game_config.getInt("dizinnessCardNum");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryCardNum = game_config.getInt("InotherInjuryToInjuryCardNum");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjurySoulValue = game_config
            .getInt("InotherInjuryToInjurySoulValue");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryHurtPercent = game_config
            .getDouble("InotherInjuryToInjuryHurtPercent");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryReservedHurtPercent = game_config
            .getDouble("InotherInjuryToInjuryReservedHurtPercent");
    DEFAULT_VALUE.GAME_VALUE.SpikeCardNum = game_config.getInt("SpikeCardNum");
    DEFAULT_VALUE.GAME_VALUE.SpikeValue = game_config.getInt("SpikeValue");
    DEFAULT_VALUE.GAME_VALUE.soulRecoveryInitial = game_config.getLong("soulRecoveryInitial");
    DEFAULT_VALUE.GAME_VALUE.GongPercent = game_config.getDouble("GongPercent", 0.02);

    //?
    DEFAULT_VALUE.GAME_VALUE.spriteFullInitial = game_config.getLong("spriteFullInitial");
    DEFAULT_VALUE.GAME_VALUE.getSpriteInitial = game_config.getLong("getSpriteInitial");

    DEFAULT_VALUE.GAME_VALUE.ItemCellNum = game_config.getInt("ItemCellNum");
}

From source file:de.sub.goobi.config.ConfigMain.java

private static PropertiesConfiguration getConfig() {
    if (config == null) {
        synchronized (ConfigMain.class) {
            PropertiesConfiguration initialized = config;
            if (initialized == null) {
                PropertiesConfiguration.setDefaultListDelimiter('&');
                try {
                    initialized = new PropertiesConfiguration(FileNames.CONFIG_FILE);
                } catch (ConfigurationException e) {
                    if (myLogger.isEnabledFor(Level.WARN)) {
                        myLogger.warn("Loading of " + FileNames.CONFIG_FILE
                                + " failed. Trying to start with empty configuration.", e);
                    }//  w ww  . j a v a2 s . c  o  m
                    initialized = new PropertiesConfiguration();
                }
                initialized.setListDelimiter('&');
                initialized.setReloadingStrategy(new FileChangedReloadingStrategy());
                config = initialized;
            }
        }
    }
    return config;
}

From source file:com.googlecode.xtecuannet.framework.catalina.manager.tomcat.constants.Constants.java

public static PropertiesConfiguration getConfig(String basePath, Class clazze) {
    PropertiesConfiguration pc = null;

    String className = clazze.getSimpleName();

    File basePathObj = new File(basePath);
    File fileCfg = new File(basePathObj, className + PROPERTIES);

    try {// ww  w . j a v a  2  s  .  co  m

        if (!basePathObj.exists()) {
            if (basePathObj.mkdirs()) {
                logger.info(basePath + " created!!!");
            }
        } else {

            logger.info(basePath + " already exists skipping!!!");

            if (!fileCfg.exists()) {

                FileUtils.touch(fileCfg);
                logger.info(fileCfg.getName() + " created!!!");
            } else {

                logger.info(fileCfg.getName() + " already exists skipping!!!");
            }
        }

        pc = new PropertiesConfiguration(fileCfg);
        pc.setReloadingStrategy(new FileChangedReloadingStrategy());
        //            pc.setAutoSave(true);
        pc.setDelimiterParsingDisabled(false);

        logger.info(fileCfg.getName() + " loaded!!!");

    } catch (IOException e) {
        logger.error("Error creating config file or directory for class: " + className, e);
    } catch (ConfigurationException ex) {
        logger.error("Error getting/initializacion config for class: " + className, ex);
    }

    return pc;
}

From source file:eu.abc4trust.guice.configuration.ConfigurationParserTest.java

@Test
public void testPropertiesConfiguration() throws IOException {
    File tmp = TemporaryFileFactory.createTemporaryFile();
    String filename = tmp.getAbsolutePath();

    String credentialFilename = "credentials.file";
    String keystorageFilename = "keystorage.file";
    String tokensFilename = "tokens.file";
    String pseudonymsFilename = "pseudonyms.file";
    String defaultImagePath = "default.jpg";
    String imageCacheDir = "image_cache_dir";

    FileWriter writer = new FileWriter(tmp);
    writer.write(" credentialstorage_file" + "=" + credentialFilename + "\n");
    writer.write("keystorage_file" + " = " + keystorageFilename + "\n\n");
    writer.write("  pseudonyms_file" + "   =    " + pseudonymsFilename + "    \n");
    writer.write("tokenstorage_file" + "=" + tokensFilename + "\n");
    writer.write("default_image_path" + "=" + defaultImagePath + "\n");
    writer.write("image_cache_dir" + "=" + imageCacheDir + "\n");
    writer.close();/*from w  ww  .ja v  a 2s . c o m*/

    PropertiesConfiguration config;
    try {
        config = new PropertiesConfiguration(filename);

        config.setReloadingStrategy(new FileChangedReloadingStrategy());

        ConfigurationParser configurationParser = new ConfigurationParser(config);
        AbceConfigurationImpl abceConfiguration = new AbceConfigurationImpl();
        configurationParser.loadConfiguration(abceConfiguration);
        assertEquals(abceConfiguration.getCredentialFile().getName(), credentialFilename);
        assertEquals(abceConfiguration.getKeyStorageFile().getName(), keystorageFilename);
        assertEquals(abceConfiguration.getPseudonymsFile().getName(), pseudonymsFilename);
        assertEquals(abceConfiguration.getTokensFile().getName(), tokensFilename);
        assertEquals(abceConfiguration.getDefaultImagePath(), defaultImagePath);
        assertEquals(abceConfiguration.getImageCacheDir().getName(), imageCacheDir);
    } catch (ConfigurationException e) {
        throw new RuntimeException("Could not load property configuration", e);
    }
}

From source file:com.bitcup.configurator.FileConfig.java

private void addToCompositeConfig(String filename, boolean logWithThrowable) {
    try {//w  w  w  .  j a v  a2 s  .  c o m
        if (logger.isTraceEnabled()) {
            logger.trace("Attempting to load config file " + filename + " on the classpath...");
        }
        PropertiesConfiguration pc = new PropertiesConfiguration(filename);
        pc.setReloadingStrategy(getReloadingStrategy());
        configuration.addConfiguration(pc);
        logger.info("Loaded config file " + filename + " on the classpath");
    } catch (ConfigurationException e) {
        if (logWithThrowable) {
            logger.warn("Config file " + filename + " not found on classpath", e);
        } else {
            logger.warn("Config file " + filename + " not found on classpath");
        }
    }
}

From source file:apacheCommonsTest.testConfig.java

@Test
public void config() throws ConfigurationException, FileNotFoundException, DocumentException {

    //xml config test
    DOMConfigurator.configureAndWatch("res/gameConfig/log4j.xml");
    XMLConfiguration goodsxml = new XMLConfiguration("res/goods.xml");
    HierarchicalConfiguration.Node node = goodsxml.getRoot();
    int count = node.getChild(0).getAttributeCount(); //
    String id = (String) node.getChild(0).getAttribute(3).getValue();

    SAXReader read = new SAXReader();
    Document doc = null;//  w w  w  .j a v a  2s.c om
    doc = read.read(new FileInputStream("res/goods.xml"));

    XMLConfiguration xmlConfiguration = new XMLConfiguration(
            Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_LEVEL);
    //        AttributeMap nodeList= (AttributeMap) xmlConfiguration.getDocument().getElementsByTagName("itemDrop");

    //        Boolean auto = xmlConfiguration.getBoolean("basic.autoRelaodConfig",false) ;
    //        long  refresh=xmlConfiguration.getLong("basic.refreshDelay");
    //        System.out.println(auto);
    //        FileChangedReloadingStrategy reloadingStrategy=new FileChangedReloadingStrategy();
    //        reloadingStrategy.setRefreshDelay(xmlConfiguration.getLong("basic.refreshDelay"));
    //        xmlConfiguration.setReloadingStrategy(reloadingStrategy);

    //properties config
    PropertiesConfiguration config = new PropertiesConfiguration("res/client.properties");
    FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); //default 5000
    config.setReloadingStrategy(strategy);
    System.out.println(config.getInt("num"));
    System.out.println(config.getString("host", "127.0.0.1"));

}

From source file:com.bitcup.configurator.FileConfig.java

private void createCompositeConfiguration(String filename) {
    if (Context.getInstance().hasConfigPath()) {
        final String fn = Context.getInstance().getConfigPath() + File.separator + filename;
        URL fileUrl = ConfigurationUtils.locate(fn);
        if (fileUrl != null) {
            try {
                PropertiesConfiguration pc = new PropertiesConfiguration(fileUrl);
                pc.setReloadingStrategy(getReloadingStrategy());
                configuration.addConfiguration(pc);
                logger.info("Loaded non-classpath config file " + fn);
            } catch (ConfigurationException e) {
                logger.warn("Config file " + fn + " not found");
            }//  w  w  w . ja v a  2 s.  c  o  m
        } else {
            logger.warn("Config file " + fn + " not found");
        }
    }
    // hostname-prefixed filename on classpath
    if (Context.getInstance().hasHostName()) {
        final String contextFilename = Context.getInstance().getHostName() + SEPARATOR + filename;
        addToCompositeConfig(contextFilename, false);
    }
    // env-prefixed filename on classpath
    if (Context.getInstance().hasEnv()) {
        final String contextFilename = Context.getInstance().getEnv() + SEPARATOR + filename;
        addToCompositeConfig(contextFilename, false);
    }
    // filename on classpath
    addToCompositeConfig(filename, !Context.getInstance().hasConfigPath()
            && !Context.getInstance().hasHostName() && !Context.getInstance().hasEnv());
}

From source file:cz.fi.muni.xkremser.editor.server.config.EditorConfigurationImpl.java

public EditorConfigurationImpl() {
    File dir = new File(WORKING_DIR);
    if (!dir.exists()) {
        boolean mkdirs = dir.mkdirs();
        if (!mkdirs) {
            LOGGER.error("cannot create directory '" + dir.getAbsolutePath() + "'");
            throw new RuntimeException("cannot create directory '" + dir.getAbsolutePath() + "'");
        }//from w  w w. ja  v a 2  s . c o  m
    }
    File confFile = new File(CONFIGURATION);
    if (!confFile.exists()) {
        try {
            confFile.createNewFile();
        } catch (IOException e) {
            LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
            throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'");
        }
        FileOutputStream confFos;
        try {
            confFos = new FileOutputStream(confFile);
        } catch (FileNotFoundException e) {
            LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
            throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'");
        }
        try {
            try {
                new Properties().store(confFos, "configuration file for module metadata editor");
            } catch (IOException e) {
                LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
                throw new RuntimeException(
                        "cannot create configuration file '" + confFile.getAbsolutePath() + "'");
            }
        } finally {
            try {
                if (confFos != null)
                    confFos.close();
            } catch (IOException e) {
                LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
                throw new RuntimeException(
                        "cannot create configuration file '" + confFile.getAbsolutePath() + "'");
            } finally {
                confFos = null;
            }
        }
    }
    File imagesDir = new File(DEFAULT_IMAGES_LOCATION);
    if (!imagesDir.exists()) {
        boolean mkdirs = imagesDir.mkdirs();
        if (!mkdirs) {
            LOGGER.error("cannot create directory '" + imagesDir.getAbsolutePath() + "'");
            throw new RuntimeException("cannot create directory '" + imagesDir.getAbsolutePath() + "'");
        }
    }

    CompositeConfiguration constconf = new CompositeConfiguration();
    PropertiesConfiguration file = null;
    try {
        file = new PropertiesConfiguration(confFile);
    } catch (ConfigurationException e) {
        LOGGER.error(e.getMessage(), e);
        new RuntimeException("cannot read configuration");
    }
    file.setReloadingStrategy(new FileChangedReloadingStrategy());
    constconf.addConfiguration(file);
    constconf.setProperty(ServerConstants.EDITOR_HOME, WORKING_DIR);
    this.configuration = constconf;
}

From source file:cz.mzk.editor.server.config.EditorConfigurationImpl.java

public EditorConfigurationImpl() {
    File dir = new File(WORKING_DIR);
    if (!dir.exists()) {
        boolean mkdirs = dir.mkdirs();
        if (!mkdirs) {
            LOGGER.error("cannot create directory '" + dir.getAbsolutePath() + "'");
            throw new RuntimeException("cannot create directory '" + dir.getAbsolutePath() + "'");
        }//  w ww .ja  v  a  2  s. c om
    }
    File confFile = new File(CONFIGURATION);
    if (!confFile.exists()) {
        try {
            confFile.createNewFile();
        } catch (IOException e) {
            LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
            throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'");
        }
        FileOutputStream confFos;
        try {
            confFos = new FileOutputStream(confFile);
        } catch (FileNotFoundException e) {
            LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
            throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'");
        }
        try {
            try {
                new Properties().store(confFos, "configuration file for module metadata editor");
            } catch (IOException e) {
                LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
                throw new RuntimeException(
                        "cannot create configuration file '" + confFile.getAbsolutePath() + "'");
            }
        } finally {
            try {
                if (confFos != null)
                    confFos.close();
            } catch (IOException e) {
                LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e);
                throw new RuntimeException(
                        "cannot create configuration file '" + confFile.getAbsolutePath() + "'");
            } finally {
                confFos = null;
            }
        }
    }

    CompositeConfiguration constconf = new CompositeConfiguration();
    PropertiesConfiguration file = null;
    try {
        file = new PropertiesConfiguration(confFile);
    } catch (ConfigurationException e) {
        LOGGER.error(e.getMessage(), e);
        new RuntimeException("cannot read configuration");
    }
    file.setReloadingStrategy(new FileChangedReloadingStrategy());
    constconf.addConfiguration(file);
    constconf.setProperty(ServerConstants.EDITOR_HOME, WORKING_DIR);
    this.configuration = constconf;

    String hostname = configuration.getString(EditorClientConfiguration.Constants.HOSTNAME, "editor.mzk.cz");
    if (hostname.contains("://")) {
        hostname = hostname.substring(hostname.indexOf("://") + "://".length());
    }
    File imagesDir = new File(ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator);
    if (!imagesDir.exists()) {
        boolean mkdirs = imagesDir.mkdirs();
        if (!mkdirs) {
            LOGGER.error("cannot create directory '" + imagesDir.getAbsolutePath() + "'");
            throw new RuntimeException("cannot create directory '" + imagesDir.getAbsolutePath() + "'");
        }
    }
    constconf.setProperty(ServerConstants.IMAGES_LOCATION,
            ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator);
    EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration();
    for (Iterator it = environmentConfiguration.getKeys(); it.hasNext();) {
        String key = (String) it.next();
        Object value = environmentConfiguration.getProperty(key);
        key = key.replaceAll("_", ".");
        key = key.replaceAll("\\.\\.", "__");
        constconf.addProperty(key, value);
    }
}