Class PropertyRegistry
- java.lang.Object
-
- edu.caltech.nanodb.server.properties.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PropertyRegistry.PropertyDescriptor
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<PropertyObserver>
observers
A collection of property observers to be informed when property values change.private java.util.concurrent.ConcurrentHashMap<java.lang.String,PropertyRegistry.PropertyDescriptor>
properties
A mapping of property names to values.private boolean
setup
This flag indicates whether the database is still in "start-up mode" or not.-
Fields inherited from interface edu.caltech.nanodb.server.properties.ServerProperties
DEFAULT_BASE_DIRECTORY, DEFAULT_PAGE_SIZE, DEFAULT_PAGECACHE_POLICY, DEFAULT_PAGECACHE_SIZE, DEFAULT_PLANNER_CLASS, MAX_PAGECACHE_SIZE, MIN_PAGECACHE_SIZE, PAGECACHE_POLICY_VALUES, PROP_BASE_DIRECTORY, PROP_CREATE_INDEXES_ON_KEYS, PROP_ENABLE_INDEXES, PROP_ENABLE_TRANSACTIONS, PROP_ENFORCE_KEY_CONSTRAINTS, PROP_FLUSH_AFTER_CMD, PROP_PAGE_SIZE, PROP_PAGECACHE_POLICY, PROP_PAGECACHE_SIZE, PROP_PLANNER_CLASS
-
-
Constructor Summary
Constructors Constructor Description PropertyRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addObserver(PropertyObserver observer)
Records a property-change observer on the property registry.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.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.java.util.Set<java.lang.String>
getAllPropertyNames()
Returns an unmodifiable set of all property names.boolean
getBooleanProperty(java.lang.String name)
Returns a property's value as a Boolean.int
getIntProperty(java.lang.String name)
Returns a property's value as an integer.java.lang.Object
getPropertyValue(java.lang.String name)
java.lang.String
getStringProperty(java.lang.String name)
Returns a property's value as a String.boolean
hasProperty(java.lang.String name)
Returnstrue
if the server has a property of the specified name,false
otherwise.private void
initProperties()
Initialize all of the properties that the database server knows about.void
setProperties(java.util.Properties properties)
This helper function sets the server properties based on the contents of a JavaProperties
object.void
setPropertyValue(java.lang.String name, java.lang.Object value)
void
setupCompleted()
Records that setup has been completed, and read-only properties should no longer be allowed to change.
-
-
-
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.
-
-
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 JavaProperties
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 propertyvalidator
- a validator for the propertyinitialValue
- an initial value for the propertyreadonly
- 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 propertyvalidator
- a validator for the propertyinitialValue
- an initial value for the property
-
hasProperty
public boolean hasProperty(java.lang.String name)
Returnstrue
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.
-
getPropertyValue
public java.lang.Object getPropertyValue(java.lang.String name) throws PropertyException
- Throws:
PropertyException
-
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
-
-