Class BundleComponentActivator
java.lang.Object
org.apache.felix.scr.impl.BundleComponentActivator
- All Implemented Interfaces:
ComponentActivator, ExtendedServiceListenerContext<ExtendedServiceEvent>
The BundleComponentActivator is helper class to load and unload Components of
a single bundle. It will read information from the metadata.xml file
descriptors and create the corresponding managers.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConfigAdminTrackerprivate final Map<String, BundleComponentActivator.ListenerInfo> private final BundleLoggerprivate final AtomicBooleanprivate final org.osgi.framework.Bundleprivate final CountDownLatchprivate final ComponentActorThreadprivate final ComponentRegistryprivate final ScrConfigurationprivate final org.osgi.framework.BundleContextprivate final List<ComponentHolder<?>> -
Constructor Summary
ConstructorsConstructorDescriptionBundleComponentActivator(ScrLogger scrLogger, ComponentRegistry componentRegistry, ComponentActorThread componentActor, org.osgi.framework.BundleContext context, ScrConfiguration configuration, List<ComponentMetadata> cachedComponentMetadata) Called upon starting of the bundle. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddServiceListener(String serviceFilterString, ExtendedServiceListener<ExtendedServiceEvent> listener) voiddisableComponent(String name) Implements theComponentContext.disableComponent(String)method by first finding the component(s) for thenameand disabling them.(package private) voiddispose(int reason) Dispose of this component activator instance and all the component managers.voidenableComponent(String name) Implements theComponentContext.enableComponent(String)method by first finding the component(s) for thenameand enabling them.<T> booleanenterCreate(org.osgi.framework.ServiceReference<T> serviceReference) (package private) static URL[]findDescriptors(org.osgi.framework.Bundle bundle, String descriptorLocation) Finds component descriptors based on descriptor location.org.osgi.framework.BundleContextReturns the BundleContext(package private) List<ComponentHolder<?>> getSelectedComponents(String name) Returns an array ofComponentHolderinstances which match thename.(package private) voidCalled outside the constructor so that the m_managers field is completely initialized.protected voidinitialize(List<ComponentMetadata> cachedComponentMetadata) Gets the MetaData location, parses the meta data and requests the processing of binder instancesbooleanisActive()Returnsif this instance is active, that is if components may be activated for this component. <T> voidleaveCreate(org.osgi.framework.ServiceReference<T> serviceReference) private voidloadDescriptor(URL descriptorURL) <T> voidmissingServicePresent(org.osgi.framework.ServiceReference<T> serviceReference) longregisterComponentId(AbstractComponentManager<?> componentManager) <S,T> void registerMissingDependency(DependencyManager<S, T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount) voidremoveServiceListener(String serviceFilterString, ExtendedServiceListener<ExtendedServiceEvent> listener) voidSchedules the giventaskfor asynchrounous execution or synchronously runs the task if the thread is not running.setRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference) voidunregisterComponentId(AbstractComponentManager<?> componentManager) voidvoidInform about any change in the state of the components.(package private) voidvalidateAndRegister(ComponentMetadata metadata)
-
Field Details
-
m_componentRegistry
-
m_bundle
private final org.osgi.framework.Bundle m_bundle -
m_context
private final org.osgi.framework.BundleContext m_context -
m_holders
-
m_componentActor
-
m_active
-
m_closeLatch
-
m_configuration
-
configAdminTracker
-
listenerMap
-
logger
-
-
Constructor Details
-
BundleComponentActivator
public BundleComponentActivator(ScrLogger scrLogger, ComponentRegistry componentRegistry, ComponentActorThread componentActor, org.osgi.framework.BundleContext context, ScrConfiguration configuration, List<ComponentMetadata> cachedComponentMetadata) throws org.osgi.service.component.ComponentException Called upon starting of the bundle. This method invokes initialize() which parses the metadata and creates the holders- Parameters:
componentRegistry- TheComponentRegistryused to register components with to ensure uniqueness of component names and to ensure configuration updates.context- The bundle context owning the components- Throws:
org.osgi.service.component.ComponentException- if any error occurrs initializing this class
-
-
Method Details
-
addServiceListener
public void addServiceListener(String serviceFilterString, ExtendedServiceListener<ExtendedServiceEvent> listener) - Specified by:
addServiceListenerin interfaceExtendedServiceListenerContext<ExtendedServiceEvent>
-
removeServiceListener
public void removeServiceListener(String serviceFilterString, ExtendedServiceListener<ExtendedServiceEvent> listener) - Specified by:
removeServiceListenerin interfaceExtendedServiceListenerContext<ExtendedServiceEvent>
-
initialize
Gets the MetaData location, parses the meta data and requests the processing of binder instances- Parameters:
cachedComponentMetadata-- Throws:
IllegalStateException- If the bundle has already been uninstalled.
-
initialEnable
void initialEnable()Called outside the constructor so that the m_managers field is completely initialized. A component might possibly start a thread to enable other components, which could access m_managers -
findDescriptors
Finds component descriptors based on descriptor location.- Parameters:
bundle- bundle to search for descriptor filesdescriptorLocation- descriptor location- Returns:
- array of descriptors or empty array if none found
-
loadDescriptor
-
validateAndRegister
-
dispose
void dispose(int reason) Dispose of this component activator instance and all the component managers. -
isActive
public boolean isActive()Returnsif this instance is active, that is if components may be activated for this component. The active flag is set early in the constructor indicating the activator is basically active (not fully setup, though) and reset early in the process of disposingthis instance.- Specified by:
isActivein interfaceComponentActivator
-
getBundleContext
public org.osgi.framework.BundleContext getBundleContext()Returns the BundleContext- Specified by:
getBundleContextin interfaceComponentActivator- Returns:
- the BundleContext
-
getConfiguration
- Specified by:
getConfigurationin interfaceComponentActivator
-
enableComponent
Implements theComponentContext.enableComponent(String)method by first finding the component(s) for thenameand enabling them. The enable method will schedule activation.- Specified by:
enableComponentin interfaceComponentActivator- Parameters:
name- The name of the component to enable ornullto enable all components.
-
disableComponent
Implements theComponentContext.disableComponent(String)method by first finding the component(s) for thenameand disabling them. The disable method will schedule deactivation- Specified by:
disableComponentin interfaceComponentActivator- Parameters:
name- The name of the component to disable ornullto disable all components.
-
getSelectedComponents
Returns an array ofComponentHolderinstances which match thename. If thenameisnullan array of all currently known component managers is returned. Otherwise an array containing a single component manager matching the name is returned if one is registered. Finally, if no component manager with the given name is registered,nullis returned.- Parameters:
name- The name of the component manager to return ornullto return an array of all component managers.- Returns:
- An array containing one or more component managers according
to the
nameparameter ornullif no component manager with the given name is currently registered.
-
registerComponentId
- Specified by:
registerComponentIdin interfaceComponentActivator
-
unregisterComponentId
- Specified by:
unregisterComponentIdin interfaceComponentActivator
-
schedule
Schedules the giventaskfor asynchrounous execution or synchronously runs the task if the thread is not running. If this instance isnot active, the task is not executed.- Specified by:
schedulein interfaceComponentActivator- Parameters:
task- The component task to execute
-
getLogger
- Specified by:
getLoggerin interfaceComponentActivator
-
enterCreate
public <T> boolean enterCreate(org.osgi.framework.ServiceReference<T> serviceReference) - Specified by:
enterCreatein interfaceComponentActivator
-
leaveCreate
public <T> void leaveCreate(org.osgi.framework.ServiceReference<T> serviceReference) - Specified by:
leaveCreatein interfaceComponentActivator
-
missingServicePresent
public <T> void missingServicePresent(org.osgi.framework.ServiceReference<T> serviceReference) - Specified by:
missingServicePresentin interfaceComponentActivator
-
registerMissingDependency
public <S,T> void registerMissingDependency(DependencyManager<S, T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount) - Specified by:
registerMissingDependencyin interfaceComponentActivator
-
setRegionConfigurationSupport
public RegionConfigurationSupport setRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference) - Specified by:
setRegionConfigurationSupportin interfaceComponentActivator
-
unsetRegionConfigurationSupport
- Specified by:
unsetRegionConfigurationSupportin interfaceComponentActivator
-
updateChangeCount
public void updateChangeCount()Description copied from interface:ComponentActivatorInform about any change in the state of the components.- Specified by:
updateChangeCountin interfaceComponentActivator
-