List of usage examples for org.apache.commons.configuration FileConfiguration getFileName
String getFileName();
From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java
@VisibleForTesting void reload() {//from w w w.j a v a 2 s. c om // No-op if already loaded. if (!initConfig()) { return; } // Reload if config exists. Set<String> confKeys = Sets.newHashSet(); for (FileConfiguration fileConfig : fileConfigs) { LOG.debug("Check and reload config, file={}, lastModified={}", fileConfig.getFile(), fileConfig.getFile().lastModified()); fileConfig.reload(); // load keys Iterator keyIter = fileConfig.getKeys(); while (keyIter.hasNext()) { String key = (String) keyIter.next(); confKeys.add(key); } } // clear unexisted keys Iterator viewIter = viewConfig.getKeys(); while (viewIter.hasNext()) { String key = (String) viewIter.next(); if (!confKeys.contains(key)) { clearViewProperty(key); } } LOG.info("Reload features : {}", confKeys); // load keys from files for (FileConfiguration fileConfig : fileConfigs) { try { loadView(fileConfig); } catch (Exception ex) { if (!fileNotFound(ex)) { LOG.error("Config reload failed for file {}", fileConfig.getFileName(), ex); } } } for (ConfigurationListener listener : confListeners) { listener.onReload(viewConfig); } }
From source file:nl.isaac.dotcms.plugin.configuration.ConfigurationService.java
/** * This method deals with constructing a key for the specified configuration, checking the cache and if it isn't in the cache constructing (and caching) it. * * @param hostName// w w w. j a v a 2 s.c o m * @param ipAddress * @param sessionId * @param pluginName * @param configurationLocation * @return * @throws ConfigurationException */ private static CustomConfiguration retrieveFromCacheOrCreateConfiguration(String keyPrefix, String hostName, String ipAddress, String sessionId, String pluginName, String configurationLocation) throws ConfigurationException { if (ConfigurationDotCMSCacheGroupHandler.isFlushed()) { clearCache(); ConfigurationDotCMSCacheGroupHandler.setLoaded(); } String key; final String basicKey = keyPrefix + hostName; // On Windows the : character is not allowed, replace it with _ if (ipAddress != null) { ipAddress = ipAddress.replace(':', '_'); } if (cacheOnIp) { String ipKey = basicKey + '_' + ipAddress + '_' + sessionId; if (!ipForwardCache.contains(ipKey)) { key = ipKey; } else { key = basicKey; } } else { key = basicKey; } Logger.debug(ConfigurationService.class, "Looking up configuration under key: " + key); CustomConfiguration conf = serverCache.get(key); if (conf != null) { return conf; } Logger.debug(ConfigurationService.class, "Loading configuration for key: " + key); Map<String, String> interpolationValues = new HashMap<String, String>(); final Bundle bundle; interpolationValues.put("hostName", hostName); if (pluginName != null && pluginName.startsWith("osgi/")) { //This is an OSGi plugin String[] splitPluginName = pluginName.split("/"); interpolationValues.put("pluginName", splitPluginName[1]); if (splitPluginName.length > 2) { long bundleId = Long.valueOf(splitPluginName[2]); bundle = OSGIProxyServlet.bundleContext.getBundle(bundleId); } else { // If we didn't get a bundleId we need to search for it, somewhat slower, but the result is cached bundle = searchBundles(splitPluginName[1]); } } else { if (pluginName != null) { interpolationValues.put("pluginName", pluginName); } bundle = null; } // We only do ip specific things on DEV (and local of course!) if (cacheOnIp && ipAddress != null) { interpolationValues.put("ClientIPAddress", ipAddress); } Map<String, StrLookup> interpolators = new HashMap<String, StrLookup>(); interpolators.put("param", StrLookup.mapLookup(interpolationValues)); DotCMSFileConfigurationProvider dotCmsProvider = new DotCMSFileConfigurationProvider(hostName); Map<String, ConfigurationProvider> providers = new HashMap<String, ConfigurationProvider>(); providers.put("dotcms", dotCmsProvider); OSGiFileConfigurationProvider osgiProvider = new OSGiFileConfigurationProvider(bundle); providers.put("osgi", osgiProvider); conf = ConfigurationFactory.createConfiguration(key, configurationLocation, interpolators, providers); boolean isIpSpecific = false; if (cacheOnIp && ipAddress != null) { for (FileConfiguration fileConf : conf.getLoadedFileConfigurations()) { if (fileConf.getFileName() != null && fileConf.getFileName().contains(ipAddress)) { isIpSpecific = true; return conf; } } } if (isIpSpecific) { ConfigurationParameters params = defaultParameters.get(); if (params != null) { params.addConfigurationToSession(key); } } if (cacheOnIp && !isIpSpecific) { ipForwardCache.add(key); if (serverCache.contains(basicKey)) { return serverCache.get(basicKey); } else { key = basicKey; } } Logger.debug(ConfigurationService.class, "Created a new configuration! " + key); serverCache.put(key, conf); return conf; }
From source file:org.betaconceptframework.astroboa.engine.definition.ContentDefinitionConfiguration.java
private boolean mustReloadDefinitionFiles(CmsRepository associatedRepository) { //Check reload flag with default value set to false if (isCmsInProductionMode()) { if (definitionFileConfigurations != null && CollectionUtils.isNotEmpty(definitionFileConfigurations.get(associatedRepository.getId()))) { return false; } else {/* w ww . j a v a 2s .c o m*/ return true; } } //Debug mode else if (configuration != null) { final boolean reloadDefinitionFiles = configuration .getBoolean(CmsConstants.RELOAD_CONTENT_DEFINITION_FILE, false); //Reloading has been disabled but no definition files have ever been loaded //It may be the first time if (!reloadDefinitionFiles && (definitionFileConfigurations == null || !definitionFileConfigurations.containsKey(associatedRepository.getId()))) { return true; } if (reloadDefinitionFiles && definitionFileConfigurations != null) { List<FileConfiguration> repositoryFileConfigurations = definitionFileConfigurations .get(associatedRepository.getId()); if (repositoryFileConfigurations == null) { return true; } //Check if any file has been added or removed //Get files that exist in definition directory File[] definitionSchemaFiles = retrieveXmlSchemaFiles(associatedRepository, false); //At least one definition was added or removed if (repositoryFileConfigurations.size() != definitionSchemaFiles.length) { return true; } //Reload flag is set to true. Check that file is changed boolean atLeastOneFileChanged = false; for (FileConfiguration fileConf : repositoryFileConfigurations) { if (fileConf.getReloadingStrategy().reloadingRequired()) { fileConf.getReloadingStrategy().reloadingPerformed(); logger.info("Definition file {} has been modified and will be reloaded for repository {}", fileConf.getFileName(), associatedRepository.getId()); atLeastOneFileChanged = true; break; } } return atLeastOneFileChanged; } } return false; }