Class PersistentProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- com.inductiveautomation.ignition.common.PersistentProperties
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.Object,java.lang.Object>
public class PersistentProperties extends java.util.PropertiesA simple extension of properties that is meant to represent a file based property file. The entire property file will be written eventually after a call to setProperty(), according to the max storage frequency.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_savePausedprotected intmaxStorageFrequencyMSprotected booleanwriteQueuedprotected java.lang.ThreadwriteThread
-
Constructor Summary
Constructors Constructor Description PersistentProperties()PersistentProperties(java.io.File file, java.lang.String comments)PersistentProperties(java.io.File file, java.lang.String comments, boolean requireInitial)Creates a new PersistentProperties object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcopyFile(java.io.File source, java.io.File dest)java.io.FilegetFile()intgetMaxStorageFrequencyMS()Returns the maximum rate at which the file will be written.java.io.FilegetTempFile()booleanisNew()java.util.Set<java.lang.Object>keySet()protected voidpotentiallyExecuteWrite()java.lang.Objectremove(java.lang.Object key)java.lang.ObjectremoveIntermediate(java.lang.Object key)voidsetMaxStorageFrequencyMS(int maxStorageFrequencyMS)Sets the maximum rate at which the file will be written.java.lang.ObjectsetProperty(java.lang.String key, java.lang.String value)java.lang.ObjectsetPropertyIntermediate(java.lang.String key, java.lang.String value)Sets a property without pesisting the change.voidstoreChanges()Do the following to ensure there is always a well-formed file on the HD Write file to temp file Copy temp file to main fileprotected voidtryLoad(java.io.File file)Tries to call super.loadFromXML with an input stream from this file.-
Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, save, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
-
-
-
Constructor Detail
-
PersistentProperties
public PersistentProperties(java.io.File file, java.lang.String comments) throws java.io.IOException- Throws:
java.io.IOException
-
PersistentProperties
public PersistentProperties(java.io.File file, java.lang.String comments, boolean requireInitial) throws java.io.IOExceptionCreates a new PersistentProperties object. The backup file will be "."+filename+".bak" and the clean file will be filename+"_clean".- Parameters:
requireInitial- Whether or not a valid file or _clean file is required. If false, the constructor will accept the situation where none of the 3 files exist.- Throws:
java.io.IOException
-
PersistentProperties
public PersistentProperties()
-
-
Method Detail
-
getMaxStorageFrequencyMS
public int getMaxStorageFrequencyMS()
Returns the maximum rate at which the file will be written. After a property is set, the file is written immediately, unless the specified time has not passed, in which case the file will be marked as "dirty" and written when the delay expires.Defaults to 500ms.
-
setMaxStorageFrequencyMS
public void setMaxStorageFrequencyMS(int maxStorageFrequencyMS)
Sets the maximum rate at which the file will be written. If 0, writes will occur immediately, and in the same thread, instead of asynchronously.
-
isNew
public boolean isNew()
-
getFile
public java.io.File getFile()
-
getTempFile
public java.io.File getTempFile()
-
tryLoad
protected void tryLoad(java.io.File file) throws java.io.IOExceptionTries to call super.loadFromXML with an input stream from this file.- Throws:
java.io.IOException- if anything goes wrong with the load.
-
removeIntermediate
public java.lang.Object removeIntermediate(java.lang.Object key)
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
removein classjava.util.Properties
-
setProperty
public java.lang.Object setProperty(java.lang.String key, java.lang.String value)- Overrides:
setPropertyin classjava.util.Properties
-
setPropertyIntermediate
public java.lang.Object setPropertyIntermediate(java.lang.String key, java.lang.String value)Sets a property without pesisting the change.
-
keySet
public java.util.Set<java.lang.Object> keySet()
- Specified by:
keySetin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
keySetin classjava.util.Properties
-
storeChanges
public void storeChanges()
Do the following to ensure there is always a well-formed file on the HD- Write file to temp file
- Copy temp file to main file
-
potentiallyExecuteWrite
protected void potentiallyExecuteWrite()
-
copyFile
protected void copyFile(java.io.File source, java.io.File dest) throws java.io.IOException- Throws:
java.io.IOException
-
-