Example usage for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy

List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy

Introduction

In this page you can find the example usage for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy.

Prototype

FileChangedReloadingStrategy

Source Link

Usage

From source file:com.github.rnewson.couchdb.lucene.Main.java

/**
 * Run couchdb-lucene.// www.  j av  a  2 s .co  m
 */
public static void main(String[] args) throws Exception {
    final HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(
            Main.class.getClassLoader().getResource("couchdb-lucene.ini"));
    configuration.setReloadingStrategy(new FileChangedReloadingStrategy());

    final File dir = new File(configuration.getString("lucene.dir", "indexes"));

    if (dir == null) {
        LOG.error("lucene.dir not set.");
        System.exit(1);
    }
    if (!dir.exists() && !dir.mkdir()) {
        LOG.error("Could not create " + dir.getCanonicalPath());
        System.exit(1);
    }
    if (!dir.canRead()) {
        LOG.error(dir + " is not readable.");
        System.exit(1);
    }
    if (!dir.canWrite()) {
        LOG.error(dir + " is not writable.");
        System.exit(1);
    }
    LOG.info("Index output goes to: " + dir.getCanonicalPath());

    final Server server = new Server();
    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setHost(configuration.getString("lucene.host", "localhost"));
    connector.setPort(configuration.getInt("lucene.port", 5985));

    LOG.info("Accepting connections with " + connector);

    server.setConnectors(new Connector[] { connector });
    server.setStopAtShutdown(true);
    server.setSendServerVersion(false);

    HttpClientFactory.setIni(configuration);
    final HttpClient httpClient = HttpClientFactory.getInstance();

    final LuceneServlet servlet = new LuceneServlet(httpClient, dir, configuration);

    final Context context = new Context(server, "/", Context.NO_SESSIONS | Context.NO_SECURITY);
    context.addServlet(new ServletHolder(servlet), "/*");
    context.addFilter(new FilterHolder(new GzipFilter()), "/*", Handler.DEFAULT);
    context.setErrorHandler(new JSONErrorHandler());
    server.setHandler(context);

    server.start();
    server.join();
}

From source file:com.pse.fotoz.helpers.Configuration.ConfigurationManager.java

public static void initConfig() {
    try {// www  . ja  va2s . c  o  m
        config = new XMLConfiguration("application.cfg.xml");
        configPasswords = new XMLConfiguration("passwords.cfg.xml");
    } catch (ConfigurationException ex) {
        Logger.getLogger(ConfigurationManager.class.getName()).log(Level.SEVERE, null, ex);
    }
    FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
    strategy.setRefreshDelay(reloadDelayMS);
    config.setReloadingStrategy(strategy);
    config.setValidating(true); //valideer de xml
}

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

/**
 * Get plugin configuration.// w  ww.j  a  v a 2s .c om
 *
 * @param inPlugin
 *            input plugin
 * @return plugin configuration
 */
public static XMLConfiguration getPluginConfig(IPlugin inPlugin) {
    String file = "plugin_" + inPlugin.getClass().getSimpleName() + ".xml";
    XMLConfiguration config;
    try {
        config = new XMLConfiguration(ConfigCore.getKitodoConfigDirectory() + file);
    } catch (ConfigurationException e) {
        logger.error(e);
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());
    return config;
}

From source file:com.weibo.datasys.common.conf.ConfigFactory.java

public static void init(String configFilePath) {
    // ??//from   w ww  . j  a v  a  2 s.  c  om
    if (configFilePath == null) {
        configFilePath = CONFIG_FILE_DEFAULT_PATH;
    }
    try {
        System.out.println(new Date() + " - [ConfigInit] - ConfigPath= " + configFilePath);
        config = new XMLConfiguration(configFilePath);
        config.setReloadingStrategy(new FileChangedReloadingStrategy());
        configDirPath = new File(configFilePath).getParentFile();
    } catch (ConfigurationException e) {
        System.out.println(new Date() + " - [FatalError] - Init ConfigFactory Error. System Exit.");
        System.exit(1);
    }
}

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  w  w . j  a  v a  2 s.  c o m*/
                    initialized = new PropertiesConfiguration();
                }
                initialized.setListDelimiter('&');
                initialized.setReloadingStrategy(new FileChangedReloadingStrategy());
                config = initialized;
            }
        }
    }
    return config;
}

