Java Code Examples for org.apache.commons.configuration.PropertiesConfiguration#setReloadingStrategy()

The following examples show how to use org.apache.commons.configuration.PropertiesConfiguration#setReloadingStrategy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelegatedAccessDaoImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Loads our SQL statements from the appropriate properties file
 
 * @param vendor	DB vendor string. Must be one of mysql, oracle, hsqldb
 */
private void initStatements(String vendor) {
	
	URL url = getClass().getClassLoader().getResource(vendor + ".properties"); 
	
	try {
		statements = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
		statements.setReloadingStrategy(new InvariantReloadingStrategy());	//don't watch for reloads
		statements.setThrowExceptionOnMissing(true);	//throw exception if no prop
		statements.setDelimiterParsingDisabled(true); //don't split properties
		statements.load(url); //now load our file
	} catch (ConfigurationException e) {
		log.error(e.getClass() + ": " + e.getMessage(), e);
		return;
	}
}
 
Example 2
Source File: DelegatedAccessDaoImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Loads our SQL statements from the appropriate properties file
 
 * @param vendor	DB vendor string. Must be one of mysql, oracle, hsqldb
 */
private void initStatements(String vendor) {
	
	URL url = getClass().getClassLoader().getResource(vendor + ".properties"); 
	
	try {
		statements = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
		statements.setReloadingStrategy(new InvariantReloadingStrategy());	//don't watch for reloads
		statements.setThrowExceptionOnMissing(true);	//throw exception if no prop
		statements.setDelimiterParsingDisabled(true); //don't split properties
		statements.load(url); //now load our file
	} catch (ConfigurationException e) {
		log.error(e.getClass() + ": " + e.getMessage(), e);
		return;
	}
}
 
Example 3
Source File: PlatformConfiguration.java    From dpCms with Apache License 2.0 5 votes vote down vote up
private PlatformConfiguration(){
	try {
		config = new PropertiesConfiguration("platform.properties");
		config.setReloadingStrategy(new FileChangedReloadingStrategy());			
	} catch (ConfigurationException e) {
		e.printStackTrace();
	}  
}
 
Example 4
Source File: ReloadablePropertySourceTest.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a new properties configuration that will re-load the properties from a file every time it is called.
 *
 * @return the properties configuration.
 * @throws ConfigurationException if the properties configuration couldn't be created.
 */
private PropertiesConfiguration getNewPropertiesConfiguration() throws ConfigurationException
{
    // Create a new properties configuration.
    // We are using this instead of a database configuration for easier testing.
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(propertiesFile);

    // Create a reloading strategy that will always reload when asked.
    // There were some problems using the FileChangedReloadingStrategy where it wasn't detecting changed files and causing some methods in this
    // JUnit to fail.
    propertiesConfiguration.setReloadingStrategy(new ReloadingStrategy()
    {
        @Override
        public void setConfiguration(FileConfiguration configuration)
        {
        }

        @Override
        public void init()
        {
        }

        @Override
        public boolean reloadingRequired()
        {
            // Tell the caller that the properties should always be reloaded.
            return true;
        }

        @Override
        public void reloadingPerformed()
        {
        }
    });

    return propertiesConfiguration;
}
 
Example 5
Source File: TutorialEntityProviderImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void initConfig() {
	
	URL url = getClass().getClassLoader().getResource("Tutorial.config"); 
	
	try {
		tutorialProps = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
		tutorialProps.setReloadingStrategy(new InvariantReloadingStrategy());	//don't watch for reloads
		tutorialProps.setThrowExceptionOnMissing(false);	//throw exception if no prop
		tutorialProps.setDelimiterParsingDisabled(true); //don't split properties
		tutorialProps.load(url); //now load our file
	} catch (ConfigurationException e) {
		log.error(e.getClass() + ": " + e.getMessage());
		return;
	}
}
 
Example 6
Source File: MessageResources.java    From unitime with Apache License 2.0 5 votes vote down vote up
private Configuration getConfiguration(String name) {
	Configuration configuration = null;
	URL url = Thread.currentThread().getContextClassLoader().getResource(name);
	if (url != null) {
		PropertiesConfiguration pc = new PropertiesConfiguration();
		pc.setURL(url);
		
		// Set reloading strategy 
		String dynamicReload = ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload", null);
		if (dynamicReload!=null && dynamicReload.equalsIgnoreCase("true")) {
			long refreshDelay = Constants.getPositiveInteger(
					ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload_interval"), 15000 );
			
			FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
			strategy.setRefreshDelay(refreshDelay); 
			pc.setReloadingStrategy(strategy);
			
			pc.addConfigurationListener(new MessageResourcesCfgListener(pc.getBasePath()));
		}			
		
		try {
			pc.load();
			configuration = pc;
		} catch (ConfigurationException e) {
			Debug.error("Message Resources configuration exception: " + e.getMessage());
		}
	}

	return configuration;
}
 
Example 7
Source File: TutorialEntityProviderImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void initConfig() {
	
	URL url = getClass().getClassLoader().getResource("Tutorial.config"); 
	
	try {
		tutorialProps = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
		tutorialProps.setReloadingStrategy(new InvariantReloadingStrategy());	//don't watch for reloads
		tutorialProps.setThrowExceptionOnMissing(false);	//throw exception if no prop
		tutorialProps.setDelimiterParsingDisabled(true); //don't split properties
		tutorialProps.load(url); //now load our file
	} catch (ConfigurationException e) {
		log.error(e.getClass() + ": " + e.getMessage());
		return;
	}
}
 
Example 8
Source File: PropertiesConfigurationProperties.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
private static PropertiesConfiguration initPropertiesConfiguration( FileObject fileObject )
  throws FileSystemException, ConfigurationException {
  PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration( fileObject.getURL() );
  propertiesConfiguration.setAutoSave( true );
  FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
  fileChangedReloadingStrategy.setRefreshDelay( 1000L );
  propertiesConfiguration.setReloadingStrategy( fileChangedReloadingStrategy );
  return propertiesConfiguration;
}
 
Example 9
Source File: SpringBootPropertiesApplication.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnProperty(name = "spring.config.location", matchIfMissing = false)
public PropertiesConfiguration propertiesConfiguration(
  @Value("${spring.config.location}") String path,
  @Value("${spring.properties.refreshDelay}") long refreshDelay) throws Exception {
    String filePath = path.substring("file:".length());
    PropertiesConfiguration configuration = new PropertiesConfiguration(new File(filePath).getCanonicalPath());
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(refreshDelay);
    configuration.setReloadingStrategy(fileChangedReloadingStrategy);
    return configuration;
}