Package org.onosproject.net.config
Class Config<S>
- java.lang.Object
- 
- org.onosproject.net.config.Config<S>
 
- 
- Type Parameters:
- S- type of subject
 - Direct Known Subclasses:
- AllowedEntityConfig,- BandwidthCapacity,- BaseConfig,- BasicFeatureConfig,- BasicUiTopoLayoutConfig,- BgpConfig,- HostLearningConfig,- InterfaceConfig,- IntReportConfig,- McastConfig,- PortDescriptionsConfig,- RouterConfig,- RoutersConfig
 
 @Beta public abstract class Config<S> extends Object Base abstraction of a configuration facade for a specific subject. Derived classes should keep all state in the specified JSON tree as that is the only state that will be distributed or persisted; this class is merely a facade for interacting with a particular facet of configuration on a given subject.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classConfig.FieldPresenceIndicator of whether a configuration JSON field is required.
 - 
Field SummaryFields Modifier and Type Field Description protected com.fasterxml.jackson.databind.node.ArrayNodearrayprotected ConfigApplyDelegatedelegateprotected Stringkeyprotected com.fasterxml.jackson.databind.ObjectMappermapperprotected com.fasterxml.jackson.databind.JsonNodenodeprotected com.fasterxml.jackson.databind.node.ObjectNodeobjectprotected Ssubject
 - 
