Package org.apache.felix.scr.impl
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 class
private static class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentMap
<Long, RegionConfigurationSupport> private final AtomicLong
private Timer
private final Object
private final ThreadLocal
<List<org.osgi.framework.ServiceReference<?>>> private long
Counter 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 ScrConfiguration
private final ScrLogger
private final Map
<org.osgi.framework.ServiceReference<?>, List<ComponentRegistry.Entry<?, ?>>> private static String
Service 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 ComponentRegistryKey
checkComponentName
(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 issueComponentHolder
instances to manage components described by the given componentmetadata
.<T> boolean
enterCreate
(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 ornull
if 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> void
leaveCreate
(org.osgi.framework.ServiceReference<T> serviceReference) <T> void
missingServicePresent
(org.osgi.framework.ServiceReference<T> serviceReference, ComponentActorThread actor) Schedule late binding of now-available reference on a different thread.(package private) final void
registerComponentHolder
(ComponentRegistryKey key, ComponentHolder<?> componentHolder) Registers the given component under the given name.(package private) final long
registerComponentId
(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) void
setRegistration
(org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> reg) (package private) final void
Removes the component registered under that name.(package private) final void
unregisterComponentHolder
(org.osgi.framework.Bundle bundle, String name) Removes the component registered under that name.(package private) final void
unregisterComponentId
(long componentId) Unregisters the component with the given component ID from the internal registry.void
void
-
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 theComponentHolder
interface.The
invalid reference
#checkComponentName(String)
invalid reference
#registerComponentHolder(String, ComponentHolder)
ComponentHolder
.- See Also:
-
m_componentHoldersByPid
The map of known components indexed by component configuration pid. The values are Sets of theComponentHolder
interface. 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 theinvalid 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 actualAbstractComponentManager
instances 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
- TheAbstractComponentManager
for 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 withinvalid reference
#registerComponentHolder(String, ComponentHolder)
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 callinginvalid 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 throughinvalid reference
#checkComponentName(String)
-
getComponentHolder
Returns the component registered under the given name ornull
if 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 orComponentHolder
instances 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 issueComponentHolder
instances 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()
-