Class 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 Detail

      • JsonConfiguration

        public JsonConfiguration()
    • Method Detail

      • init

        public void init()
        Initializes this configuration by initializing a Debouncer for writes and reading the configuration file.
      • 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 javax.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:
        Debouncer.call()
      • writeNow

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