Class ComponentRegistry

java.lang.Object
org.apache.felix.scr.impl.ComponentRegistry

public class ComponentRegistry extends Object
The ComponentRegistry class acts as the global registry for components by name and by component ID.
  • Field Details

    • PROP_CHANGECOUNT

      private static String 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 type Long.
    • m_componentHoldersByName

      private final Map<ComponentRegistryKey,ComponentHolder<?>> m_componentHoldersByName
      The map of known components indexed by component name. The values are either null (for name reservations) or implementations of the ComponentHolder interface.

      The #checkComponentName(String) will first add an entry to this map with null value to reserve the name. After setting up the component, the #registerComponentHolder(String, ComponentHolder) method replaces the value of the named entry with the actual ComponentHolder.

      See Also:
      • #checkComponentName(String)
      • #registerComponentHolder(String, ComponentHolder)
      • #unregisterComponentHolder(String)
    • m_componentHoldersByPid

      private final Map<String,Set<ComponentHolder<?>>> m_componentHoldersByPid
      The map of known components indexed by component configuration pid. The values are Sets of the ComponentHolder 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 the #getComponentHoldersByPid(String) method which returns an iterator over all components that are using the given pid for configuration.

      See Also:
    • m_componentsById

      private final Map<Long,AbstractComponentManager<?>> m_componentsById
      Map of components by component ID. This map indexed by the component ID number (java.lang.Long) contains the actual AbstractComponentManager instances existing in the system.
      See Also:
    • m_componentCounter

      private long m_componentCounter
      Counter to setup the component IDs as issued by the registerComponentId(AbstractComponentManager) method. This counter is only incremented.
    • m_missingDependencies

      private final Map<org.osgi.framework.ServiceReference<?>,List<ComponentRegistry.Entry<?,?>>> m_missingDependencies
    • m_logger

      private final ScrLogger m_logger
    • m_configuration

      private final ScrConfiguration m_configuration
    • circularInfos

      private final ThreadLocal<List<org.osgi.framework.ServiceReference<?>>> circularInfos
    • bundleToRcsMap

      private final ConcurrentMap<Long,RegionConfigurationSupport> bundleToRcsMap
    • changeCountLock

      private final Object changeCountLock
    • changeCount

      private volatile long changeCount
    • timer

      private volatile Timer timer
    • registration

      private volatile org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> registration
  • Constructor Details

  • Method Details

    • registerComponentId

      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.
      Parameters:
      componentManager - The AbstractComponentManager 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

      final ComponentRegistryKey checkComponentName(org.osgi.framework.Bundle bundle, String name)
      Checks whether the component name is "globally" unique or not. If it is unique, it is reserved until the actual component is registered with #registerComponentHolder(String, ComponentHolder) or until it is unreserved by calling #unregisterComponentHolder(String). If a component with the same name has already been reserved or registered a ComponentException is thrown with a descriptive message.
      Parameters:
      bundle - the bundle registering the component
      name - the component name to check and reserve
      Throws:
      org.osgi.service.component.ComponentException - if the name is already in use by another component.
    • registerComponentHolder

      final void registerComponentHolder(ComponentRegistryKey key, ComponentHolder<?> componentHolder)
      Registers the given component under the given name. If the name has not already been reserved calling #checkComponentName(String) this method throws a ComponentException.
      Parameters:
      name - The name to register the component under
      componentHolder - The component to register
      Throws:
      org.osgi.service.component.ComponentException - if the name has not been reserved through #checkComponentName(String) yet.
    • getComponentHolder

      public final ComponentHolder<?> getComponentHolder(org.osgi.framework.Bundle bundle, String name)
      Returns the component registered under the given name or null if no component is registered yet.
    • getComponentHoldersByPid

      public final Collection<ComponentHolder<?>> getComponentHoldersByPid(TargetedPID targetedPid)
      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

      public final List<ComponentHolder<?>> 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 or ComponentHolder instances for actual holders of components.
    • getComponentHolders

      public final List<ComponentHolder<?>> getComponentHolders(org.osgi.framework.Bundle... bundles)
    • unregisterComponentHolder

      final void unregisterComponentHolder(org.osgi.framework.Bundle bundle, String name)
      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

      final void unregisterComponentHolder(ComponentRegistryKey key)
      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 issue ComponentHolder instances to manage components described by the given component metadata.
    • 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

      public void unregisterRegionConfigurationSupport(RegionConfigurationSupport rcs)
    • getServiceRegistrationProperties

      public Dictionary<String,Object> getServiceRegistrationProperties()
    • setRegistration

      public void setRegistration(org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> reg)
    • updateChangeCount

      public void updateChangeCount()