Class ComponentRegistry
java.lang.Object
org.apache.felix.scr.impl.ComponentRegistry
The
ComponentRegistry class acts as the global registry for
components by name and by component ID.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classprivate static classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentMap<Long, RegionConfigurationSupport> private final AtomicLongprivate Timerprivate final Objectprivate final ThreadLocal<List<org.osgi.framework.ServiceReference<?>>> private longCounter to setup the component IDs as issued by theregisterComponentId(AbstractComponentManager)method.private final Map<ComponentRegistryKey, ComponentHolder<?>> The map of known components indexed by component name.private final Map<String, Set<ComponentHolder<?>>> The map of known components indexed by component configuration pid.private final Map<Long, AbstractComponentManager<?>> Map of components by component ID.private final ScrConfigurationprivate final ScrLoggerprivate final Map<org.osgi.framework.ServiceReference<?>, List<ComponentRegistry.Entry<?, ?>>> private static StringService property for change count.private org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final ComponentRegistryKeycheckComponentName(org.osgi.framework.Bundle bundle, String name) Checks whether the component name is "globally" unique or not.<S> ComponentHolder<S> createComponentHolder(ComponentActivator activator, ComponentMetadata metadata, ComponentLogger logger) Factory method to issueComponentHolderinstances to manage components described by the given componentmetadata.<T> booleanenterCreate(org.osgi.framework.ServiceReference<T> serviceReference) Track getService calls by service reference.final ComponentHolder<?> getComponentHolder(org.osgi.framework.Bundle bundle, String name) Returns the component registered under the given name ornullif no component is registered yet.final List<ComponentHolder<?>> Returns an array of all values currently stored in the component holders map.final List<ComponentHolder<?>> getComponentHolders(org.osgi.framework.Bundle... bundles) final Collection<ComponentHolder<?>> getComponentHoldersByPid(TargetedPID targetedPid) Returns the set of ComponentHolder instances whose configuration pids are matching the given pid.<T> voidleaveCreate(org.osgi.framework.ServiceReference<T> serviceReference) <T> voidmissingServicePresent(org.osgi.framework.ServiceReference<T> serviceReference, ComponentActorThread actor) Schedule late binding of now-available reference on a different thread.(package private) final voidregisterComponentHolder(ComponentRegistryKey key, ComponentHolder<?> componentHolder) Registers the given component under the given name.(package private) final longregisterComponentId(AbstractComponentManager<?> componentManager) Assigns a unique ID to the component, internally registers the component under that ID and returns the assigned component ID.<S,T> void registerMissingDependency(DependencyManager<S, T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount) registerRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference) voidsetRegistration(org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> reg) (package private) final voidRemoves the component registered under that name.(package private) final voidunregisterComponentHolder(org.osgi.framework.Bundle bundle, String name) Removes the component registered under that name.(package private) final voidunregisterComponentId(long componentId) Unregisters the component with the given component ID from the internal registry.voidvoid
-
Field Details
-
PROP_CHANGECOUNT
Service property for change count. This constant is defined here to avoid a dependency on R7 of the framework. The value of the property is of typeLong. -
m_componentHoldersByName
The map of known components indexed by component name. The values are either null (for name reservations) or implementations of theComponentHolderinterface.The
will first add an entry to this map with null value to reserve the name. After setting up the component, theinvalid reference
#checkComponentName(String)method replaces the value of the named entry with the actualinvalid reference
#registerComponentHolder(String, ComponentHolder)ComponentHolder.- See Also:
-
m_componentHoldersByPid
The map of known components indexed by component configuration pid. The values are Sets of theComponentHolderinterface. Normally, the configuration pid is the component name, but since DS 1.2 (OSGi 4.3), a component may specify a specific pid, and it is possible that different components refer to the same pid. That's why the values of this map are Sets of ComponentHolders, allowing to lookup all components which are using a given configuration pid. This map is used when the ConfigurationSupport detects that a CM pid is updated. When a PID is updated, the ConfigurationSupport listener class invokes themethod which returns an iterator over all components that are using the given pid for configuration.invalid reference
#getComponentHoldersByPid(String)- See Also:
-
m_componentsById
Map of components by component ID. This map indexed by the component ID number (java.lang.Long) contains the actualAbstractComponentManagerinstances existing in the system.- See Also:
-
m_componentCounter
private long m_componentCounterCounter to setup the component IDs as issued by theregisterComponentId(AbstractComponentManager)method. This counter is only incremented. -
m_missingDependencies
private final Map<org.osgi.framework.ServiceReference<?>, List<ComponentRegistry.Entry<?,?>>> m_missingDependencies -
m_logger
-
m_configuration
-
circularInfos
-
bundleToRcsMap
-
changeCount
-
changeCountTimer
-
changeCountTimerLock
-
registration
private volatile org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> registration
-
-
Constructor Details
-
ComponentRegistry
-
-
Method Details
-
registerComponentId
Assigns a unique ID to the component, internally registers the component under that ID and returns the assigned component ID.- Parameters:
componentManager- TheAbstractComponentManagerfor which to assign a component ID and which is to be internally registered- Returns:
- the assigned component ID
-
unregisterComponentId
final void unregisterComponentId(long componentId) Unregisters the component with the given component ID from the internal registry. After unregistration, the component ID should be considered invalid.- Parameters:
componentId- The ID of the component to be removed from the internal component registry.
-
checkComponentName
Checks whether the component name is "globally" unique or not. If it is unique, it is reserved until the actual component is registered withor until it is unreserved by callinginvalid reference
#registerComponentHolder(String, ComponentHolder). If a component with the same name has already been reserved or registered a ComponentException is thrown with a descriptive message.invalid reference
#unregisterComponentHolder(String)- Parameters:
bundle- the bundle registering the componentname- the component name to check and reserve- Throws:
org.osgi.service.component.ComponentException- if the name is already in use by another component.
-
registerComponentHolder
Registers the given component under the given name. If the name has not already been reserved callingthis method throws ainvalid reference
#checkComponentName(String)ComponentException.- Parameters:
componentHolder- The component to registername- The name to register the component under- Throws:
org.osgi.service.component.ComponentException- if the name has not been reserved throughyet.invalid reference
#checkComponentName(String)
-
getComponentHolder
Returns the component registered under the given name ornullif no component is registered yet. -
getComponentHoldersByPid
Returns the set of ComponentHolder instances whose configuration pids are matching the given pid.- Parameters:
pid- the pid candidate- Returns:
- the set of ComponentHolders matching the singleton pid supplied
-
getComponentHolders
Returns an array of all values currently stored in the component holders map. The entries in the array are either String types for component name reservations orComponentHolderinstances for actual holders of components. -
getComponentHolders
-
unregisterComponentHolder
Removes the component registered under that name. If no component is yet registered but the name is reserved, it is unreserved.After calling this method, the name can be reused by other components.
-
unregisterComponentHolder
Removes the component registered under that name. If no component is yet registered but the name is reserved, it is unreserved.After calling this method, the name can be reused by other components.
-
createComponentHolder
public <S> ComponentHolder<S> createComponentHolder(ComponentActivator activator, ComponentMetadata metadata, ComponentLogger logger) Factory method to issueComponentHolderinstances to manage components described by the given componentmetadata. -
enterCreate
public <T> boolean enterCreate(org.osgi.framework.ServiceReference<T> serviceReference) Track getService calls by service reference.- Parameters:
serviceReference-- Returns:
- true is we have encountered a circular dependency, false otherwise.
-
leaveCreate
public <T> void leaveCreate(org.osgi.framework.ServiceReference<T> serviceReference) -
missingServicePresent
public <T> void missingServicePresent(org.osgi.framework.ServiceReference<T> serviceReference, ComponentActorThread actor) Schedule late binding of now-available reference on a different thread. The late binding cannot occur on this thread due to service registry circular reference detection. We cannot wait for the late binding before returning from the initial getService call because of synchronization in the service registry.- Parameters:
serviceReference-actor-
-
registerMissingDependency
public <S,T> void registerMissingDependency(DependencyManager<S, T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount) -
registerRegionConfigurationSupport
public RegionConfigurationSupport registerRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference) -
registerRegionConfigurationSupport
public RegionConfigurationSupport registerRegionConfigurationSupport(RegionConfigurationSupport trialRcs) -
unregisterRegionConfigurationSupport
-
getServiceRegistrationProperties
-
setRegistration
public void setRegistration(org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> reg) -
updateChangeCount
public void updateChangeCount()
-