Package org.n52.faroe.json
Class JsonConfiguration
- java.lang.Object
-
- org.n52.faroe.json.JsonConfiguration
-
- All Implemented Interfaces:
com.google.common.base.Supplier<com.fasterxml.jackson.databind.node.ObjectNode>,Supplier<com.fasterxml.jackson.databind.node.ObjectNode>,javax.inject.Provider<com.fasterxml.jackson.databind.node.ObjectNode>,FileSettingsConfiguration,Destroyable,Producer<com.fasterxml.jackson.databind.node.ObjectNode>
public class JsonConfiguration extends Object implements Destroyable, Producer<com.fasterxml.jackson.databind.node.ObjectNode>, FileSettingsConfiguration
Class to encapsulate writes and reads to a JSON file.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor Description JsonConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()Deletes the configuration file if it exists.voiddestroy()Destroys this configuration by executing any pending write.com.fasterxml.jackson.databind.node.ObjectNodeget()Gets the (possibly empty) configuration JSON node.PathgetPath()voidinit()Initializes this configuration by initializing aDebouncerfor writes and reading the configuration file.LockreadLock()Gets the read lock for this configuration.voidrefresh()Refreshes the configuration from disk.voidscheduleWrite()Schedule a write.voidset(com.fasterxml.jackson.databind.node.ObjectNode configuration)Set the configurationvoidsetConfigLocationProvider(ConfigLocationProvider configLocationProvider)Sets the configuration location provider.voidsetFileName(String fileName)Sets the file name of this configuration.voidsetReadonly(boolean readonly)Sets the flag to persist or not persist the settings, e.g. settings defined externallyvoidsetWriteTimeout(int writeTimeout)Sets the time to wait for additional changes before the configuration is persisted.StringtoString()LockwriteLock()Gets the write lock for this configuration.voidwriteNow()Do not wait, but persist the settings right now.
-
-
-
Method Detail
-
init
public void init()
Initializes this configuration by initializing aDebouncerfor writes and reading the configuration file.
-
refresh
public void refresh()
Refreshes the configuration from disk.- Specified by:
refreshin interfaceFileSettingsConfiguration
-
destroy
public void destroy()
Destroys this configuration by executing any pending write.- Specified by:
destroyin interfaceDestroyable- See Also:
Debouncer.finish()
-
delete
public void delete()
Deletes the configuration file if it exists.
-
get
public com.fasterxml.jackson.databind.node.ObjectNode get()
Gets the (possibly empty) configuration JSON node.- Specified by:
getin interfaceProducer<com.fasterxml.jackson.databind.node.ObjectNode>- Specified by:
getin interfacejavax.inject.Provider<com.fasterxml.jackson.databind.node.ObjectNode>- Specified by:
getin interfacecom.google.common.base.Supplier<com.fasterxml.jackson.databind.node.ObjectNode>- Specified by:
getin interfaceSupplier<com.fasterxml.jackson.databind.node.ObjectNode>- Returns:
- the node (never
null)
-
set
public void set(com.fasterxml.jackson.databind.node.ObjectNode configuration)
Set the configuration- Parameters:
configuration- the configuration
-
setWriteTimeout
public void setWriteTimeout(int writeTimeout)
Sets the time to wait for additional changes before the configuration is persisted.- Parameters:
writeTimeout- the time out in milliseconds
-
setReadonly
public void setReadonly(boolean readonly)
Sets the flag to persist or not persist the settings, e.g. settings defined externally- Parameters:
readonly- the flag to persist settings or not
-
setFileName
public void setFileName(String fileName)
Sets the file name of this configuration.- Parameters:
fileName- the file name
-
setConfigLocationProvider
public void setConfigLocationProvider(ConfigLocationProvider configLocationProvider)
Sets the configuration location provider.- Parameters:
configLocationProvider- the provider
-
readLock
public Lock readLock()
Gets the read lock for this configuration.- Returns:
- the (reentrant) read lock
-
writeLock
public Lock writeLock()
Gets the write lock for this configuration.- Returns:
- the (reentrant) write lock
-
scheduleWrite
public void scheduleWrite()
Schedule a write. This will be executed after the configuredtimeoutif no further writes are scheduled, else it will postponed until their are no further requests fortimeoutmilliseconds.- See Also:
Debouncer.call()
-
writeNow
public void writeNow()
Do not wait, but persist the settings right now.
-
getPath
public Path getPath()
- Specified by:
getPathin interfaceFileSettingsConfiguration
-
-