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.Properties
A 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
_savePaused
protected int
maxStorageFrequencyMS
protected boolean
writeQueued
protected java.lang.Thread
writeThread
-
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 void
copyFile(java.io.File source, java.io.File dest)
java.io.File
getFile()
int
getMaxStorageFrequencyMS()
Returns the maximum rate at which the file will be written.java.io.File
getTempFile()
boolean
isNew()
java.util.Set<java.lang.Object>
keySet()
protected void
potentiallyExecuteWrite()
java.lang.Object
remove(java.lang.Object key)
java.lang.Object
removeIntermediate(java.lang.Object key)
void
setMaxStorageFrequencyMS(int maxStorageFrequencyMS)
Sets the maximum rate at which the file will be written.java.lang.Object
setProperty(java.lang.String key, java.lang.String value)
java.lang.Object
setPropertyIntermediate(java.lang.String key, java.lang.String value)
Sets a property without pesisting the change.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 fileprotected void
tryLoad(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.IOException
Creates 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.IOException
Tries 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:
remove
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
remove
in classjava.util.Properties
-
setProperty
public java.lang.Object setProperty(java.lang.String key, java.lang.String value)
- Overrides:
setProperty
in 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:
keySet
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
keySet
in 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
-
-