Class PropertyRegistry

  • All Implemented Interfaces:
    ServerProperties

    public class PropertyRegistry
    extends java.lang.Object
    implements ServerProperties
    This is the central location where all properties exposed by the database can be registered and accessed. Various components register their configurable properties with the registry, and then they can be accessed and/or set from the SQL prompt.
    • Field Detail

      • properties

        private java.util.concurrent.ConcurrentHashMap<java.lang.String,​PropertyRegistry.PropertyDescriptor> properties
        A mapping of property names to values. A thread-safe hash map is used since this will be accessed and mutated from different threads.
      • observers

        private java.util.ArrayList<PropertyObserver> observers
        A collection of property observers to be informed when property values change.
      • setup

        private boolean setup
        This flag indicates whether the database is still in "start-up mode" or not. During start-up mode, all read-only properties may also be modified.
    • Constructor Detail

      • PropertyRegistry

        public PropertyRegistry()
    • Method Detail

      • initProperties

        private void initProperties()
        Initialize all of the properties that the database server knows about. Some of these properties are read-write, and others are read-only and are initialized right at database startup, before any other steps occur.
        Code Review:
        (donnie) It's not great that this configuration is in here. Someday, should probably migrate it back into NanoDBServer.
      • setProperties

        public void setProperties​(java.util.Properties properties)
        This helper function sets the server properties based on the contents of a Java Properties object. This allows us to set NanoDB properties from system properties and/or other sources of properties.
        Parameters:
        properties - the properties to apply to NanoDB's configuration.
      • setupCompleted

        public void setupCompleted()
        Records that setup has been completed, and read-only properties should no longer be allowed to change.
      • addObserver

        public void addObserver​(PropertyObserver observer)
        Records a property-change observer on the property registry.
        Parameters:
        observer - the observer to receive property-change notifications
      • addProperty

        public void addProperty​(java.lang.String name,
                                PropertyValidator validator,
                                java.lang.Object initialValue,
                                boolean readonly)
        Add a read-only or read-write property to the registry, along with a type and an initial value.
        Parameters:
        name - the name of the property
        validator - a validator for the property
        initialValue - an initial value for the property
        readonly - a flag indicating whether the property is read-only (true) or read-write (false)
      • addProperty

        public void addProperty​(java.lang.String name,
                                PropertyValidator validator,
                                java.lang.Object initialValue)
        Add a read-write property to the registry, along with a type and an initial value.
        Parameters:
        name - the name of the property
        validator - a validator for the property
        initialValue - an initial value for the property
      • hasProperty

        public boolean hasProperty​(java.lang.String name)
        Returns true if the server has a property of the specified name, false otherwise.
        Parameters:
        name - the non-null name of the property
        Returns:
        true if the server has a property of the specified name, false otherwise.
      • getAllPropertyNames

        public java.util.Set<java.lang.String> getAllPropertyNames()
        Returns an unmodifiable set of all property names.
        Returns:
        an unmodifiable set of all property names.
      • setPropertyValue

        public void setPropertyValue​(java.lang.String name,
                                     java.lang.Object value)
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String name)
        Returns a property's value as a Boolean. If the property's value is not a Boolean then an exception is reported.
        Parameters:
        name - the name of the property to fetch
        Returns:
        a Boolean true or false value for the property
      • getStringProperty

        public java.lang.String getStringProperty​(java.lang.String name)
        Returns a property's value as a String. If the property's value is not a String then an exception is reported.
        Parameters:
        name - the name of the property to fetch
        Returns:
        a String value for the property
      • getIntProperty

        public int getIntProperty​(java.lang.String name)
        Returns a property's value as an integer. If the property's value is not an integer then an exception is reported.
        Parameters:
        name - the name of the property to fetch
        Returns:
        an integer value for the property