Class Configurator


  • public class Configurator
    extends Object
    Fills in configured values from configuration source based on annotations in the source code.

    Configuration clauses are assumed to be of the form
        pkg.class[.instance].property = value
    where pkg is the package name without org.powertac (or the full classname for classes outside the org.powertac hierarchy), class is the classname (but the first character is lowercase), instance is an optional instance name, and property is the property name. The target property must be annotated with ConfigurableValue, either on the property itself, or on a setter method. For example, the following property will set the jmsBrokerUrl property of the class JmsManagementService.

    server.jmsManagementService.jmsBrokerUrl = tcp://localhost:61616

    In the server, an instance of this class is typically created by a service that collects configuration data, creates and initializes a Configurator, then waits for each service to ask for its configuration. There are many examples of configuration settings in the server properties file.

    When used in a broker, classes outside the org.powertac tree can be used if the full package prefix is specified. For example, the following property specification will set the foo property of class edu.umn.Bar:

    edu.umn.bar.foo = 42

    Author:
    John Collins
    • Constructor Detail

      • Configurator

        public Configurator()
    • Method Detail

      • readXML

        public static final org.apache.commons.configuration2.XMLConfiguration readXML​(String path)
                                                                                throws org.apache.commons.configuration2.ex.ConfigurationException
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
      • readXML

        public static final org.apache.commons.configuration2.XMLConfiguration readXML​(File file)
                                                                                throws org.apache.commons.configuration2.ex.ConfigurationException
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
      • readXML

        public static final org.apache.commons.configuration2.XMLConfiguration readXML​(URL url)
                                                                                throws org.apache.commons.configuration2.ex.ConfigurationException
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
      • readProperties

        public static final org.apache.commons.configuration2.PropertiesConfiguration readProperties​(String path)
                                                                                              throws org.apache.commons.configuration2.ex.ConfigurationException
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
      • readProperties

        public static final org.apache.commons.configuration2.PropertiesConfiguration readProperties​(URL url)
                                                                                              throws org.apache.commons.configuration2.ex.ConfigurationException
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
      • readProperties

        public static final org.apache.commons.configuration2.PropertiesConfiguration readProperties​(File file)
                                                                                              throws org.apache.commons.configuration2.ex.ConfigurationException
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException
      • setConfiguration

        public void setConfiguration​(org.apache.commons.configuration2.AbstractConfiguration config)
        Loads a Configuration into this Configurator.
      • setConfigOutput

        public void setConfigOutput​(ConfigurationRecorder configOutput)
        Sets up an output stream for config dump.
      • configureSingleton

        public void configureSingleton​(Object thing)
        Configures the given thing, using the pre-loaded Configuration.
      • configureInstances

        public Collection<?> configureInstances​(Class<?> type)
        Creates and configures instances of the given class. In the configuration, we expect to see a property of the form pkg.class.instances = a, b, c, ... where a, b, c, etc. are the names of instances of the class to be created and configured. These names are provided to the instances through their constructors, and are expected to show up in the configuration as instance names in clauses of the form pkg.class.name.property = value. Returns empty list in case instances cannot be created.
      • configureNamedInstances

        public Collection<?> configureNamedInstances​(List<?> instances)
        Configures a set of instances of some class. In the configuration, we expect to see properties of the form pkg.class.name.property = value where name is the name of an instance in the list to be configured. These names must be accessible through a getName() method on each instance. It is an error if instances are not of the same class; in fact, the class of the first instance in the list is used to form the pkg.class. It also does not work for types that lack a getName() method returning a String, or if the name does not match the name in the properties. portion of the property names.
      • gatherPublishedConfiguration

        public void gatherPublishedConfiguration​(Object thing,
                                                 ConfigurationRecorder recorder)
        Pulls the "published" ConfigurableValues out of object thing, adds them to config.
      • gatherBootstrapState

        public void gatherBootstrapState​(Object thing,
                                         ConfigurationRecorder recorder)
        Pulls the "bootstrapState" ConfigurableValues out of object thing, adds them to config.
      • gatherBootstrapList

        public void gatherBootstrapList​(List<Object> things,
                                        ConfigurationRecorder recorder)
        Pulls "bootstrapState" ConfigurationValues out of objects in the given list, adds them to config with their names. This requires that the instances in the list each have a getName() method that returns a String. Any instance lacking such a method will not be recorded, and an error message logged.