Class AbstractPropertyBackedBean

  • All Implemented Interfaces:
    java.util.EventListener, PropertyBackedBean, PropertyBackedBeanState, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
    Direct Known Subclasses:
    AuditModelRegistryImpl, ChildApplicationContextFactory, CompositeDataBean, DefaultChildApplicationContextManager, SwitchableApplicationContextFactory

    public abstract class AbstractPropertyBackedBean
    extends java.lang.Object
    implements PropertyBackedBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.BeanNameAware
    A base class for PropertyBackedBeans. Gets its category from its Spring bean name and automatically propagates and resolves property defaults on initialization. Automatically destroys itself on server shutdown. Communicates its creation and destruction and start and stop events to a PropertyBackedBeanRegistry. Listens for start and stop events from remote nodes in order to keep the bean in sync with edits made on a remote node. On receiving a start event from a remote node, the bean is completely reinitialized, allowing it to be resynchronized with any persisted changes.
    Author:
    dward
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()
      protected void applyDefaultOverrides​(PropertyBackedBeanState state)
      Applies default overrides to the initial state.
      protected abstract PropertyBackedBeanState createInitialState()
      Creates the initial state.
      void destroy()
      protected void destroy​(boolean isPermanent)
      Releases any resources held by this component.
      protected void doInit()
      Initializes or resets the bean and its state.
      protected java.lang.String getCategory()
      Gets the category.
      java.lang.String getDescription​(java.lang.String name)
      Gets a Human readable description of the property, e.g.
      protected java.util.Properties getEncryptedPropertyDefaults()  
      java.util.List<java.lang.String> getId()
      Gets a unique identifier for the bean.
      protected java.util.List<java.lang.String> getInstancePath()
      Gets the hierarchical instance path within the category (second part of the ID).
      protected org.springframework.context.ApplicationContext getParent()
      Gets the parent application context.
      java.lang.String getProperty​(java.lang.String name)
      Gets a property value.
      protected java.util.Properties getPropertyDefaults()
      Gets the property defaults provided by the installer or System properties.
      java.util.Set<java.lang.String> getPropertyNames()
      Gets the names of all properties.
      protected PropertyBackedBeanRegistry getRegistry()
      Gets the registry of all property backed beans.
      protected PropertyBackedBeanState getState​(boolean start)
      Gets the state.
      void init()
      Initializes or resets the bean and its state.
      boolean isUpdateable​(java.lang.String name)
      Checks if a property is updateable.
      void onApplicationEvent​(org.springframework.context.ApplicationEvent event)
      java.lang.String performEarlyPropertyChecks​(java.util.Map<java.lang.String,​java.lang.String> properties)
      Check properties for invalid values using SubsystemEarlyPropertyCheckers
      void removeProperties​(java.util.Collection<java.lang.String> properties)
      Removes properties added by code within the local node.
      void removeProperty​(java.lang.String name)
      Removes a property added by code within the local node.
      protected java.lang.String resolveDefault​(java.lang.String name)
      Resolves the default value of a property, if there is one, expanding placholders as necessary.
      void revert()
      Reverts this component to its original default start state, removing any previously persisted state changes.
      void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)  
      void setAutoStart​(boolean autoStart)
      Indicates whether the bean should be started on startup of the parent application context.
      void setBeanName​(java.lang.String name)  
      void setCategory​(java.lang.String category)
      Sets the category (first part of the ID).
      void setEarlyPropertyCheckers​(java.util.Map<java.lang.String,​SubsystemEarlyPropertyChecker> earlyPropertyCheckers)  
      void setEncryptedPropertyDefaults​(java.util.Properties propertyDefaults)  
      void setInstancePath​(java.util.List<java.lang.String> instancePath)
      Sets the hierarchical instance path within the category (second part of the ID)..
      void setProperties​(java.util.Map<java.lang.String,​java.lang.String> properties)
      Tries setting the given properties on this component.
      void setProperty​(java.lang.String name, java.lang.String value)
      Sets the value of a property.
      void setPropertyDefaults​(java.util.Properties propertyDefaults)
      Sets the property defaults provided by the installer or System properties.
      void setRegistry​(PropertyBackedBeanRegistry registry)
      Sets the registry of all property backed beans.
      void setSaveSetProperty​(boolean saveSetProperty)
      When set to true, calls to setProperties / setProperty are persisted to the MBean if it exists.
      void start()
      Starts up the component, using its new property values.
      protected void start​(boolean broadcastNow, boolean broadcastLater)
      Starts the bean, optionally broadcasting the event to remote nodes.
      void stop()
      Stops the component, so that its property values can be changed.
      protected void stop​(boolean broadcast)
      Stops the bean, optionally broadcasting the event to remote nodes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_INSTANCE_NAME

        protected static final java.lang.String DEFAULT_INSTANCE_NAME
        The default final part of an ID.
        See Also:
        Constant Field Values
      • lock

        protected java.util.concurrent.locks.ReentrantReadWriteLock lock
        Lock for concurrent access.
    • Constructor Detail

      • AbstractPropertyBackedBean

        public AbstractPropertyBackedBean()
    • Method Detail

      • setEarlyPropertyCheckers

        public void setEarlyPropertyCheckers​(java.util.Map<java.lang.String,​SubsystemEarlyPropertyChecker> earlyPropertyCheckers)
      • setApplicationContext

        public void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)
                                   throws org.springframework.beans.BeansException
        Specified by:
        setApplicationContext in interface org.springframework.context.ApplicationContextAware
        Throws:
        org.springframework.beans.BeansException
      • setRegistry

        public void setRegistry​(PropertyBackedBeanRegistry registry)
        Sets the registry of all property backed beans.
        Parameters:
        registry - the registry of all property backed beans
      • getRegistry

        protected PropertyBackedBeanRegistry getRegistry()
        Gets the registry of all property backed beans.
        Returns:
        the registry of all property backed beans
      • setBeanName

        public void setBeanName​(java.lang.String name)
        Specified by:
        setBeanName in interface org.springframework.beans.factory.BeanNameAware
      • setCategory

        public void setCategory​(java.lang.String category)
        Sets the category (first part of the ID).
        Parameters:
        category - the category
      • setInstancePath

        public void setInstancePath​(java.util.List<java.lang.String> instancePath)
        Sets the hierarchical instance path within the category (second part of the ID)..
        Parameters:
        instancePath - the instance path
      • setAutoStart

        public void setAutoStart​(boolean autoStart)
        Indicates whether the bean should be started on startup of the parent application context.
        Parameters:
        autoStart - true if the bean should be started on startup of the parent application context
      • setPropertyDefaults

        public void setPropertyDefaults​(java.util.Properties propertyDefaults)
        Sets the property defaults provided by the installer or System properties.
        Parameters:
        propertyDefaults - the property defaults
      • setEncryptedPropertyDefaults

        public void setEncryptedPropertyDefaults​(java.util.Properties propertyDefaults)
      • getPropertyDefaults

        protected java.util.Properties getPropertyDefaults()
        Gets the property defaults provided by the installer or System properties.
        Returns:
        the property defaults
      • getEncryptedPropertyDefaults

        protected java.util.Properties getEncryptedPropertyDefaults()
      • resolveDefault

        protected java.lang.String resolveDefault​(java.lang.String name)
        Resolves the default value of a property, if there is one, expanding placholders as necessary.
        Parameters:
        name - the property name
        Returns:
        the resolved default value or null if there isn't one
      • getParent

        protected org.springframework.context.ApplicationContext getParent()
        Gets the parent application context.
        Returns:
        the parent application context
      • getState

        protected PropertyBackedBeanState getState​(boolean start)
        Gets the state.
        Parameters:
        start - are we making use of the state? I.e. should we start it if it has not been already?
        Returns:
        the state
      • setSaveSetProperty

        public void setSaveSetProperty​(boolean saveSetProperty)
        When set to true, calls to setProperties / setProperty are persisted to the MBean if it exists.
      • performEarlyPropertyChecks

        public java.lang.String performEarlyPropertyChecks​(java.util.Map<java.lang.String,​java.lang.String> properties)
        Check properties for invalid values using SubsystemEarlyPropertyCheckers
        Parameters:
        properties -
        Returns:
        The complete error message in case of exceptions or empty string otherwise
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • init

        public final void init()
        Initializes or resets the bean and its state.
      • doInit

        protected void doInit()
        Initializes or resets the bean and its state.
      • revert

        public final void revert()
        Reverts this component to its original default start state, removing any previously persisted state changes.
        Specified by:
        revert in interface PropertyBackedBean
      • createInitialState

        protected abstract PropertyBackedBeanState createInitialState()
                                                               throws java.io.IOException
        Creates the initial state.
        Returns:
        the property backed bean state
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • applyDefaultOverrides

        protected void applyDefaultOverrides​(PropertyBackedBeanState state)
                                      throws java.io.IOException
        Applies default overrides to the initial state.
        Parameters:
        state - the state
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • getId

        public java.util.List<java.lang.String> getId()
        Gets a unique identifier for the bean. The ID is a List to encourage hierarchical structuring of IDs, e.g. to aid construction of JMX Object names and presentation in JConsole.
        Specified by:
        getId in interface PropertyBackedBean
        Returns:
        the id
      • getCategory

        protected java.lang.String getCategory()
        Gets the category.
        Returns:
        the category
      • getInstancePath

        protected java.util.List<java.lang.String> getInstancePath()
        Gets the hierarchical instance path within the category (second part of the ID).
        Returns:
        the instance path
      • destroy

        public final void destroy()
        Specified by:
        destroy in interface org.springframework.beans.factory.DisposableBean
      • destroy

        protected void destroy​(boolean isPermanent)
        Releases any resources held by this component.
        Parameters:
        isPermanent - is the component being destroyed forever, i.e. should persisted values be removed? On server shutdown, this value would be false, whereas on the removal of a dynamically created instance, this value would be true.
      • isUpdateable

        public boolean isUpdateable​(java.lang.String name)
        Checks if a property is updateable.
        Specified by:
        isUpdateable in interface PropertyBackedBean
        Parameters:
        name - the property name
        Returns:
        true if the property is updateable
      • getDescription

        public java.lang.String getDescription​(java.lang.String name)
        Gets a Human readable description of the property, e.g. to provide via JMX.
        Specified by:
        getDescription in interface PropertyBackedBean
        Parameters:
        name - the name
        Returns:
        the description
      • onApplicationEvent

        public void onApplicationEvent​(org.springframework.context.ApplicationEvent event)
        Specified by:
        onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
      • getProperty

        public java.lang.String getProperty​(java.lang.String name)
        Gets a property value.
        Specified by:
        getProperty in interface PropertyBackedBeanState
        Parameters:
        name - the name
        Returns:
        the property value
      • getPropertyNames

        public java.util.Set<java.lang.String> getPropertyNames()
        Gets the names of all properties.
        Specified by:
        getPropertyNames in interface PropertyBackedBeanState
        Returns:
        the property names
      • setProperty

        public void setProperty​(java.lang.String name,
                                java.lang.String value)
        Sets the value of a property. This may only be called after PropertyBackedBeanState.stop().

        When called from code within the local node the values are saved to the database in the Enterprise edition and will be visible in a JMX client.

        Specified by:
        setProperty in interface PropertyBackedBeanState
        Parameters:
        name -
        value -
      • setProperties

        public void setProperties​(java.util.Map<java.lang.String,​java.lang.String> properties)
        Tries setting the given properties on this component. Will leave the component in a started state consisting of the new properties if they are valid, or the previous state otherwise. Note that the new state still has to be confirmed to the entire cluster with PropertyBackedBeanState.start(), presumably after persistence of the new state has been completed.

        When called from code within the local node the values are saved to the database in the Enterprise edition and will be visible in a JMX client.

        Specified by:
        setProperties in interface PropertyBackedBean
        Parameters:
        properties - to be saved.
      • removeProperty

        public void removeProperty​(java.lang.String name)
        Removes a property added by code within the local node.
        Specified by:
        removeProperty in interface PropertyBackedBeanState
        Parameters:
        name - to be removed.
      • removeProperties

        public void removeProperties​(java.util.Collection<java.lang.String> properties)
        Removes properties added by code within the local node.
        Specified by:
        removeProperties in interface PropertyBackedBean
        Parameters:
        properties - to be removed.
      • start

        public final void start()
        Starts up the component, using its new property values.
        Specified by:
        start in interface PropertyBackedBeanState
      • start

        protected void start​(boolean broadcastNow,
                             boolean broadcastLater)
        Starts the bean, optionally broadcasting the event to remote nodes.
        Parameters:
        broadcastNow - Should the event be broadcast immediately?
        broadcastLater - Should the event be broadcast ever?
      • stop

        public final void stop()
        Stops the component, so that its property values can be changed.
        Specified by:
        stop in interface PropertyBackedBeanState
      • stop

        protected void stop​(boolean broadcast)
        Stops the bean, optionally broadcasting the event to remote nodes.
        Parameters:
        broadcast - Should the event be broadcast?