Class ComponentRegistry


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

      • PROP_CHANGECOUNT

        private static java.lang.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 java.util.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 java.util.Map<java.lang.String,​java.util.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:
        #registerComponentHolder(String, ComponentHolder), #unregisterComponentHolder(String), RegionConfigurationSupport.configurationEvent(org.osgi.service.cm.ConfigurationEvent)
      • m_missingDependencies

        private final java.util.Map<org.osgi.framework.ServiceReference<?>,​java.util.List<ComponentRegistry.Entry<?,​?>>> m_missingDependencies
      • circularInfos

        private final java.lang.ThreadLocal<java.util.List<org.osgi.framework.ServiceReference<?>>> circularInfos
      • changeCount

        private final java.util.concurrent.atomic.AtomicLong changeCount
      • changeCountTimer

        private volatile java.util.Timer changeCountTimer
      • changeCountTimerLock

        private final java.lang.Object changeCountTimerLock
      • registration

        private volatile org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> registration
    • Method Detail

      • 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,
                                                      java.lang.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,
                                                           java.lang.String name)
        Returns the component registered under the given name or null if no component is registered yet.
      • getComponentHoldersByPid

        public final java.util.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 java.util.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 java.util.List<ComponentHolder<?>> getComponentHolders​(org.osgi.framework.Bundle... bundles)
      • unregisterComponentHolder

        final void unregisterComponentHolder​(org.osgi.framework.Bundle bundle,
                                             java.lang.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.

      • 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)
      • getServiceRegistrationProperties

        public java.util.Dictionary<java.lang.String,​java.lang.Object> getServiceRegistrationProperties()
      • setRegistration

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

        public void updateChangeCount()