@Managed public class ConfigurationListener extends java.lang.Object implements DeleteTrigger
Instances of this class will listen for configuration
lifecycle events - load
, activate
,
deactivate
, replace
, and remove
.
Creating a listener instance implicitly registers the instance for a configuration type. A listener instance can only listen for one configuration type. Each type may have zero, one, or more listener instances registered. If multiple listeners are registered for the same configuration type, each listener will be called for each lifecycle event. The order in which they are invoked is non-deterministic. See the Configuration chapter of the Developer's Guide for more information on configuration types.
This class provides both audit and lifecycle callbacks.
Audit methods are invoked before the state transition, and may veto the requested change if a state or consistency problem is detected. As an example, you may disallow deactivate and replace of a version if it is currently managing a connected network resource.
Lifecycle callbacks occur after the state transition is confirmed. In the lifecycle callbacks, you should implement any application-visible changes to follow the new configuration state - for example, creating and starting network resources based on a Config instance.
Constructor and Description |
---|
ConfigurationListener(java.lang.String configurationType)
Create an instance to listen for configuration lifecycle events.
|
Modifier and Type | Method and Description |
---|---|
void |
activated(Version version)
Called when a configuration version has been activated for a registered
configuration type.
|
void |
auditActivate(Version version)
Called before a configuration version is activated for a registered
configuration type.
|
void |
auditDeactivate(Version version)
Called before a configuration version is deactivated for a registered
configuration type.
|
void |
auditLoad(Version version)
Called when a configuration version is loaded for a registered
configuration type.
|
void |
auditRemove(Version version)
Called before a configuration version is removed
for a registered configuration type.
|
void |
auditReplace(Version deactivating,
Version activating)
Called before a configuration version is replacing the active version
for a registered configuration type.
|
void |
deactivated(Version version)
Called when a configuration version has been deactivated for a registered
configuration type.
|
void |
loaded(Version version,
java.util.List<Config> additions)
Called when a new version has been loaded for a registered configuration
type.
|
void |
removed(Version version)
Called when a configuration version has been removed.
|
void |
replaced(Version deactivated,
Version activated)
Called when a configuration version has been activated, replacing an
existing, active, version.
|
void |
uponDelete()
Delete trigger callback method.
|
public ConfigurationListener(java.lang.String configurationType)
All configuration listeners must provide a constructor that overrides this constructor. The configuration type must be specified in the child constructor and passed to this constructor using super.
Creating an instance of a configuration listener implicitly registers a listener for the configurationType.
configurationType
- Configuration typepublic void uponDelete()
DeleteTrigger
uponDelete
in interface DeleteTrigger
public void loaded(Version version, java.util.List<Config> additions) throws ConfigurationException
additions
parameter.
This method may also veto the load by throwing
ConfigurationException
.
version
- Version instance that has been loaded.additions
- a list of Config instances to be added to the
newly-loaded version. This will be a valid List instance supporting
add
when the method is invoked.ConfigurationException
- thrown by the implementation
in order to veto the version load.public void activated(Version version)
version
belongs to. If the new version is replacing a previous active version,
then replaced(com.kabira.platform.switchconfig.Version, com.kabira.platform.switchconfig.Version)
is called instead.
Implementations that modify non-transactional resources should manage this carefully in activated() and deactivated(). See the Transactions chapter of the Developer's Guide.
version
- A version instance that has been activated.public void deactivated(Version version)
replaced(com.kabira.platform.switchconfig.Version, com.kabira.platform.switchconfig.Version)
is called instead.version
- A version instance that has been deactivated.public void replaced(Version deactivated, Version activated)
The default implementation of this method is to call the
deactivated
and activated
methods directly.
deactivated
- Version instance that has been deactivated.activated
- Version instance that has been activated.public void removed(Version version)
version
- Version instance that has been removed.public void auditLoad(Version version) throws ConfigurationException
versionLoaded
will be invoked on all registered listeners
before auditLoad
is called on any listener.
This method should check whether the given version is
legal to be loaded. If this version is not legal, the listener
may veto the version by throwing ConfigurationException
.
version
- The version instance about to be loaded.ConfigurationException
- to veto the entire version load.public void auditActivate(Version version) throws ConfigurationException
version
belongs to. If the new version will replace a previous active version,
then auditReplace(com.kabira.platform.switchconfig.Version, com.kabira.platform.switchconfig.Version)
is called instead.
This method should check whether the given version is
legal to be activated. It may veto the activation by throwing
ConfigurationException
.
version
- The version instance to be activated.ConfigurationException
- to veto the version activation.public void auditDeactivate(Version version) throws ConfigurationException
version
belongs to. If a new version will replace the previously-active version,
then auditReplace(com.kabira.platform.switchconfig.Version, com.kabira.platform.switchconfig.Version)
is called instead.
This method should check whether the given version is
legal to be deactivated. It may veto the deactivation by throwing
ConfigurationException
.
version
- The version instance to be deactivated.ConfigurationException
- to veto the version deactivation.public void auditReplace(Version deactivating, Version activating) throws ConfigurationException
This method should check whether the given version replacement is
legal. It may veto the replace operation by throwing
ConfigurationException
.
deactivating
- The version to be deactivated.activating
- The version to be activated.ConfigurationException
- to veto the version replace.public void auditRemove(Version version) throws ConfigurationException
This method should check whether the given remove is
legal. It may veto the remove operation by throwing
ConfigurationException
.
version
- The version to be removed.ConfigurationException
- to veto the version removal.