Class JsonConfiguration

java.lang.Object
org.n52.faroe.json.JsonConfiguration
All Implemented Interfaces:
com.google.common.base.Supplier<com.fasterxml.jackson.databind.node.ObjectNode>, jakarta.inject.Provider<com.fasterxml.jackson.databind.node.ObjectNode>, Supplier<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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes the configuration file if it exists.
    void
    Destroys this configuration by executing any pending write.
    com.fasterxml.jackson.databind.node.ObjectNode
    get()
    Gets the (possibly empty) configuration JSON node.
     
    void
    Initializes this configuration by initializing a Debouncer for writes and reading the configuration file.
    Gets the read lock for this configuration.
    void
    Refreshes the configuration from disk.
    void
    Schedule a write.
    void
    set(com.fasterxml.jackson.databind.node.ObjectNode configuration)
    Set the configuration
    void
    Sets the configuration location provider.
    void
    setFileName(String fileName)
    Sets the file name of this configuration.
    void
    setReadonly(boolean readonly)
    Sets the flag to persist or not persist the settings, e.g.
    void
    setWriteTimeout(int writeTimeout)
    Sets the time to wait for additional changes before the configuration is persisted.
     
    Gets the write lock for this configuration.
    void
    Do not wait, but persist the settings right now.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.google.common.base.Supplier

    equals
  • Constructor Details

    • JsonConfiguration

      public JsonConfiguration()
  • Method Details

    • init

      public void init()
      Initializes this configuration by initializing a Debouncer for writes and reading the configuration file.
    • refresh

      public void refresh()
      Refreshes the configuration from disk.
      Specified by:
      refresh in interface FileSettingsConfiguration
    • destroy

      public void destroy()
      Destroys this configuration by executing any pending write.
      Specified by:
      destroy in interface Destroyable
      See Also:
    • 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:
      get in interface Producer<com.fasterxml.jackson.databind.node.ObjectNode>
      Specified by:
      get in interface jakarta.inject.Provider<com.fasterxml.jackson.databind.node.ObjectNode>
      Specified by:
      get in interface com.google.common.base.Supplier<com.fasterxml.jackson.databind.node.ObjectNode>
      Specified by:
      get in interface Supplier<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 configured timeout if no further writes are scheduled, else it will postponed until their are no further requests for timeout milliseconds.
      See Also:
    • writeNow

      public void writeNow()
      Do not wait, but persist the settings right now.
    • getPath

      public Path getPath()
      Specified by:
      getPath in interface FileSettingsConfiguration
    • toString

      public String toString()
      Overrides:
      toString in class Object