public class Configurator extends Object implements Cloneable
Modifier and Type | Field and Description |
---|---|
static int |
MAX_FILE_SIZE |
Constructor and Description |
---|
Configurator(Configuration conf)
Constructs a new configuration object with the specified configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Tries to close all open components, clears the components map.
|
<T> T |
construct(Class<T> klass,
String name,
com.typesafe.config.Config conf,
Map<String,String> runtimeParams)
Constructs an instance of the specified class with the passed
in config.
|
<T> T |
get(Class<T> klass)
Get a specific named instance of the component with the specified class.
|
<T> T |
get(Class<T> klass,
String name) |
<T> T |
get(Class<T> klass,
String name,
Map<String,String> runtimeParams)
Get a specific named instance of the component with the specified class.
|
<T> T |
get(Class<T> klass,
String name,
String runtimeKey,
String runtimeValue)
Get a component with a single runtime parameter
|
Configuration |
getConf() |
com.typesafe.config.Config |
getConfig(Class klass,
String name)
Returns the config object associated with the given class and name.
|
String |
resolveComponentName(Class klass,
String name)
If the component name is "default" or null, return the name of the default implementation of the compoenent.
|
public static final int MAX_FILE_SIZE
public Configurator(Configuration conf) throws ConfigurationException
conf
- ConfigurationException
public Configuration getConf()
public <T> T get(Class<T> klass, String name) throws ConfigurationException
T
- klass
- name
- ConfigurationException
get(Class, String, java.util.Map)
public <T> T get(Class<T> klass, String name, String runtimeKey, String runtimeValue) throws ConfigurationException
T
- klass
- name
- runtimeKey
- runtimeValue
- ConfigurationException
get(Class, String, java.util.Map)
public <T> T get(Class<T> klass, String name, Map<String,String> runtimeParams) throws ConfigurationException
klass
- The generic interface or superclass, not the specific implementation.name
- The name of the class as it appears in the config file. If name is null,
the configurator tries to guess by looking for a "default" entry in
the config that provides the name for a default implementation or, if
there is exactly one implementation returning it. Otherwise, if name is
null it throws an error.runtimeParams
- Parameters to be passed to the provider that affect component creation.
The identity of a component includes the runtime parameters, so
two components with the same klass and name, but different runtimeParams
will be cached independently.ConfigurationException
public String resolveComponentName(Class klass, String name) throws ConfigurationException
klass
- name
- ConfigurationException
public com.typesafe.config.Config getConfig(Class klass, String name) throws ConfigurationException
klass
- The generic interface or superclass, not the specific implementation.name
- The name of the class as it appears in the config file. If name is null,
the configurator tries to guess by looking for a "default" entry in
the config that provides the name for a default implementation or, if
there is exactly one implementation returning it. Otherwise, if name is
null it throws an error.ConfigurationException
public <T> T construct(Class<T> klass, String name, com.typesafe.config.Config conf, Map<String,String> runtimeParams) throws ConfigurationException
klass
- The class being created.name
- An arbitrary name for the object. Can be null.conf
- The configuration for the object.runtimeParams
- ConfigurationException
public <T> T get(Class<T> klass) throws ConfigurationException
klass
- The generic interface or superclass, not the specific implementation.ConfigurationException
public void close()
Copyright © 2018. All rights reserved.