|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.netflix.config.DynamicProperty
public class DynamicProperty
A cached configuration property value that is automatically updated when the config is changed. The object is fully thread safe, and access is very fast. (In fact, testing indicates that using a DynamicProperty is faster than fetching a System Property.)
This class is intended for those situations where the value of a property is fetched many times, and the value may be changed on-the-fly. If the property is being read only once, "normal" access methods should be used. If the property value is fixed, consider just caching the value in a variable.
Fetching the cached value is synchronized only on this property, so contention should be negligible. If even that level of overhead is too much for you, you should (a) think real hard about what you are doing, and (b) just cache the property value in a variable and be done with it.
IMPORTANT NOTE
DynamicProperty objects are not subject to normal garbage collection.
They should be used only as a static value that lives for the
lifetime of the program.
Constructor Summary | |
---|---|
protected |
DynamicProperty()
|
Method Summary | |
---|---|
void |
addCallback(java.lang.Runnable r)
Adds a callback to the DynamicProperty to run when the value of the propety is updated. |
java.lang.Boolean |
getBoolean()
Gets the current value of the property as an Boolean. |
java.lang.Boolean |
getBoolean(java.lang.Boolean defaultValue)
Gets the current value of the property as an Boolean. |
long |
getChangedTimestamp()
Gets the time (in milliseconds since the epoch) when the property value was last set/changed. |
java.lang.Double |
getDouble()
Gets the current value of the property as a Long. |
java.lang.Double |
getDouble(java.lang.Double defaultValue)
Gets the current value of the property as a Long. |
java.lang.Float |
getFloat()
Gets the current value of the property as a Float. |
java.lang.Float |
getFloat(java.lang.Float defaultValue)
Gets the current value of the property as a Float. |
static DynamicProperty |
getInstance(java.lang.String propName)
Gets the DynamicProperty for a given property name. |
java.lang.Integer |
getInteger()
Gets the current value of the property as an Integer. |
java.lang.Integer |
getInteger(java.lang.Integer defaultValue)
Gets the current value of the property as an Integer. |
java.lang.Long |
getLong()
Gets the current value of the property as a Long. |
java.lang.Long |
getLong(java.lang.Long defaultValue)
Gets the current value of the property as a Long. |
java.lang.String |
getName()
Gets the name of the property. |
java.lang.Class |
getNamedClass()
Gets the current value of the property as a Class. |
java.lang.Class<?> |
getNamedClass(java.lang.Class<?> defaultValue)
Gets the current value of the property as a Class. |
java.lang.String |
getString()
Gets the current value of the property as a String. |
java.lang.String |
getString(java.lang.String defaultValue)
Gets the current value of the property as a String. |
boolean |
removeCallback(java.lang.Runnable r)
Removes a callback to the DynamicProperty so that it will no longer be run when the value of the propety is updated. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected DynamicProperty()
Method Detail |
---|
public static DynamicProperty getInstance(java.lang.String propName)
propName
- the name of the property
propName
public java.lang.String getName()
public long getChangedTimestamp()
public java.lang.String getString()
public java.lang.String getString(java.lang.String defaultValue)
defaultValue
- the value to return if the property is not defined
public java.lang.Boolean getBoolean() throws java.lang.IllegalArgumentException
Boolean.TRUE
.
A property string value of "false", "no", "off", "f" or "b"
produces Boolean.FALSE
.
(The value comparison ignores case.)
Any other value will result in an exception.
java.lang.IllegalArgumentException
- if the property is defined but
is not an Booleanpublic java.lang.Boolean getBoolean(java.lang.Boolean defaultValue)
defaultValue
- the value to return if the property is not defined,
or is not of the proper format
public java.lang.Integer getInteger() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if the property is defined but
is not an Integerpublic java.lang.Integer getInteger(java.lang.Integer defaultValue)
defaultValue
- the value to return if the property is not defined,
or is not of the proper format
public java.lang.Float getFloat() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if the property is defined but is
not a Floatpublic java.lang.Float getFloat(java.lang.Float defaultValue)
defaultValue
- the value to return if the property is not defined,
or is not of the proper format
public java.lang.Long getLong() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if the property is defined but is
not a Longpublic java.lang.Long getLong(java.lang.Long defaultValue)
defaultValue
- the value to return if the property is not defined,
or is not of the proper format
public java.lang.Double getDouble() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if the property is defined but is
not a Longpublic java.lang.Double getDouble(java.lang.Double defaultValue)
defaultValue
- the value to return if the property is not defined,
or is not of the proper format
public java.lang.Class getNamedClass() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- zif the property is defined but is
not the name of a Classpublic java.lang.Class<?> getNamedClass(java.lang.Class<?> defaultValue)
defaultValue
- the value to return if the property is not defined,
or is not the name of a Class
public void addCallback(java.lang.Runnable r)
public boolean removeCallback(java.lang.Runnable r)
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |