...
QPID uses Commons Configuration to handle nearly all configuration. It provides methods that allow parsing of options from a range of sources, including configuration files, system properties or simply hard coded classes of values (which is very useful in unit test cases).
The file format used by QPID is XML, and Commons Configuration allows a very simple XPath-like syntax to query individual elements from the configuration file.
In order to make using configuration as non-intrusive, flexible and strongly-typed as possible we do the following:
...
Example
An example should make this clearer. Consider a (fictional) configuration file containing the following XM
Code Block | ||
---|---|---|
| ||
<qpid>
<connector>
<ssl>true</ssl>
<port>5672</port>
</connector>
</qpid>
|
To use this in the application we would define a class to represent it:
Code Block | ||
---|---|---|
| ||
public class ConnectionConfig
{
public static final String SSL_PORT = "8672";
@Configured(path = "connector.port",
defaultValue = DEFAULT_PORT)
public int port;
@Configured(path = "connector.ssl",
defaultValue = "false")
public boolean enableSSL;
}
|
Note the use of @Configured to define the mapping between the configuration file and the field values.
All we need to do the access this configuration object anywhere within the application is call:
Code Block | ||
---|---|---|
| ||
ConnectionConfig cfg = ApplicationRegistry.getInstance().getConfiguredObject(ConnectionConfig.class);
|
The ApplicationRegistry is documented elsewhere but from the configuration perspective all you need to know is that the first time getConfiguredObject is called for a particular class, the configuration file is parsed and the configuration object is stored for future use. Subsequent calls to getConfiguredObject for the same class are very cheap since only a hash table lookup is doneBroker configuration is accessed through the class in the org.apache.qpid.server.configuration, primarily starting at ServerConfiguration and retrieving values or other Configuration classes from there.
Include Page | ||||
---|---|---|---|---|
|
...