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
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.protectedAbstractConfiguredBean(PersistentObject<ROOT> persistentObject) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidStart 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.voiddestroy()Stop this instance.protected TGet the current configuration (sub-tree) object appropriate for this instance, or null if not configured.protected abstract TgetBeanConfig(ROOT rootConfig) Extract the configuration sub-tree object that this node uses for its configuration given the root configuration object.protected Stringprotected TGet 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 voidhandleEvent(PersistentObjectEvent<ROOT> event) Handle notification of an updated root object.booleanIs this bean configured? "Configured" means that eitherstart()orreconfigure()has been invoked successfully since the most recentstop().protected voidreconfigure(T oldConfig, T newConfig) Reconfigure this bean.protected booleanrequiresReconfigure(T oldConfig, T newConfig) voidsetBeanName(String beanName) protected voidsetPersistentObject(PersistentObject<ROOT> persistentObject) Configure thePersistentObjectthat this instance will monitor.protected voidStart this bean.protected voidstop()Stop this bean.
-
Constructor Details
-
AbstractConfiguredBean
protected AbstractConfiguredBean()Default constructor. -
AbstractConfiguredBean
Constructor.- Parameters:
persistentObject- keeper of the current configuration
-
-
Method Details
-
setPersistentObject
Configure thePersistentObjectthat this instance will monitor.- Parameters:
persistentObject- keeper of the this bean's configuration
-
setBeanName
- Specified by:
setBeanNamein 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:
afterPropertiesSetin interfaceInitializingBean- Overrides:
afterPropertiesSetin classAbstractBean- Throws:
Exception
-
destroy
Stop this instance. Does nothing if already stopped.- Specified by:
destroyin interfaceDisposableBean- Overrides:
destroyin 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:PersistentObjectListenerHandle notification of an updated root object.- Specified by:
handleEventin 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
AbstractConfiguredBeandoes 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
AbstractConfiguredBeandoes nothing. -
reconfigure
Reconfigure this bean. This instance's monitor will be locked when this method is invoked.The implementation in
AbstractConfiguredBeaninvokesstop()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 fromoldConfigtonewConfigrequires areconfigure()operation.The implementation in
AbstractConfiguredBeaninvokesnewConfig.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
PersistentObjecthas 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 thePersistentObjecthas been stopped
-