Class ComponentFactoryImpl<S>

  • All Implemented Interfaces:
    ComponentContainer<S>, ComponentManager<S>, org.osgi.service.component.ComponentFactory<S>

    public class ComponentFactoryImpl<S>
    extends AbstractComponentManager<S>
    implements org.osgi.service.component.ComponentFactory<S>, ComponentContainer<S>
    The ComponentFactoryImpl extends the AbstractComponentManager class to implement the component factory functionality. As such the OSGi Declarative Services ComponentFactory interface is implemented.

    In addition the ComponentHolder interface is implemented to use this class directly as the holder for component instances created by the newInstance(Dictionary) method.

    This class implements spec-compliant component factories and the felix "persistent" component factory, where the factory is always registered whether or not all dependencies are present and the created components also persist whether or not the dependencies are present to allow the component instance to exist.

    • Field Detail

      • m_componentInstances

        private final java.util.Map<SingleComponentManager<S>,​SingleComponentManager<S>> m_componentInstances
        Contains the component instances created by calling the newInstance(Dictionary) method. These component instances are provided with updated configuration (or deleted configuration) if such modifications for the component factory takes place.

        The map is keyed by the component manager instances. The value of each entry is the same as the entry's key. This is an IdentityHashMap for speed, thus not a Set.

      • m_configuration

        private volatile java.util.Map<java.lang.String,​java.lang.Object> m_configuration
        The configuration for the component factory. This configuration is supplied as the base configuration for each component instance created by the newInstance(Dictionary) method.
      • m_hasConfiguration

        private volatile boolean m_hasConfiguration
        Flag telling if our component factory is currently configured from config admin. We are configured when configuration policy is required and we have received the config admin properties, or when configuration policy is optional or ignored.
      • m_changeCount

        protected volatile long m_changeCount
        Configuration change count (R5) or imitation (R4)
    • Method Detail

      • newInstance

        public org.osgi.service.component.ComponentInstance<S> newInstance​(java.util.Dictionary<java.lang.String,​?> dictionary)
        Specified by:
        newInstance in interface org.osgi.service.component.ComponentFactory<S>
      • equals

        public boolean equals​(java.lang.Object object)
        Compares this ComponentFactoryImpl object to another object.

        A component factory impl is considered to be equal to another component factory impl if the component names are equal(using String.equals).

        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - The ComponentFactoryImpl object to be compared.
        Returns:
        true if object is a ComponentFactoryImpl and is equal to this object; false otherwise.
      • hashCode

        public int hashCode()
        Returns a hash code value for the object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        An integer which is a hash code value for this object.
      • deleteComponent

        protected void deleteComponent​(int reason)
        The component factory does not have a component to delete.

        But in the backwards compatible case any instances created for factory configuration instances are to disabled as a consequence of deactivating the component factory.

        Specified by:
        deleteComponent in class AbstractComponentManager<S>
      • hasConfiguration

        public boolean hasConfiguration()
      • getProperties

        public java.util.Map<java.lang.String,​java.lang.Object> getProperties()
        For ComponentFactoryImpl, this is used only for updating targets on the dependency managers, so we don't need any other properties.
        Specified by:
        getProperties in interface ComponentManager<S>
        Specified by:
        getProperties in class AbstractComponentManager<S>
      • getServiceProperties

        public java.util.Dictionary<java.lang.String,​java.lang.Object> getServiceProperties()
        Description copied from class: AbstractComponentManager
        Returns the subset of component properties to be used as service properties. These properties are all component properties where property name does not start with dot (.), properties which are considered private.
        Overrides:
        getServiceProperties in class AbstractComponentManager<S>
      • collectDependencies

        protected boolean collectDependencies​(ComponentContextImpl<S> componentContext)
        Description copied from class: AbstractComponentManager
        Collect and store in m_dependencies_map all the services for dependencies, outside of any locks.
        Overrides:
        collectDependencies in class AbstractComponentManager<S>
        Parameters:
        componentContext - possible instance key for prototype scope references
        Returns:
        true if all references can be collected, false if some dependency is no longer available.
      • dispose

        public void dispose​(int reason)
        Disposes off all components ever created by this component holder. This method is called if either the Declarative Services runtime is stopping or if the owning bundle is stopped. In both cases all components created by this holder must be disposed off.
        Overrides:
        dispose in class AbstractComponentManager<S>