Constructor SummaryConstructors Constructor Description Config()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapply()Applies any configuration changes made via this configuration.protected Config<S>clear(String name)Clears the specified property.protected booleanget(String name, boolean defaultValue)Gets the specified property as a boolean.protected doubleget(String name, double defaultValue)Gets the specified property as a double.protected intget(String name, int defaultValue)Gets the specified property as an integer.protected longget(String name, long defaultValue)Gets the specified property as a long.protected <E extends Enum<E>>
 Eget(String name, E defaultValue, Class<E> enumClass)Gets the specified property as an enum.protected Stringget(String name, String defaultValue)Gets the specified property as a string.protected <T> List<T>getList(String name, Function<String,T> function)Gets the specified array property as a list of items.protected <T> List<T>getList(String name, Function<String,T> function, List<T> defaultValue)Gets the specified array property as a list of items.protected booleanhasField(com.fasterxml.jackson.databind.node.ObjectNode node, String name)Returns true if the given node contains a field with the given name.protected booleanhasField(String name)Returns true if this config contains a field with the given name.protected booleanhasFields(com.fasterxml.jackson.databind.node.ObjectNode node, String... mandatoryFields)Indicates whether all specified fields are present in a particular JSON object.protected booleanhasFields(String... mandatoryFields)Indicates whether all specified fields are present in the backing JSON.protected booleanhasOnlyFields(com.fasterxml.jackson.databind.node.ObjectNode node, String... allowedFields)Indicates whether only the specified fields are present in a particular JSON object.protected booleanhasOnlyFields(String... allowedFields)Indicates whether only the specified fields are present in the backing JSON.voidinit(S subject, String key, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.ObjectMapper mapper, ConfigApplyDelegate delegate)Initializes the configuration behaviour with necessary context.protected booleanisBoolean(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid boolean value.protected booleanisBoolean(String field, Config.FieldPresence presence)Indicates whether the specified field holds a valid boolean value.protected booleanisConnectPoint(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid connect point string.protected booleanisConnectPoint(String field, Config.FieldPresence presence)Indicates whether the specified field holds a valid connect point string.protected booleanisDecimal(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, double... minMax)Indicates whether the specified field of a particular node holds a valid decimal number.protected booleanisDecimal(String field, Config.FieldPresence presence, double... minMax)Indicates whether the specified field holds a valid decimal number.protected booleanisIntegralNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, long... minMax)Indicates whether the specified field of a particular node holds a valid integer.protected booleanisIntegralNumber(String field, Config.FieldPresence presence, long... minMax)Indicates whether the specified field holds a valid integer.protected booleanisIpAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid IP address.protected booleanisIpAddress(String field, Config.FieldPresence presence)Indicates whether the specified field holds a valid IP address.protected booleanisIpPrefix(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid IP prefix.protected booleanisIpPrefix(String field, Config.FieldPresence presence)Indicates whether the specified field holds a valid IP prefix.protected booleanisMacAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid MAC address.protected booleanisMacAddress(String field, Config.FieldPresence presence)Indicates whether the specified field holds a valid MAC address.protected booleanisNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, long... minMax)Indicates whether the specified field of a particular node holds a valid number.protected booleanisNumber(String field, Config.FieldPresence presence, long... minMax)Indicates whether the specified field holds a valid number.protected booleanisString(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, String... pattern)Indicates whether the specified field on a particular node holds a valid string value.protected booleanisString(String field, Config.FieldPresence presence, String... pattern)Indicates whether the specified field holds a valid string value.protected booleanisTpPort(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid transport layer port.protected booleanisTpPort(String field, Config.FieldPresence presence)Indicates whether the specified field holds a valid transport layer port.booleanisValid()Indicates whether or not the backing JSON node contains valid data.protected booleanisValidLength(String field, int maxLength)Indicates whether the specified field is of a valid length.Stringkey()Returns the configuration key.com.fasterxml.jackson.databind.JsonNodenode()Returns the JSON node that contains the configuration data.protected <T> Config<S>setList(String name, Function<? super T,String> function, List<T> value)Sets the specified property as an array of items in a given collection transformed into a String with suppliedfunction.protected <E extends Enum>
 Config<S>setOrClear(String name, E value)Sets the specified property as a double or clears it if null value given.protected Config<S>setOrClear(String name, Boolean value)Sets the specified property as a boolean or clears it if null value given.protected Config<S>setOrClear(String name, Double value)Sets the specified property as a double or clears it if null value given.protected Config<S>setOrClear(String name, Integer value)Sets the specified property as an integer or clears it if null value given.protected Config<S>setOrClear(String name, Long value)Sets the specified property as a long or clears it if null value given.protected Config<S>setOrClear(String name, String value)Sets the specified property as a string or clears it if null value given.protected <T> Config<S>setOrClear(String name, Collection<T> collection)Sets the specified property as an array of items in a given collection or clears it if null is given.Ssubject()Returns the specific subject to which this configuration pertains.StringtoString()
 
- 
- 
- 
Field Detail- 
subjectprotected S subject 
 - 
keyprotected String key 
 - 
nodeprotected com.fasterxml.jackson.databind.JsonNode node 
 - 
objectprotected com.fasterxml.jackson.databind.node.ObjectNode object 
 - 
arrayprotected com.fasterxml.jackson.databind.node.ArrayNode array 
 - 
mapperprotected com.fasterxml.jackson.databind.ObjectMapper mapper 
 - 
delegateprotected ConfigApplyDelegate delegate 
 
- 
 - 
Method Detail- 
initpublic final void init(S subject, String key, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.ObjectMapper mapper, ConfigApplyDelegate delegate) Initializes the configuration behaviour with necessary context.- Parameters:
- subject- configuration subject
- key- configuration key
- node- JSON node where configuration data is stored
- mapper- JSON object mapper
- delegate- delegate context, or null for detached configs.
 
 - 
isValidpublic boolean isValid() Indicates whether or not the backing JSON node contains valid data.Default implementation returns true. Subclasses are expected to override this with their own validation. Implementations are free to throw a RuntimeException if data is invalid. - Returns:
- true if the data is valid; false otherwise
- Throws:
- RuntimeException- if configuration is invalid or completely foobar
 
 - 
subjectpublic S subject() Returns the specific subject to which this configuration pertains.- Returns:
- configuration subject
 
 - 
keypublic String key() Returns the configuration key. This is primarily aimed for use in composite JSON trees in external representations and has no bearing on the internal behaviours.- Returns:
- configuration key
 
 - 
nodepublic com.fasterxml.jackson.databind.JsonNode node() Returns the JSON node that contains the configuration data.- Returns:
- JSON node backing the configuration
 
 - 
applypublic void apply() Applies any configuration changes made via this configuration.Not effective for detached configs. 
 - 
getprotected String get(String name, String defaultValue) Gets the specified property as a string.- Parameters:
- name- property name
- defaultValue- default value if property not set
- Returns:
- property value or default value
 
 - 
setOrClearprotected Config<S> setOrClear(String name, String value) Sets the specified property as a string or clears it if null value given.- Parameters:
- name- property name
- value- new value or null to clear the property
- Returns:
- self
 
 - 
getprotected boolean get(String name, boolean defaultValue) Gets the specified property as a boolean.- Parameters:
- name- property name
- defaultValue- default value if property not set
- Returns:
- property value or default value
 
 - 
clearprotected Config<S> clear(String name) Clears the specified property.- Parameters:
- name- property name
- Returns:
- self
 
 - 
setOrClearprotected Config<S> setOrClear(String name, Boolean value) Sets the specified property as a boolean or clears it if null value given.- Parameters:
- name- property name
- value- new value or null to clear the property
- Returns:
- self
 
 - 
getprotected int get(String name, int defaultValue) Gets the specified property as an integer.- Parameters:
- name- property name
- defaultValue- default value if property not set
- Returns:
- property value or default value
 
 - 
setOrClearprotected Config<S> setOrClear(String name, Integer value) Sets the specified property as an integer or clears it if null value given.- Parameters:
- name- property name
- value- new value or null to clear the property
- Returns:
- self
 
 - 
getprotected long get(String name, long defaultValue) Gets the specified property as a long.- Parameters:
- name- property name
- defaultValue- default value if property not set
- Returns:
- property value or default value
 
 - 
setOrClearprotected Config<S> setOrClear(String name, Long value) Sets the specified property as a long or clears it if null value given.- Parameters:
- name- property name
- value- new value or null to clear the property
- Returns:
- self
 
 - 
getprotected double get(String name, double defaultValue) Gets the specified property as a double.- Parameters:
- name- property name
- defaultValue- default value if property not set
- Returns:
- property value or default value
 
 - 
setOrClearprotected Config<S> setOrClear(String name, Double value) Sets the specified property as a double or clears it if null value given.- Parameters:
- name- property name
- value- new value or null to clear the property
- Returns:
- self
 
 - 
getprotected <E extends Enum<E>> E get(String name, E defaultValue, Class<E> enumClass) Gets the specified property as an enum.- Type Parameters:
- E- type of enum
- Parameters:
- name- property name
- defaultValue- default value if property not set
- enumClass- the enum class
- Returns:
- property value or default value
 
 - 
setOrClearprotected <E extends Enum> Config<S> setOrClear(String name, E value) Sets the specified property as a double or clears it if null value given.- Type Parameters:
- E- type of enum
- Parameters:
- name- property name
- value- new value or null to clear the property
- Returns:
- self
 
 - 
getListprotected <T> List<T> getList(String name, Function<String,T> function) Gets the specified array property as a list of items.- Type Parameters:
- T- type of item
- Parameters:
- name- property name
- function- mapper from string to item
- Returns:
- list of items
 
 - 
getListprotected <T> List<T> getList(String name, Function<String,T> function, List<T> defaultValue) Gets the specified array property as a list of items.- Type Parameters:
- T- type of item
- Parameters:
- name- property name
- function- mapper from string to item
- defaultValue- default value if property not set
- Returns:
- list of items
 
 - 
setListprotected <T> Config<S> setList(String name, Function<? super T,String> function, List<T> value) Sets the specified property as an array of items in a given collection transformed into a String with suppliedfunction.- Type Parameters:
- T- type of items
- Parameters:
- name- propertyName
- function- to transform item to a String
- value- list of items
- Returns:
- self
 
 - 
setOrClearprotected <T> Config<S> setOrClear(String name, Collection<T> collection) Sets the specified property as an array of items in a given collection or clears it if null is given.- Type Parameters:
- T- type of items
- Parameters:
- name- propertyName
- collection- collection of items
- Returns:
- self
 
 - 
isValidLengthprotected boolean isValidLength(String field, int maxLength) Indicates whether the specified field is of a valid length.- Parameters:
- field- the field to validate
- maxLength- the maximum allowed length of the field
- Returns:
- true if the field lenth is less than the required length
 
 - 
hasFieldprotected boolean hasField(String name) Returns true if this config contains a field with the given name.- Parameters:
- name- the field name
- Returns:
- true if field is present, false otherwise
 
 - 
hasFieldprotected boolean hasField(com.fasterxml.jackson.databind.node.ObjectNode node, String name)Returns true if the given node contains a field with the given name.- Parameters:
- node- the node to examine
- name- the name to look for
- Returns:
- true if the node has a field with the given name, false otherwise
 
 - 
hasOnlyFieldsprotected boolean hasOnlyFields(String... allowedFields) Indicates whether only the specified fields are present in the backing JSON.- Parameters:
- allowedFields- allowed field names
- Returns:
- true if only allowedFields are present; false otherwise
 
 - 
hasOnlyFieldsprotected boolean hasOnlyFields(com.fasterxml.jackson.databind.node.ObjectNode node, String... allowedFields)Indicates whether only the specified fields are present in a particular JSON object.- Parameters:
- node- node whose fields to check
- allowedFields- allowed field names
- Returns:
- true if only allowedFields are present; false otherwise
 
 - 
hasFieldsprotected boolean hasFields(String... mandatoryFields) Indicates whether all specified fields are present in the backing JSON.- Parameters:
- mandatoryFields- mandatory field names
- Returns:
- true if all mandatory fields are present; false otherwise
 
 - 
hasFieldsprotected boolean hasFields(com.fasterxml.jackson.databind.node.ObjectNode node, String... mandatoryFields)Indicates whether all specified fields are present in a particular JSON object.- Parameters:
- node- node whose fields to check
- mandatoryFields- mandatory field names
- Returns:
- true if all mandatory fields are present; false otherwise
 
 - 
isMacAddressprotected boolean isMacAddress(String field, Config.FieldPresence presence) Indicates whether the specified field holds a valid MAC address.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isMacAddressprotected boolean isMacAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid MAC address.- Parameters:
- objectNode- JSON node
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isIpAddressprotected boolean isIpAddress(String field, Config.FieldPresence presence) Indicates whether the specified field holds a valid IP address.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isIpAddressprotected boolean isIpAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid IP address.- Parameters:
- objectNode- node from whom to access the field
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isIpPrefixprotected boolean isIpPrefix(String field, Config.FieldPresence presence) Indicates whether the specified field holds a valid IP prefix.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isIpPrefixprotected boolean isIpPrefix(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid IP prefix.- Parameters:
- objectNode- node from whom to access the field
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isTpPortprotected boolean isTpPort(String field, Config.FieldPresence presence) Indicates whether the specified field holds a valid transport layer port.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isTpPortprotected boolean isTpPort(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid transport layer port.- Parameters:
- objectNode- node from whom to access the field
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isConnectPointprotected boolean isConnectPoint(String field, Config.FieldPresence presence) Indicates whether the specified field holds a valid connect point string.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isConnectPointprotected boolean isConnectPoint(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid connect point string.- Parameters:
- objectNode- JSON node
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isStringprotected boolean isString(String field, Config.FieldPresence presence, String... pattern) Indicates whether the specified field holds a valid string value.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- pattern- optional regex pattern
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isStringprotected boolean isString(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, String... pattern)Indicates whether the specified field on a particular node holds a valid string value.- Parameters:
- objectNode- JSON node
- field- JSON field name
- presence- specifies if field is optional or mandatory
- pattern- optional regex pattern
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isNumberprotected boolean isNumber(String field, Config.FieldPresence presence, long... minMax) Indicates whether the specified field holds a valid number.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- minMax- optional min/max values
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isNumberprotected boolean isNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, long... minMax)Indicates whether the specified field of a particular node holds a valid number.- Parameters:
- objectNode- JSON object
- field- JSON field name
- presence- specifies if field is optional or mandatory
- minMax- optional min/max values
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isIntegralNumberprotected boolean isIntegralNumber(String field, Config.FieldPresence presence, long... minMax) Indicates whether the specified field holds a valid integer.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- minMax- optional min/max values
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isIntegralNumberprotected boolean isIntegralNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, long... minMax)Indicates whether the specified field of a particular node holds a valid integer.- Parameters:
- objectNode- JSON node
- field- JSON field name
- presence- specifies if field is optional or mandatory
- minMax- optional min/max values
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isDecimalprotected boolean isDecimal(String field, Config.FieldPresence presence, double... minMax) Indicates whether the specified field holds a valid decimal number.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- minMax- optional min/max values
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isDecimalprotected boolean isDecimal(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence, double... minMax)Indicates whether the specified field of a particular node holds a valid decimal number.- Parameters:
- objectNode- JSON node
- field- JSON field name
- presence- specifies if field is optional or mandatory
- minMax- optional min/max values
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isBooleanprotected boolean isBoolean(String field, Config.FieldPresence presence) Indicates whether the specified field holds a valid boolean value.- Parameters:
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 - 
isBooleanprotected boolean isBoolean(com.fasterxml.jackson.databind.node.ObjectNode objectNode, String field, Config.FieldPresence presence)Indicates whether the specified field of a particular node holds a valid boolean value.- Parameters:
- objectNode- JSON object node
- field- JSON field name
- presence- specifies if field is optional or mandatory
- Returns:
- true if valid; false otherwise
- Throws:
- InvalidFieldException- if the field is present but not valid
 
 
- 
 
-