Class ConfigurableComponentHolder<S>
java.lang.Object
org.apache.felix.scr.impl.manager.ConfigurableComponentHolder<S>
- All Implemented Interfaces:
ComponentContainer<S>, ComponentHolder<S>
- Direct Known Subclasses:
ComponentRegistry.DefaultConfigurableComponentHolder
public abstract class ConfigurableComponentHolder<S>
extends Object
implements ComponentHolder<S>, ComponentContainer<S>
The
ConfigurableComponentHolder class is a
ComponentHolder for automatically configured components instances
that may or may not be configured through Config Admin.
The holder copes with three situations:
- No configuration is available for the held component. That is there is
no configuration whose
service.pidorservice.factoryPidequals the component name. - A singleton configuration is available whose
service.pidequals the component name. - One or more factory configurations exist whose
service.factoryPidequals the component name.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Objectprivate final ComponentLoggerprivate final ComponentActivatorThe activator owning the per-bundle componentsprivate final Long[]private final ComponentMetadataTheComponentMetadatadescribing the held component(s)private final ComponentMethods<S> private final Map<String, AbstractComponentManager<S>> A map of components configured with factory configuration.private final Dictionary<String,Object>[] the non-factory configurations shared between all instances.private org.osgi.util.promise.Promise<Void> private booleanWhether components have already been enabled by calling theenableComponents(boolean)method.private org.osgi.util.promise.Promise<Void> private final Map<String, Dictionary<String, Object>> the factory configurations indexed by pid (which cannot be a TargetedPID since it's generated by CA).private Integerthe index in metadata.getConfigurationPid() of the base factory pid, if any.private final Map<String, TargetedPID> Each factory config may be from a different TargetedPID (sharing the same base service pid, but with different level of detail)private AbstractComponentManager<S> The special component used if there is no configuration or a singleton configuration.private final TargetedPID[]the targeted pids corresponding to the pids specified in the config metadata, except possibly for the single factory pid -
Constructor Summary
ConstructorsConstructorDescriptionConfigurableComponentHolder(ComponentActivator activator, ComponentMetadata metadata, ComponentLogger logger) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckFactoryPidIndex(TargetedPID factoryPid) (package private) voidvoidconfigurationDeleted(TargetedPID pid, TargetedPID factoryPid) The configuration with the givenpid(service.pidof the configuration object) is deleted.booleanconfigurationUpdated(TargetedPID pid, TargetedPID factoryPid, Dictionary<String, Object> props, long changeCount) Configures a component with the given configuration.protected static voidprotected AbstractComponentManager<S> createComponentManager(boolean factoryConfiguration) protected abstract ComponentMethods<S> org.osgi.util.promise.Promise<Void> disableComponents(boolean async) Disables all components of this holder.voiddisposeComponents(int reason) Disposes off all components of this holder.voiddisposed(SingleComponentManager<S> component) Informs the holder that the component has been disposed as a result of calling the dispose method.org.osgi.util.promise.Promise<Void> enableComponents(boolean async) Enables all components of this holder and if satisfied activates them.booleanCompares thisImmediateComponentHolderobject to another object.final ComponentActivatorReturns theComponentActivatorowning this component holder.(package private) List<AbstractComponentManager<S>> Returns all component managers from the map and the single component manager, optionally also removing them from the map.final ComponentMetadataReturns theComponentMetadatadescribing and declaring this component.protected ComponentMethods<S> List<? extends ComponentManager<?>> Returns allComponentinstances held by this holder.getConfigurationTargetedPID(TargetedPID pid, TargetedPID factoryPid) Returns the targeted PID used to configure this component(package private) List<AbstractComponentManager<S>> (package private) StringgetName()private intinthashCode()Returns a hash code value for the object.booleanwhether the component is currently enabledprivate booleanDetermine if the holder is satisfied with configurationsmergeProperties(String servicePid) toString()private void
-
Field Details
-
m_activator
The activator owning the per-bundle components -
m_componentMetadata
TheComponentMetadatadescribing the held component(s) -
m_targetedPids
the targeted pids corresponding to the pids specified in the config metadata, except possibly for the single factory pid -
m_changeCount
-
m_factoryChangeCount
-
m_factoryPidIndex
the index in metadata.getConfigurationPid() of the base factory pid, if any. Each component created from a factory configuration might have a different targeted pid. -
m_configurations
the non-factory configurations shared between all instances. -
m_factoryConfigurations
the factory configurations indexed by pid (which cannot be a TargetedPID since it's generated by CA). We have to track these since other required configs may not yet be present so we can't create the component manager yet. -
m_factoryTargetedPids
Each factory config may be from a different TargetedPID (sharing the same base service pid, but with different level of detail) -
m_components
A map of components configured with factory configuration. The indices are the PIDs (service.pid) of the configuration objects. The values are thecomponent instancescreated on behalf of the configurations. -
m_singleComponent
The special component used if there is no configuration or a singleton configuration. This field is onlynullonce all components held by this holder have been disposed of bydisposeComponents(int)and is first created in the constructor. As factory configurations are provided this instance may be configured or "deconfigured".Expected invariants:
- This field is only
nullafter disposal of all held components - The
m_componentsmap is empty or the component pointed to by this field is also contained in the map
- This field is only
-
m_enabled
private volatile boolean m_enabledWhether components have already been enabled by calling theenableComponents(boolean)method. If this field istruecomponent instances created per configuration by theconfigurationUpdated(TargetedPID, TargetedPID, Dictionary, long)method are also enabled. Otherwise they are not enabled immediately. -
enableLock
-
m_enablePromise
-
m_disablePromise
-
m_componentMethods
-
logger
-
-
Constructor Details
-
ConfigurableComponentHolder
public ConfigurableComponentHolder(ComponentActivator activator, ComponentMetadata metadata, ComponentLogger logger)
-
-
Method Details
-
createComponentMethods
-
getComponentMethods
-
createComponentManager
-
getActivator
Description copied from interface:ComponentHolderReturns theComponentActivatorowning this component holder. (overlaps ComponentContaienr)- Specified by:
getActivatorin interfaceComponentContainer<S>- Specified by:
getActivatorin interfaceComponentHolder<S>
-
getComponentMetadata
Description copied from interface:ComponentHolderReturns theComponentMetadatadescribing and declaring this component. (overlaps ComponentContaienr)- Specified by:
getComponentMetadatain interfaceComponentContainer<S>- Specified by:
getComponentMetadatain interfaceComponentHolder<S>
-
configurationDeleted
The configuration with the givenpid(service.pidof the configuration object) is deleted.The following situations are supported:
- The configuration was a singleton configuration (pid equals the component name). In this case the internal component map is empty and the single component has been configured by the singleton configuration and is no "deconfigured".
- A factory configuration object has been deleted and the configured object is set as the single component. If the single component held the last factory configuration object, it is deconfigured. Otherwise the single component is disposed off and replaced by another component in the map of existing components.
- A factory configuration object has been deleted and the configured object is not set as the single component. In this case the component is simply disposed off and removed from the internal map.
- Specified by:
configurationDeletedin interfaceComponentHolder<S>- Parameters:
pid- The PID of the deleted configurationfactoryPid- The factory PID of the deleted configuration
-
configurationUpdated
public boolean configurationUpdated(TargetedPID pid, TargetedPID factoryPid, Dictionary<String, Object> props, long changeCount) Configures a component with the given configuration. This configuration update may happen in various situations:- The
pidequals the component name. Hence we have a singleton configuration for the single component held by this holder - The configuration is a factory configuration and is the first configuration provided. In this case the single component is provided with the configuration and also stored in the map.
- The configuration is a factory configuration but not the first. In this case a new component is created, configured and stored in the map
- Specified by:
configurationUpdatedin interfaceComponentHolder<S>- Parameters:
pid- Targeted PID for the configurationfactoryPid- the (targeted) factory pid or null for a singleton pidprops- the property dictionary from the configuration.changeCount- change count of the configuration, or R4 imitation.- Returns:
- true if a new configuration was created, false otherwise. TODO there are now 3 states..... still not satisfied, existing, and new
- The
-
mergeProperties
-
getSingletonPidIndex
-
checkFactoryPidIndex
-
copyTo
-
isSatisfied
private boolean isSatisfied()Determine if the holder is satisfied with configurations- Returns:
- true if configuration optional or all pids supplied with configurations
-
getComponents
Description copied from interface:ComponentHolderReturns allComponentinstances held by this holder.- Specified by:
getComponentsin interfaceComponentHolder<S>
-
isEnabled
public boolean isEnabled()Description copied from interface:ComponentHolderwhether the component is currently enabled- Specified by:
isEnabledin interfaceComponentHolder<S>- Returns:
- whether the component is enabled
-
wait
-
enableComponents
Description copied from interface:ComponentHolderEnables all components of this holder and if satisfied activates them.- Specified by:
enableComponentsin interfaceComponentHolder<S>- Parameters:
async- Whether the actual activation should take place asynchronously or not.
-
disableComponents
Description copied from interface:ComponentHolderDisables all components of this holder.- Specified by:
disableComponentsin interfaceComponentHolder<S>- Parameters:
async- Whether the actual deactivation should take place asynchronously or not.
-
disposeComponents
public void disposeComponents(int reason) Description copied from interface:ComponentHolderDisposes off all components of this holder.- Specified by:
disposeComponentsin interfaceComponentHolder<S>- Parameters:
reason-
-
disposed
Description copied from interface:ComponentContainerInforms the holder that the component has been disposed as a result of calling the dispose method.- Specified by:
disposedin interfaceComponentContainer<S>
-
equals
Compares thisImmediateComponentHolderobject to another object.A ImmediateComponentHolder is considered to be equal to another ImmediateComponentHolder if the component names are equal(using
String.equals) and they have the same bundle activator -
hashCode
-
toString
-
getName
String getName() -
getComponentManagers
List<AbstractComponentManager<S>> getComponentManagers()Returns all component managers from the map and the single component manager, optionally also removing them from the map. If there are no component managers,nullis returned. Must be called synchronized on m_components. -
getDirectComponentManagers
List<AbstractComponentManager<S>> getDirectComponentManagers() -
clearComponents
void clearComponents() -
getLogger
- Specified by:
getLoggerin interfaceComponentContainer<S>
-
getConfigurationTargetedPID
Description copied from interface:ComponentHolderReturns the targeted PID used to configure this component- Specified by:
getConfigurationTargetedPIDin interfaceComponentHolder<S>- Parameters:
pid- a targetedPID containing the service pid for the component desired (the rest of the targeted pid is ignored)factoryPid- a targetedPID containing the factory pid for the component desired.- Returns:
- the complete targeted pid actually used to configure the comonent.
-