|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.netflix.config.DynamicPropertyFactory
public class DynamicPropertyFactory
A factory that creates instances of dynamic properties and associates them with an underlying configuration
or DynamicPropertySupport
where the properties could be changed dynamically at runtime.
It is recommended to initialize this class with a configuration or DynamicPropertySupport before the first call to
getInstance()
. Otherwise, it will be lazily initialized with a ConcurrentCompositeConfiguration
,
where a SystemConfiguration and DynamicURLConfiguration
will be added. You can also disable installing the default configuration
by setting system property "archaius.dynamicProperty.disableDefaultConfig" to be true
.
If system property "archaius.dynamicPropertyFactory.registerConfigWithJMX" is set to true
, when this class is initialized with a configuration,
the configuration will also be exposed to JMX via an instance of BaseConfigMBean
, where you can update the properties
via jconsole.
Example:
import com.netflix.config.DynamicProperty; class MyClass { private static DynamicIntProperty maxWaitMillis = DynamicPropertyFactory.getInstance().createIntProperty("myclass.sleepMillis", 250); // ... // add a callback when this property is changed maxWaitMillis.addCallback(new Runnable() { public void run() { int currentValue = maxWaitMillis.get(); // ... } }); // ... // Wait for a configurable amount of time for condition to become true. // Note that the time can be changed on-the-fly. someCondition.wait(maxWaitMillis.get()); // ... }
Please note that you should not cache the property value if you expect the value to change on-the-fly. For example, in the following code the change of the value is ineffective:
int maxWaitMillis = DynamicPropertyFactory.getInstance().createIntProperty("myclass.sleepMillis", 250).get(); // ... someCondition.wait(maxWaitMillis);
Field Summary | |
---|---|
static java.lang.String |
DISABLE_DEFAULT_CONFIG
System property to determine whether DynamicPropertyFactory should be lazily initialized with default configuration for getInstance() . |
static java.lang.String |
DISABLE_DEFAULT_SYS_CONFIG
System property to disable adding SystemConfiguration to the default ConcurrentCompositeConfiguration |
static java.lang.String |
ENABLE_JMX
Boolean system property to define whether a configuration MBean should be registered with JMX so that properties can be accessed via JMX console. |
static java.lang.String |
SYS_CONFIG_NAME
|
static java.lang.String |
THROW_MISSING_CONFIGURATION_SOURCE_EXCEPTION
System property name that defines whether getInstance() should throw
MissingConfigurationSourceException if there is no proper configuration source
at the time of call. |
static java.lang.String |
URL_CONFIG_NAME
|
Method Summary | |
---|---|
static java.lang.Object |
getBackingConfigurationSource()
Get the backing configuration from the factory. |
DynamicBooleanProperty |
getBooleanProperty(java.lang.String propName,
boolean defaultValue)
Create a new property whose value is a boolean and subject to change on-the-fly.. |
DynamicBooleanProperty |
getBooleanProperty(java.lang.String propName,
boolean defaultValue,
java.lang.Runnable propertyChangeCallback)
Create a new property whose value is a boolean and subject to change on-the-fly. |
DynamicDoubleProperty |
getDoubleProperty(java.lang.String propName,
double defaultValue)
Create a new property whose value is a double and subject to change on-the-fly.. |
DynamicDoubleProperty |
getDoubleProperty(java.lang.String propName,
double defaultValue,
java.lang.Runnable propertyChangeCallback)
Create a new property whose value is a double and subject to change on-the-fly. |
DynamicFloatProperty |
getFloatProperty(java.lang.String propName,
float defaultValue)
Create a new property whose value is a float and subject to change on-the-fly.. |
DynamicFloatProperty |
getFloatProperty(java.lang.String propName,
float defaultValue,
java.lang.Runnable propertyChangeCallback)
Create a new property whose value is a float and subject to change on-the-fly. |
static DynamicPropertyFactory |
getInstance()
Get the instance to create dynamic properties. |
DynamicIntProperty |
getIntProperty(java.lang.String propName,
int defaultValue)
Create a new property whose value is an integer and subject to change on-the-fly.. |
DynamicIntProperty |
getIntProperty(java.lang.String propName,
int defaultValue,
java.lang.Runnable propertyChangeCallback)
Create a new property whose value is an integer and subject to change on-the-fly. |
DynamicLongProperty |
getLongProperty(java.lang.String propName,
long defaultValue)
Create a new property whose value is a long and subject to change on-the-fly.. |
DynamicLongProperty |
getLongProperty(java.lang.String propName,
long defaultValue,
java.lang.Runnable propertyChangeCallback)
Create a new property whose value is a long and subject to change on-the-fly. |
DynamicStringProperty |
getStringProperty(java.lang.String propName,
java.lang.String defaultValue)
Create a new property whose value is a string and subject to change on-the-fly. |
DynamicStringProperty |
getStringProperty(java.lang.String propName,
java.lang.String defaultValue,
java.lang.Runnable propertyChangeCallback)
Create a new property whose value is a string and subject to change on-the-fly. |
static DynamicPropertyFactory |
initWithConfigurationSource(org.apache.commons.configuration.AbstractConfiguration config)
Initialize the factory with an AbstractConfiguration. |
static DynamicPropertyFactory |
initWithConfigurationSource(DynamicPropertySupport dynamicPropertySupport)
Initialize the factory with a DynamicPropertySupport . |
static boolean |
isInitializedWithDefaultConfig()
Return whether the factory is initialized with the default ConcurrentCompositeConfiguration. |
static boolean |
isThrowMissingConfigurationSourceException()
|
static void |
setThrowMissingConfigurationSourceException(boolean value)
Set the boolean value to indicate whether getInstance() should throw
MissingConfigurationSourceException if there is no proper configuration source
at the time of call. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String URL_CONFIG_NAME
public static final java.lang.String SYS_CONFIG_NAME
public static final java.lang.String ENABLE_JMX
public static final java.lang.String THROW_MISSING_CONFIGURATION_SOURCE_EXCEPTION
getInstance()
should throw
MissingConfigurationSourceException
if there is no proper configuration source
at the time of call.
public static final java.lang.String DISABLE_DEFAULT_SYS_CONFIG
public static final java.lang.String DISABLE_DEFAULT_CONFIG
getInstance()
. Default is false (not set).
Method Detail |
---|
public static DynamicPropertyFactory initWithConfigurationSource(org.apache.commons.configuration.AbstractConfiguration config)
The initialization will register a ConfigurationListener with the configuration so that DynamicProperty
will receives a callback and refresh its value when a property is changed in the configuration.
If the factory is already initialized with a default configuration source (see getInstance()
), it will re-register
itself with the new configuration source passed to this method. Otherwise, this method will throw IllegalArgumentException
if it has been initialized with a different and non-default configuration source. This method should be only called once.
config
- Configuration to be attached with DynamicProperty
java.lang.IllegalArgumentException
- if the factory has already been initialized with a non-default configuration sourcepublic static boolean isInitializedWithDefaultConfig()
public static java.lang.Object getBackingConfigurationSource()
ConcurrentCompositeConfiguration
if the default configuration is installed.
For example:
Configuration config = DynamicPropertyFactory.getInstance().getBackingConfigurationSource(); if (DynamicPropertyFactory.isInitializedWithDefaultConfig()) { ConcurrentCompositeConfiguration composite = (ConcurrentCompositeConfiguration) config; // ... }
DynamicPropertySupport
, or null if DynamicPropertyFactory has not been initialized.public static void setThrowMissingConfigurationSourceException(boolean value)
getInstance()
should throw
MissingConfigurationSourceException
if there is no proper configuration source
at the time of call.
value
- to setpublic static boolean isThrowMissingConfigurationSourceException()
getInstance()
should throw
MissingConfigurationSourceException
if there is no proper configuration source
at the time of call.public static DynamicPropertyFactory initWithConfigurationSource(DynamicPropertySupport dynamicPropertySupport)
DynamicPropertySupport
.
The initialization will register a PropertyListener
with the DynamicPropertySupport so that DynamicProperty
will receives a callback and refresh its value when a property is changed.
If the factory is already initialized with a default configuration source (see getInstance()
), it will re-register
itself with the new configuration source passed to this method. Otherwise, this method will throw IllegalArgumentException
if it has been initialized with a non-default configuration source. This method should be only called once.
dynamicPropertySupport
- DynamicPropertySupport to be associated with the DynamicProperty
java.lang.IllegalArgumentException
- if the factory has already been initialized with a different and non-default configuration sourcepublic static DynamicPropertyFactory getInstance() throws MissingConfigurationSourceException
initWithConfigurationSource(AbstractConfiguration)
and initWithConfigurationSource(DynamicPropertySupport)
),
it will fist try to initialize itself with a default ConcurrentCompositeConfiguration
, with the following two
sub configurations:
true
DynamicURLConfiguration
, which at a fixed interval polls
a configuration file (see URLConfigurationSource.DEFAULT_CONFIG_FILE_NAME
on classpath and a set of URLs specified via a system property
(see URLConfigurationSource.CONFIG_URL
).
You can disable the initialization with the default configuration by setting system property "archaius.dynamicProperty.disableDefaultConfig" to "true".
MissingConfigurationSourceException
- if throwMissingConfigurationSourceException is true and
an error occurred in creating the default configuration.public DynamicStringProperty getStringProperty(java.lang.String propName, java.lang.String defaultValue)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpublic DynamicStringProperty getStringProperty(java.lang.String propName, java.lang.String defaultValue, java.lang.Runnable propertyChangeCallback)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpropertyChangeCallback
- a Runnable to be called when the property is changedpublic DynamicIntProperty getIntProperty(java.lang.String propName, int defaultValue)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpublic DynamicIntProperty getIntProperty(java.lang.String propName, int defaultValue, java.lang.Runnable propertyChangeCallback)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpropertyChangeCallback
- a Runnable to be called when the property is changedpublic DynamicLongProperty getLongProperty(java.lang.String propName, long defaultValue)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpublic DynamicLongProperty getLongProperty(java.lang.String propName, long defaultValue, java.lang.Runnable propertyChangeCallback)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpropertyChangeCallback
- a Runnable to be called when the property is changedpublic DynamicBooleanProperty getBooleanProperty(java.lang.String propName, boolean defaultValue)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpublic DynamicBooleanProperty getBooleanProperty(java.lang.String propName, boolean defaultValue, java.lang.Runnable propertyChangeCallback)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpropertyChangeCallback
- a Runnable to be called when the property is changedpublic DynamicFloatProperty getFloatProperty(java.lang.String propName, float defaultValue)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpublic DynamicFloatProperty getFloatProperty(java.lang.String propName, float defaultValue, java.lang.Runnable propertyChangeCallback)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpropertyChangeCallback
- a Runnable to be called when the property is changedpublic DynamicDoubleProperty getDoubleProperty(java.lang.String propName, double defaultValue)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpublic DynamicDoubleProperty getDoubleProperty(java.lang.String propName, double defaultValue, java.lang.Runnable propertyChangeCallback)
propName
- property namedefaultValue
- default value if the property is not defined in underlying configurationpropertyChangeCallback
- a Runnable to be called when the property is changed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |