Package com.arpnetworking.utility
Class Configurator<T extends Launchable,S>
java.lang.Object
com.arpnetworking.utility.Configurator<T,S>
- Type Parameters:
T
- TheLaunchable
type to configure.S
- The type representing the validated configuration.
- All Implemented Interfaces:
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 com)
-
Constructor Summary
ConstructorDescriptionConfigurator
(ConfiguredLaunchableFactory<T, S> factory, Class<? extends S> configurationClass) Public constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked to apply the most recently offered configuration.void
launch()
Launch the component.void
offerConfiguration
(Configuration configuration) Invoked before new configuration is applied.void
shutdown()
Shutdown the component.Generate a Steno log compatible representation.toString()
-
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
Description copied from interface:Listener
Invoked before new configuration is applied. Any registered listener may reject the configuration by throwing anException
. Any listener rejecting the configuration rejects the entire configuration and the offering instance will log theException
with an error. Once any listener rejects theConfiguration
other listeners may not be offered that instance.- Specified by:
offerConfiguration
in interfaceListener
- Parameters:
configuration
- The newConfiguration
to be validated.- Throws:
Exception
- Thrown if theConfiguration
should be rejected.
-
applyConfiguration
public void applyConfiguration()Description copied from interface:Listener
Invoked to apply the most recently offered configuration. AnyRuntimeException
thrown is logged and ignored. All validation must be performed during offer.- Specified by:
applyConfiguration
in interfaceListener
-
launch
public void launch()Description copied from interface:Launchable
Launch the component.- Specified by:
launch
in interfaceLaunchable
-
shutdown
public void shutdown()Description copied from interface:Launchable
Shutdown the component.- Specified by:
shutdown
in interfaceLaunchable
-
toLogValue
Generate a Steno log compatible representation.- Returns:
- Steno log compatible representation.
-
toString
-