public class ComponentRegistry
extends java.lang.Object
ComponentRegistry
class acts as the global registry for
components by name and by component ID.Modifier and Type | Class and Description |
---|---|
(package private) static class |
ComponentRegistry.DefaultConfigurableComponentHolder<S> |
private static class |
ComponentRegistry.Entry<S,T> |
private class |
ComponentRegistry.Info |
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.ConcurrentMap<java.lang.Long,RegionConfigurationSupport> |
bundleToRcsMap |
private java.lang.ThreadLocal<java.util.List<org.osgi.framework.ServiceReference<?>>> |
circularInfos |
private long |
m_componentCounter
Counter to setup the component IDs as issued by the
registerComponentId(AbstractComponentManager) method. |
private java.util.Map<ComponentRegistryKey,ComponentHolder<?>> |
m_componentHoldersByName
The map of known components indexed by component name.
|
private java.util.Map<java.lang.String,java.util.Set<ComponentHolder<?>>> |
m_componentHoldersByPid
The map of known components indexed by component configuration pid.
|
private java.util.Map<java.lang.Long,AbstractComponentManager<?>> |
m_componentsById
Map of components by component ID.
|
private SimpleLogger |
m_logger |
private java.util.Map<org.osgi.framework.ServiceReference<?>,java.util.List<ComponentRegistry.Entry<?,?>>> |
m_missingDependencies |
Constructor and Description |
---|
ComponentRegistry(SimpleLogger logger) |
Modifier and Type | Method and Description |
---|---|
(package private) ComponentRegistryKey |
checkComponentName(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)
Factory method to issue
ComponentHolder instances to manage
components described by the given component metadata . |
<T> boolean |
enterCreate(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 or
null
if 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.
|
(package private) static boolean |
isBundleActive(org.osgi.framework.Bundle bundle)
Returns
true if the bundle is to be considered
active from the perspective of declarative services. |
<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) void |
registerComponentHolder(ComponentRegistryKey key,
ComponentHolder<?> componentHolder)
Registers the given component under the given name.
|
(package private) 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) |
RegionConfigurationSupport |
registerRegionConfigurationSupport(RegionConfigurationSupport trialRcs) |
RegionConfigurationSupport |
registerRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference) |
(package private) void |
unregisterComponentHolder(org.osgi.framework.Bundle bundle,
java.lang.String name)
Removes the component registered under that name.
|
(package private) void |
unregisterComponentHolder(ComponentRegistryKey key)
Removes the component registered under that name.
|
(package private) void |
unregisterComponentId(long componentId)
Unregisters the component with the given component ID from the internal
registry.
|
void |
unregisterRegionConfigurationSupport(RegionConfigurationSupport rcs) |
private final java.util.Map<ComponentRegistryKey,ComponentHolder<?>> m_componentHoldersByName
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
.
#checkComponentName(String)
,
#registerComponentHolder(String, ComponentHolder)
,
#unregisterComponentHolder(String)
private final java.util.Map<java.lang.String,java.util.Set<ComponentHolder<?>>> m_componentHoldersByPid
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.
#registerComponentHolder(String, ComponentHolder)
,
#unregisterComponentHolder(String)
,
RegionConfigurationSupport.configurationEvent(org.osgi.service.cm.ConfigurationEvent)
private final java.util.Map<java.lang.Long,AbstractComponentManager<?>> m_componentsById
java.lang.Long
) contains the actual
AbstractComponentManager
instances existing in the system.private long m_componentCounter
registerComponentId(AbstractComponentManager)
method. This
counter is only incremented.private final java.util.Map<org.osgi.framework.ServiceReference<?>,java.util.List<ComponentRegistry.Entry<?,?>>> m_missingDependencies
private final SimpleLogger m_logger
private final java.lang.ThreadLocal<java.util.List<org.osgi.framework.ServiceReference<?>>> circularInfos
private final java.util.concurrent.ConcurrentMap<java.lang.Long,RegionConfigurationSupport> bundleToRcsMap
public ComponentRegistry(SimpleLogger logger)
final long registerComponentId(AbstractComponentManager<?> componentManager)
componentManager
- The AbstractComponentManager
for which
to assign a component ID and which is to be internally registeredfinal void unregisterComponentId(long componentId)
componentId
- The ID of the component to be removed from the
internal component registry.final ComponentRegistryKey checkComponentName(org.osgi.framework.Bundle bundle, java.lang.String name)
#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.bundle
- the bundle registering the componentname
- the component name to check and reserveorg.osgi.service.component.ComponentException
- if the name is already in use by another
component.final void registerComponentHolder(ComponentRegistryKey key, ComponentHolder<?> componentHolder)
#checkComponentName(String)
this
method throws a ComponentException
.name
- The name to register the component undercomponentHolder
- The component to registerorg.osgi.service.component.ComponentException
- if the name has not been reserved through
#checkComponentName(String)
yet.public final ComponentHolder<?> getComponentHolder(org.osgi.framework.Bundle bundle, java.lang.String name)
null
if no component is registered yet.public final java.util.Collection<ComponentHolder<?>> getComponentHoldersByPid(TargetedPID targetedPid)
pid
- the pid candidatepublic final java.util.List<ComponentHolder<?>> getComponentHolders()
ComponentHolder
instances for actual
holders of components.public final java.util.List<ComponentHolder<?>> getComponentHolders(org.osgi.framework.Bundle... bundles)
final void unregisterComponentHolder(org.osgi.framework.Bundle bundle, java.lang.String name)
After calling this method, the name can be reused by other components.
final void unregisterComponentHolder(ComponentRegistryKey key)
After calling this method, the name can be reused by other components.
public <S> ComponentHolder<S> createComponentHolder(ComponentActivator activator, ComponentMetadata metadata)
ComponentHolder
instances to manage
components described by the given component metadata
.static boolean isBundleActive(org.osgi.framework.Bundle bundle)
true
if the bundle
is to be considered
active from the perspective of declarative services.
As of R4.1 a bundle may have lazy activation policy which means a bundle remains in the STARTING state until a class is loaded from that bundle (unless that class is declared to not cause the bundle to start). And thus for DS 1.1 this means components are to be loaded for lazily started bundles being in the STARTING state (after the LAZY_ACTIVATION event) has been sent. Hence DS must consider a bundle active when it is really active and when it is a lazily activated bundle in the STARTING state.
bundle
- The bundle checktrue
if bundle
is not null
and the bundle is either active or has lazy activation policy
and is in the starting state.public <T> boolean enterCreate(org.osgi.framework.ServiceReference<T> serviceReference)
serviceReference
- public <T> void leaveCreate(org.osgi.framework.ServiceReference<T> serviceReference)
public <T> void missingServicePresent(org.osgi.framework.ServiceReference<T> serviceReference, ComponentActorThread actor)
serviceReference
- actor
- public <S,T> void registerMissingDependency(DependencyManager<S,T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount)
public RegionConfigurationSupport registerRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference)
public RegionConfigurationSupport registerRegionConfigurationSupport(RegionConfigurationSupport trialRcs)
public void unregisterRegionConfigurationSupport(RegionConfigurationSupport rcs)