|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.olat.core.logging.LogDelegator
org.olat.core.configuration.PersistedProperties
public class PersistedProperties
Description:
The PersistedProperties features reading and writing of configuration
properties from and to properties files for module and application
configuration.
The idea is that the system can be configured with default values within the
module code either by a spring configuration or by using hardcoded default
values. Those default values are overridden by the values stored in the
properties files found in the user space of the system (
olatdata/system/configuration/fully.qualified.ClassName.properties
). Installing updates will not overwrite those properties files, the 'old'
configuration is available immediately to the sytem without reconfiguration.
The developer should provide a GUI for each of those values that can be configured at runtime. It is up to the programmer if the system needs a reboot or not.
After constructing an instance of this class the setXXXPropertyDefault() methods must be called to set the default values in case no user configuration is found. This is where you can set the values you get from the spring or the old olat_config.xml module configuration.
After the default values have been set, using the getXXXPropertyValue() you will get the current configuration value. The PersistedProperties class will first look in properties from the filesystem and if nothing found, use the setted default values.
The class does also provide setXXXProperty() methods. Setting a property will
store it always in the user space properties file
olatdata/system/configuration/fully.qualified.ClassName.properties
. It will not modify any spring or olat_config.xml file. The setter methods
can be stored immediately after each set or remain transient until the
explicit savePropertiesAndFireChangedEvent() method is called.
To work properly in a cluster environment, the class will fire a PersitedPropertiesChangedEvent at the end of each save cycle. This event must be catched by the class that is using this PersistingProperties. When constructing the PersistingProperties, a reference to the using class must be provided. The PersistingProperties deals with registering and unregistering of the event listeners for the multi-node events, this is hidden to the using class.
When finished, the destroy() method must be called. In most cases this will be at system shutdown time.
NOTE 1: By replacing the OLAT code with a new version all configurations made will remain since the configuration is stored in the user space and not in the OLAT web application directory. This greatly simplifies upgrading without reconfiguring everything.
NOTE 2: When you saved a configuration using the set and save methods in this class, the default configuration in your olat_config.xml or spring configuration becomes irrelevant. Changing the values in olat_config.xml or your spring file will have no effect whatsoever.
NOTE 3: At any time, the configuration properties files at
olatdata/system/configuration/ can be deleted. The system then
uses the default values provided in your olat_confix.xml, your spring
configuration or your hardcoded default values provided at init time.
NOTE 4: As a developer you must decide if a configuration can be reflected in realtime or if you must reboot the system. In the first case you can savely use the getter methods to read the configuration every time you need the value, in the second case you should make a copy of the configuration value at init time and operate only with the copy.
NOTE 5: In extreme conditions the get/set methods might not be cluster save. Make sure you use a cluster wide GUI lock in the admin interfaces that makes use of the setter methods and you are on the save side. On the other hand it is very unlikely that something really bad happens, the properties files are just overwritten by the next save.
Initial Date: 01.10.2007
| Constructor Summary | |
|---|---|
PersistedProperties(GenericEventListener propertiesChangedEventListener)
Constructor for a PersistedProperties object. |
|
| Method Summary | |
|---|---|
void |
clearAndSaveProperties()
Clear the properties and save the empty properties to the file system. |
java.util.Properties |
createPropertiesFromPersistedProperties()
Clone the persisted properties to a standard properties object. |
void |
destroy()
Call this method when the PersitedProperties is not used anymore. |
boolean |
getBooleanPropertyValue(java.lang.String propertyName)
Return a boolean value for certain propertyName |
int |
getIntPropertyValue(java.lang.String propertyName)
Retrun an int value for a certain propertyName |
java.lang.String |
getStringPropertyValue(java.lang.String propertyName,
boolean allowEmptyString)
Return a string value for certain propertyName-parameter. |
void |
savePropertiesAndFireChangedEvent()
Save the properties configuration to disk and notify other nodes about change. |
void |
setBooleanProperty(java.lang.String propertyName,
boolean value,
boolean saveConfiguration)
Set a boolean property |
void |
setBooleanPropertyDefault(java.lang.String propertyName,
boolean value)
Set a default value for a boolean property |
void |
setIntProperty(java.lang.String propertyName,
int value,
boolean saveConfiguration)
Set an int property |
void |
setIntPropertyDefault(java.lang.String propertyName,
int value)
Set a default value for an integer property |
void |
setStringProperty(java.lang.String propertyName,
java.lang.String value,
boolean saveConfiguration)
Set a string property |
void |
setStringPropertyDefault(java.lang.String propertyName,
java.lang.String value)
Set a default value for a string property |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PersistedProperties(GenericEventListener propertiesChangedEventListener)
propertiesChangedEventListener - | Method Detail |
|---|
public final void destroy()
public int getIntPropertyValue(java.lang.String propertyName)
propertyName -
public java.lang.String getStringPropertyValue(java.lang.String propertyName,
boolean allowEmptyString)
propertyName - allowEmptyString - true: empty strings are valid values; false: emtpy
strings are discarded
public boolean getBooleanPropertyValue(java.lang.String propertyName)
propertyName -
public void setStringProperty(java.lang.String propertyName,
java.lang.String value,
boolean saveConfiguration)
propertyName - The keyvalue - The ValuesaveConfiguration - true: will save property and fire event; false:
will not save, but set a dirty flag
public void setIntProperty(java.lang.String propertyName,
int value,
boolean saveConfiguration)
propertyName - The keyvalue - The ValuesaveConfiguration - true: will save property and fire event; false:
will not save, but set a dirty flag
public void setBooleanProperty(java.lang.String propertyName,
boolean value,
boolean saveConfiguration)
propertyName - The keyvalue - The ValuesaveConfiguration - true: will save property and fire event; false:
will not save, but set a dirty flag
public void setStringPropertyDefault(java.lang.String propertyName,
java.lang.String value)
propertyName - value -
public void setIntPropertyDefault(java.lang.String propertyName,
int value)
propertyName - value -
public void setBooleanPropertyDefault(java.lang.String propertyName,
boolean value)
propertyName - value - public void savePropertiesAndFireChangedEvent()
public void clearAndSaveProperties()
public java.util.Properties createPropertiesFromPersistedProperties()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||