Class AbstractConfiguredBean<ROOT,T>
- Type Parameters:
ROOT
- type of the configuration object rootT
- type of the sub-graph of ROOT that this bean is configured by
- All Implemented Interfaces:
PersistentObjectListener<ROOT>
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
PersistentObject
root object, or some portion thereof.
This superclass handles registering as a listener on the PersistentObject
, and invokes the
start()
, stop()
, and reconfigure()
lifecycle methods as needed.
The subclass method getBeanConfig(ROOT)
determines the portion of the configuration object of interest to the subclass.
Subclasses may also override requiresReconfigure(T, T)
to determine whether a configuration change requires a
reconfigure()
operation.
Empty starts and empty stops are supported; these are treated as an unconfigured state and the bean will be (or remain) stopped in those states.
At any point in time, getBeanConfig()
(and it's alternate form getRequiredConfig()
)
access this bean's current configuration (if any).
-
Field Summary
Fields inherited from class org.dellroad.stuff.spring.AbstractBean
log
-
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor.protected
AbstractConfiguredBean
(PersistentObject<ROOT> persistentObject) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Start and configure this instance if the current configuration is valid; if not (i.e., "empty start"), then do nothing and wait until it becomes valid.void
destroy()
Stop this instance.protected T
Get the current configuration (sub-tree) object appropriate for this instance, or null if not configured.protected abstract T
getBeanConfig
(ROOT rootConfig) Extract the configuration sub-tree object that this node uses for its configuration given the root configuration object.protected String
protected T
Get the current configuration (sub-tree) object appropriate for this instance, and require that this instance also be configured at the time this method is invoked.final void
handleEvent
(PersistentObjectEvent<ROOT> event) Handle notification of an updated root object.boolean
Is this bean configured? "Configured" means that eitherstart()
orreconfigure()
has been invoked successfully since the most recentstop()
.protected void
reconfigure
(T oldConfig, T newConfig) Reconfigure this bean.protected boolean
requiresReconfigure
(T oldConfig, T newConfig) void
setBeanName
(String beanName) protected void
setPersistentObject
(PersistentObject<ROOT> persistentObject) Configure thePersistentObject
that this instance will monitor.protected void
Start this bean.protected void
stop()
Stop this bean.
-
Constructor Details
-
AbstractConfiguredBean
protected AbstractConfiguredBean()Default constructor. -
AbstractConfiguredBean
Constructor.- Parameters:
persistentObject
- keeper of the current configuration
-
-
Method Details
-
setPersistentObject
Configure thePersistentObject
that this instance will monitor.- Parameters:
persistentObject
- keeper of the this bean's configuration
-
setBeanName
- Specified by:
setBeanName
in interfaceBeanNameAware
-
getBeanName
-
afterPropertiesSet
Start and configure this instance if the current configuration is valid; if not (i.e., "empty start"), then do nothing and wait until it becomes valid.- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Overrides:
afterPropertiesSet
in classAbstractBean
- Throws:
Exception
-
destroy
Stop this instance. Does nothing if already stopped.- Specified by:
destroy
in interfaceDisposableBean
- Overrides:
destroy
in classAbstractBean
- Throws:
Exception
-
isConfigured
public boolean isConfigured()Is this bean configured? "Configured" means that eitherstart()
orreconfigure()
has been invoked successfully since the most recentstop()
.- Returns:
- true if this instance is configured
-
handleEvent
Description copied from interface:PersistentObjectListener
Handle notification of an updated root object.- Specified by:
handleEvent
in interfacePersistentObjectListener<ROOT>
- Parameters:
event
- notification event
-
start
Start this bean. This instance's monitor will be locked when this method is invoked.The implementation in
AbstractConfiguredBean
does nothing.- Parameters:
beanConfig
- configuration sub-tree object, never null- Throws:
Exception
- upon failure; in this case the bean will be considered not configured
-
stop
protected void stop()Stop this bean. This instance's monitor will be locked when this method is invoked.The implementation in
AbstractConfiguredBean
does nothing. -
reconfigure
Reconfigure this bean. This instance's monitor will be locked when this method is invoked.The implementation in
AbstractConfiguredBean
invokesstop()
followed bystart(T)
.- Parameters:
oldConfig
- old configuration sub-tree object, never nullnewConfig
- new configuration sub-tree object, never null- Throws:
Exception
- upon failure; in this case the bean will be considered not configured
-
requiresReconfigure
Determine if a change fromoldConfig
tonewConfig
requires areconfigure()
operation.The implementation in
AbstractConfiguredBean
invokesnewConfig.equals(oldConfig)
and returns true if they are not equal.- Parameters:
oldConfig
- old configuration sub-tree object, never nullnewConfig
- new configuration sub-tree object, never null- Returns:
- true if
reconfigure()
needs to be invoked
-
getBeanConfig
Extract the configuration sub-tree object that this node uses for its configuration given the root configuration object.- Parameters:
rootConfig
- root config object, never null- Returns:
- this bean's config object
-
getBeanConfig
Get the current configuration (sub-tree) object appropriate for this instance, or null if not configured.- Returns:
- current bean configuration, or null if not configured
or the
PersistentObject
has been stopped
-
getRequiredConfig
Get the current configuration (sub-tree) object appropriate for this instance, and require that this instance also be configured at the time this method is invoked. This method is likegetBeanConfig()
but it throws an exception instead of returning null.- Returns:
- current bean configuration, never null
- Throws:
NotConfiguredException
- if this instance is not configuredNotConfiguredException
- if thePersistentObject
has been stopped
-