Class Configurator<T extends Launchable,S>

java.lang.Object
com.arpnetworking.utility.Configurator<T,S>
Type Parameters:
T - The Launchable type to configure.
S - The type representing the validated configuration.
All Implemented Interfaces:
Listener, Launchable

public class Configurator<T extends Launchable,S> extends Object implements Listener, Launchable
Manages configuration and reconfiguration of a Launchable instance using a POJO representation of its configuration. The Launchable is instantiated with each new configuration. The configuration must validate on construction and throw an exception if the configuration is invalid.
Author:
Ville Koskela (ville dot koskela at inscopemetrics dot io)
  • Constructor Details

    • Configurator

      public Configurator(ConfiguredLaunchableFactory<T,S> factory, Class<? extends S> configurationClass)
      Public constructor.
      Parameters:
      factory - The factory to create a launchable.
      configurationClass - The configuration class.
  • Method Details

    • offerConfiguration

      public void offerConfiguration(Configuration configuration) throws Exception
      Description copied from interface: Listener
      Invoked before new configuration is applied. Any registered listener may reject the configuration by throwing an Exception. Any listener rejecting the configuration rejects the entire configuration and the offering instance will log the Exception with an error. Once any listener rejects the Configuration other listeners may not be offered that instance.
      Specified by:
      offerConfiguration in interface Listener
      Parameters:
      configuration - The new Configuration to be validated.
      Throws:
      Exception - Thrown if the Configuration should be rejected.
    • applyConfiguration

      public void applyConfiguration()
      Description copied from interface: Listener
      Invoked to apply the most recently offered configuration. Any RuntimeException thrown is logged and ignored. All validation must be performed during offer.
      Specified by:
      applyConfiguration in interface Listener
    • launch

      public void launch()
      Description copied from interface: Launchable
      Launch the component.
      Specified by:
      launch in interface Launchable
    • shutdown

      public void shutdown()
      Description copied from interface: Launchable
      Shutdown the component.
      Specified by:
      shutdown in interface Launchable
    • toLogValue

      public Object toLogValue()
      Generate a Steno log compatible representation.
      Returns:
      Steno log compatible representation.
    • toString

      public String toString()
      Overrides:
      toString in class Object