public class ConfigurationService extends Object
The service uses an internally-managed instance of Configuration
to handle
the registration, retrieval and deregistration of the configuration objects under its
management.
The service first attempts to use the Java Services API to resolve the instance
of Configuration to use. If multiple implementations of Configuration are registered
via the Services API mechanism, the first one returned by the ServiceLoader
iterator
is used. If no Configuration implementation is declared or resolvable using
the Services API, then it uses the default implementation MapBasedConfiguration
.
The Configuration instance to use may also be set externally via setConfiguration(Configuration)
.
This may be useful where an application-specific means such as Spring is used to configure the environment.
This overrides the resolution process described above.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PARTITION_NAME
The default storage partition name, if none is specified using configuration properties.
|
static String |
PROPERTY_PARTITION_NAME
The configuration property name for the storage partition name to use.
|
Modifier | Constructor and Description |
---|---|
protected |
ConfigurationService()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
deregister(Class<T> configClass)
Deregister a configuration instance.
|
static <T> T |
get(Class<T> configClass)
Obtain the registered configuration instance.
|
protected static Configuration |
getConfiguration()
Get the
Configuration instance to use. |
static Properties |
getConfigurationProperties()
Get the set of configuration meta-properties, which determines the configuration of the configuration
service itself.
|
protected static String |
getPartitionName()
Return the partition name which will be used for storage of configuration objects.
|
static <T,I extends T> |
register(Class<T> configClass,
I configInstance)
Register a configuration instance.
|
static void |
setConfiguration(Configuration newConfiguration)
Set the
Configuration instance to use. |
@Nonnull public static final String DEFAULT_PARTITION_NAME
@Nonnull public static final String PROPERTY_PARTITION_NAME
public static <T> T get(@Nonnull Class<T> configClass)
T
- the type of configuration being retrievedconfigClass
- the configuration class identifierpublic static <T,I extends T> void register(@Nonnull Class<T> configClass, @Nonnull I configInstance)
T
- the type of configuration being registeredI
- the configuration object instance type being registered, which must be an instance of configClass
- the type of configuration being registeredconfigInstance
- the configuration object instance being registeredpublic static <T> T deregister(@Nonnull Class<T> configClass)
T
- the type of configuration being deregisteredconfigClass
- the type of configuration class being deregistered@Nullable public static Properties getConfigurationProperties()
The properties set is obtained from the first registered instance of
ConfigurationPropertiesSource
which returns a non-null properties set.
The implementations of properties sources to use
are obtained via the Java Services API.
Properties made available in this meta-properties set may also be used by Initializer
implementations.
public static void setConfiguration(@Nonnull Configuration newConfiguration)
Configuration
instance to use.
The configuration instance to use is normally resolved via the Java Services API, or is defaulted. However, this method is provided to allow the configuration instance to be supplied externally, perhaps using an application-specific means such as Spring dependency injection.
newConfiguration
- the Configuration instance to use@Nonnull @NotEmpty protected static String getPartitionName()
This partition name is obtained from the configuration meta-properties. If a value is not supplied via that mechanism, then an internal default value is used.
@Nonnull protected static Configuration getConfiguration()
Configuration
instance to use.
The implementation to return is first resolved using the Java Services API.
If this produces no implementation, then an instance of the default implementation
of MapBasedConfiguration
is used.
Copyright © 2016 JBoss by Red Hat. All rights reserved.