Package org.apache.felix.scr.impl
Class ComponentRegistry
- java.lang.Object
-
- org.apache.felix.scr.impl.ComponentRegistry
-
public class ComponentRegistry extends java.lang.ObjectTheComponentRegistryclass acts as the global registry for components by name and by component ID.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classComponentRegistry.DefaultConfigurableComponentHolder<S>private static classComponentRegistry.Entry<S,T>private classComponentRegistry.Info
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentMap<java.lang.Long,RegionConfigurationSupport>bundleToRcsMapprivate longchangeCountprivate java.lang.ObjectchangeCountLockprivate java.lang.ThreadLocal<java.util.List<org.osgi.framework.ServiceReference<?>>>circularInfosprivate longm_componentCounterCounter to setup the component IDs as issued by theregisterComponentId(AbstractComponentManager)method.private java.util.Map<ComponentRegistryKey,ComponentHolder<?>>m_componentHoldersByNameThe map of known components indexed by component name.private java.util.Map<java.lang.String,java.util.Set<ComponentHolder<?>>>m_componentHoldersByPidThe map of known components indexed by component configuration pid.private java.util.Map<java.lang.Long,AbstractComponentManager<?>>m_componentsByIdMap of components by component ID.private ScrConfigurationm_configurationprivate ScrLoggerm_loggerprivate java.util.Map<org.osgi.framework.ServiceReference<?>,java.util.List<ComponentRegistry.Entry<?,?>>>m_missingDependenciesprivate static java.lang.StringPROP_CHANGECOUNTService property for change count.private org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime>registrationprivate java.util.Timertimer
-
Constructor Summary
Constructors Constructor Description ComponentRegistry(ScrConfiguration scrConfiguration, ScrLogger logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) ComponentRegistryKeycheckComponentName(org.osgi.framework.Bundle bundle, java.lang.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.ComponentHolder<?>getComponentHolder(org.osgi.framework.Bundle bundle, java.lang.String name)Returns the component registered under the given name ornullif no component is registered yet.java.util.List<ComponentHolder<?>>getComponentHolders()Returns an array of all values currently stored in the component holders map.java.util.List<ComponentHolder<?>>getComponentHolders(org.osgi.framework.Bundle... bundles)java.util.Collection<ComponentHolder<?>>getComponentHoldersByPid(TargetedPID targetedPid)Returns the set of ComponentHolder instances whose configuration pids are matching the given pid.java.util.Dictionary<java.lang.String,java.lang.Object>getServiceRegistrationProperties()<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) voidregisterComponentHolder(ComponentRegistryKey key, ComponentHolder<?> componentHolder)Registers the given component under the given name.(package private) 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>
voidregisterMissingDependency(DependencyManager<S,T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount)RegionConfigurationSupportregisterRegionConfigurationSupport(RegionConfigurationSupport trialRcs)RegionConfigurationSupportregisterRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference)voidsetRegistration(org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> reg)(package private) voidunregisterComponentHolder(ComponentRegistryKey key)Removes the component registered under that name.(package private) voidunregisterComponentHolder(org.osgi.framework.Bundle bundle, java.lang.String name)Removes the component registered under that name.(package private) voidunregisterComponentId(long componentId)Unregisters the component with the given component ID from the internal registry.voidunregisterRegionConfigurationSupport(RegionConfigurationSupport rcs)voidupdateChangeCount()
-
-
-
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 typeLong.
-
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 theComponentHolderinterface.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 actualComponentHolder.- 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 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 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_componentsById
private final java.util.Map<java.lang.Long,AbstractComponentManager<?>> 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.
-
m_componentCounter
private long m_componentCounter
Counter to setup the component IDs as issued by theregisterComponentId(AbstractComponentManager)method. This counter is only incremented.
-
m_missingDependencies
private final java.util.Map<org.osgi.framework.ServiceReference<?>,java.util.List<ComponentRegistry.Entry<?,?>>> m_missingDependencies
-
m_logger
private final ScrLogger m_logger
-
m_configuration
private final ScrConfiguration m_configuration
-
circularInfos
private final java.lang.ThreadLocal<java.util.List<org.osgi.framework.ServiceReference<?>>> circularInfos
-
bundleToRcsMap
private final java.util.concurrent.ConcurrentMap<java.lang.Long,RegionConfigurationSupport> bundleToRcsMap
-
changeCountLock
private final java.lang.Object changeCountLock
-
changeCount
private volatile long changeCount
-
timer
private volatile java.util.Timer timer
-
registration
private volatile org.osgi.framework.ServiceRegistration<org.osgi.service.component.runtime.ServiceComponentRuntime> registration
-
-
Constructor Detail
-
ComponentRegistry
public ComponentRegistry(ScrConfiguration scrConfiguration, ScrLogger logger)
-
-
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- 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
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 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
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 aComponentException.- Parameters:
name- The name to register the component undercomponentHolder- 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 ornullif 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 orComponentHolderinstances 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.
-
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
public void unregisterRegionConfigurationSupport(RegionConfigurationSupport rcs)
-
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()
-
-