From source file:de.unigoettingen.sub.search.opac.ConfigOpac.java

private static XMLConfiguration getConfig() throws FileNotFoundException {
    if (Objects.nonNull(config)) {
        return config;
    }//from  w w  w .j  a va  2  s  .co m

    KitodoConfigFile opacConfiguration = KitodoConfigFile.OPAC_CONFIGURATION;

    if (!opacConfiguration.exists()) {
        throw new FileNotFoundException("File not found: " + opacConfiguration.getAbsolutePath());
    }
    try {
        config = new XMLConfiguration(opacConfiguration.getFile());
    } catch (ConfigurationException e) {
        logger.error(e.getMessage(), e);
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());
    return config;
}

From source file:net.jforum.util.JForumConfig.java

public JForumConfig(ServletContext servletContext, SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
    this.setReloadingStrategy(new FileChangedReloadingStrategy());
    this.setDelimiterParsingDisabled(true);

    try {//ww w. ja v  a2  s . c o  m
        loadProps();
        if (servletContext != null) {
            setProperty(ConfigKeys.APPLICATION_PATH, servletContext.getRealPath(""));
        }
        loadDatabaseProperties();
        normalizeTemplateDirectory();
    } catch (Exception e) {
        throw new ForumException(e);
    }
}

From source file:com.github.rnewson.couchdb.lucene.Config.java

public Config() throws ConfigurationException {
    this.configuration = new HierarchicalINIConfiguration(
            Config.class.getClassLoader().getResource(CONFIG_FILE));
    this.configuration.setReloadingStrategy(new FileChangedReloadingStrategy());
}

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

public static PropertiesConfiguration getConfig(String basePath, Class clazze) {
    PropertiesConfiguration pc = null;/*from  www  .  j a  v  a 2 s.  c  o  m*/

    String className = clazze.getSimpleName();

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

    try {

        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:com.intuit.tank.vm.settings.BaseCommonsXmlConfig.java

/**
 * Constructor pulls file out of the jar or reads from disk and sets up refresh policy.
 * /*from w w w .  j  a  va  2s .  c  om*/
 * @param expressionEngine
 *            the expression engine to use. Null results in default expression engine
 */
protected void readConfig() {
    try {
        ExpressionEngine expressionEngine = new XPathExpressionEngine();
        String configPath = getConfigName();
        FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();

        File dataDirConfigFile = new File(configPath);
        //            LOG.info("Reading settings from " + dataDirConfigFile.getAbsolutePath());
        if (!dataDirConfigFile.exists()) {
            // Load a default from the classpath:
            // Note: we don't let new XMLConfiguration() lookup the resource
            // url directly because it may not be able to find the desired
            // classloader to load the URL from.
            URL configResourceUrl = this.getClass().getClassLoader().getResource(configPath);
            if (configResourceUrl == null) {
                throw new RuntimeException("unable to load resource: " + configPath);
            }

            XMLConfiguration tmpConfig = new XMLConfiguration(configResourceUrl);
            // Copy over a default configuration since none exists:
            // Ensure data dir location exists:
            if (dataDirConfigFile.getParentFile() != null && !dataDirConfigFile.getParentFile().exists()
                    && !dataDirConfigFile.getParentFile().mkdirs()) {
                throw new RuntimeException("could not create directories.");
            }
            tmpConfig.save(dataDirConfigFile);
            LOG.info("Saving settings file to " + dataDirConfigFile.getAbsolutePath());
        }

        if (dataDirConfigFile.exists()) {
            config = new XMLConfiguration(dataDirConfigFile);
        } else {
            // extract from jar and write to
            throw new IllegalStateException("Config file does not exist or cannot be created");
        }
        if (expressionEngine != null) {
            config.setExpressionEngine(expressionEngine);
        }
        configFile = dataDirConfigFile;
        // reload at most once per thirty seconds on configuration queries.
        config.setReloadingStrategy(reloadingStrategy);
        initConfig(config);
    } catch (ConfigurationException e) {
        LOG.error("Error reading settings file: " + e, e);
        throw new RuntimeException(e);
    }
}